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

177 lines
7.7 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_notify_url0 : 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();
DAL.P_Guige daoGuige = new DAL.P_Guige();
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();
DAL.user_zzjf daozzjf = new DAL.user_zzjf();
DAL.user_zzjf_log daozzjflog = new DAL.user_zzjf_log();
DAL.business_info daobusiness = new DAL.business_info();
Utility.Config config = new Mtxfw.Utility.Config("");
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;
if (resp_code == "00000000")
{
if (Mtxfw.Utility.Interface_WxPay.verfySign(config.hfpayPublicKey, sign, data))
{
/********************************
*
*
*
*********************************/
huifupayresult1 rada = (huifupayresult1)Fromhuifupayresult1Json(data);
if (rada.trans_stat == "S")
{
Mtxfw.Utility.Common.WriteHtml("/weixin/hfpay_notify_url0.txt", rada.trans_stat);
bool ifjs = true;
if (Application["LogLock0" + rada.req_seq_id] != null)
{
ifjs = false;
}
if (ifjs)
{
Application["LogLock0" + rada.req_seq_id] = "lock";
Mtxfw.Model.user_Results ReModel = daoResults.GetModel1(9, rada.req_seq_id);
if (ReModel != null)
{
DateTime dt = DateTime.Now;
daoResults.Updatemoney("b15", 2, "id=" + 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 = "支付接口错误0";
mo.addtime = DateTime.Now;
mo.ErrBody = resp_code + "|" + resp_desc + "|" + sign;
mo.ErrBody2 = data;
new DAL.User_Errlog().Add(mo);
//Response.Write("fail");
}
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 Fromhuifupayresult1Json(string json)
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Deserialize<huifupayresult1>(json);
}
}
}