Files
g.hnyhua.cn/Mtxfw.VipSite/pay/hfpay_chashnotify_url.aspx.cs

173 lines
7.5 KiB
C#
Raw Permalink Normal View History

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
namespace Mtxfw.VipSite
{
/// <summary>
/// 功能:服务器异步通知页面
/// 版本3.3
/// 日期2012-07-10
/// 说明:
/// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
/// 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
///
/// ///////////////////页面功能说明///////////////////
/// 创建该页面文件时请留心该页面文件中无任何HTML代码及空格。
/// 该页面不能在本机电脑测试,请到服务器上做测试。请确保外部可以访问该页面。
/// 该页面调试工具请使用写文本函数logResult。
/// 如果没有收到该页面返回的 success 信息支付宝会在24小时内按一定的时间策略重发通知
/// </summary>
public partial class hfpay_chashnotify_url : System.Web.UI.Page
{
Mtxfw.DAL.user_info daoUser = new Mtxfw.DAL.user_info();
Mtxfw.DAL.order_info daoorder = new Mtxfw.DAL.order_info();
Mtxfw.DAL.user_Results daoResults = new Mtxfw.DAL.user_Results();
DAL.user_Results_jl daojl = new DAL.user_Results_jl();
DAL.user_Results_jl2 daojl2 = new DAL.user_Results_jl2();
Mtxfw.DAL.P_Product daoProduct = new Mtxfw.DAL.P_Product();
Mtxfw.DAL.order_product_info daoorderproduct = new Mtxfw.DAL.order_product_info();
DAL.Article daoArt = new DAL.Article();
DAL.user_live daolive = new DAL.user_live();
DAL.user_proxy daoproxy = new DAL.user_proxy();
Mtxfw.Utility.Config config = new Mtxfw.Utility.Config("");
DAL.business_info daobusiness = new DAL.business_info();
public int gtype = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
string hostname = Request.Url.Host;
gtype = new DAL.host().GetId(hostname);
if (!String.IsNullOrEmpty(Request.Form["resp_code"]) && !String.IsNullOrEmpty(Request.Form["resp_desc"]) && !String.IsNullOrEmpty(Request.Form["sign"]) && !String.IsNullOrEmpty(Request.Form["resp_data"]))
{
string resp_code = Request.Form["resp_code"].ToString();
string resp_desc = Request.Form["resp_desc"].ToString();
string sign = Request.Form["sign"].ToString();
string data = Request.Form["resp_data"].ToString();
bool iferr = false;
Mtxfw.Utility.Common.WriteHtml("/weixin/hfpay_chashnotify_url.txt", data);
if (resp_code == "10000")
{
if (Mtxfw.Utility.Interface_WxPay.verfySign(config.hfpayPublicKey, sign, data))
{
/********************************
*
*
*
*********************************/
huifupayresult2 rada = (huifupayresult2)Fromhuifupayresult2Json(data);
if (rada.trans_status == "S" && rada.acct_status == "S" && rada.channel_status == "S")
{
Mtxfw.Model.user_Results ReModel = daoResults.GetModel2(10, rada.req_seq_id);
if (ReModel != null)
{
DateTime dt = DateTime.Now;
if (ReModel.Seef == 0)
{
ReModel.Seef = 1;
daoResults.UpdateSeef(1, DateTime.Now, ReModel.Id);
}
}
}
else
{
iferr = true;
}
}
else
{
iferr = true;
}
}
else
{
iferr = true;
}
if (iferr)
{
Model.User_Errlog mo = new Model.User_Errlog();
mo.DLID = 0;
mo.ErrType = "返回支付成本接口错误";
mo.addtime = DateTime.Now;
mo.ErrBody = resp_code + "|" + resp_desc + "|" + sign;
mo.ErrBody2 = data;
new DAL.User_Errlog().Add(mo);
}
else
{
}
Response.Write("200"); //请不要修改或删除
}
else//验证失败
{
Response.Write("fail");
}
}
catch (Exception err)
{
Mtxfw.Utility.Common.WriteHtml("/weixin/payerr.txt", err.ToString());
}
}
}
/// <summary>
/// 获取支付宝POST过来通知消息并以“参数名=参数值”的形式组成数组
/// </summary>
/// <returns>request回来的信息组成的数组</returns>
public IDictionary<string, string> GetRequestPost()
{
int i = 0;
IDictionary<string, string> sArray = new Dictionary<string, string>();
NameValueCollection coll;
//Load Form variables into NameValueCollection variable.
coll = Request.Form;
// Get names of all forms into a string array.
String[] requestItem = coll.AllKeys;
for (i = 0; i < requestItem.Length; i++)
{
sArray.Add(requestItem[i], Request.Form[requestItem[i]]);
}
return sArray;
}
//切记alipaypublickey是支付宝的公钥请去open.alipay.com对应应用下查看。
//bool RSACheckV1(IDictionary<string, string> parameters, string alipaypublicKey, string charset, string signType, bool keyFromFile)
public object Fromhuifupayresult2Json(string json)
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Deserialize<huifupayresult2>(json);
}
public object FromhuifuresultJson(string json)
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Deserialize<huifuresult>(json);
}
}
}