using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Xml; using System.Globalization; using System.Text; using Newtonsoft.Json; using System.Web.Script.Serialization; using System.Security.Cryptography; namespace Mtxfw.VipSite { public partial class merchant_notify : 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_jl2 daojl2 = new DAL.user_Results_jl2(); Mtxfw.DAL.order_product_info daoorderproduct = new Mtxfw.DAL.order_product_info(); private Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(""); DAL.Article daoArt = new DAL.Article(); DAL.user_live daolive = new DAL.user_live(); DAL.user_proxy daoproxy = new DAL.user_proxy(); DAL.user_jjfp daojjfp = new DAL.user_jjfp(); Mtxfw.DAL.P_Product daoProduct = new Mtxfw.DAL.P_Product(); int gtype = 0; public string APIv3key = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string hostname = Request.Url.Host; byte[] bytes = Request.BinaryRead(Request.ContentLength); string strRequest = System.Text.Encoding.UTF8.GetString(bytes); merchant_returns mr = (merchant_returns)Frommerchant_returnsJson(strRequest); string status = mr.status; string errorCode = ""; if (!String.IsNullOrEmpty(mr.errorCode)) { errorCode = mr.errorCode; } string errorCodeDesc = ""; if (!String.IsNullOrEmpty(mr.errorCodeDesc)) { errorCodeDesc = mr.errorCodeDesc; } string userNo = mr.userNo; string merchantOrderNo = mr.merchantOrderNo; string platformSerialNo = mr.platformSerialNo; string receiverAccountNoEnc = mr.receiverAccountNoEnc; string receiverNameEnc = mr.receiverNameEnc; string paidAmount = mr.paidAmount; string fee = mr.fee; string hmac = mr.hmac; string strsign = status + errorCode + errorCodeDesc + userNo + merchantOrderNo + platformSerialNo + receiverAccountNoEnc + receiverNameEnc + paidAmount + fee; string hmac0 = Mtxfw.Utility.Interface_WxPay.GetMD5(strsign + config.hjpay_Secret); if (hmac0 == hmac && (status == "204" || status == "205")) { DateTime dt = DateTime.Now; if (status == "204") { Mtxfw.Model.user_Results ReModel = daoResults.GetModel2(1, merchantOrderNo); if (ReModel != null) { Model.User_Errlog mo = new Model.User_Errlog(); mo.DLID = 0; mo.ErrType = "merchant_notify_1_204"; mo.addtime = DateTime.Now; mo.ErrBody = ReModel.Seef + "|" + ReModel.b17; mo.ErrBody2 = errorCode + "|" + errorCodeDesc; new DAL.User_Errlog().Add(mo); if (ReModel.Seef == 0 && ReModel.b17 > 0) { ReModel.b17 = 0; daoResults.Updatemoney("b17", 0, "id=" + ReModel.Id); } } ReModel = daoResults.GetModel2(10, merchantOrderNo); if (ReModel != null) { Model.User_Errlog mo = new Model.User_Errlog(); mo.DLID = 0; mo.ErrType = "merchant_notify_10_204"; mo.addtime = DateTime.Now; mo.ErrBody = ReModel.Seef + "|" + ReModel.b17; mo.ErrBody2 = merchantOrderNo + "|" + errorCode + "|" + errorCodeDesc; new DAL.User_Errlog().Add(mo); if (ReModel.Seef == 0 && ReModel.b17 > 0) { ReModel.b17 = 0; daoResults.Updatemoney("b17", 0, "id=" + ReModel.Id); if (ReModel.Sended == 1 && ReModel.Managers != "") { DateTime addtime = Convert.ToDateTime(ReModel.Managers); string mindt = addtime.ToString("yyyy-MM-dd") + " 00:00:00"; string maxdt = addtime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00"; string strsql = " And addtime>='" + mindt + "' and addtime<'" + maxdt + "'"; daoResults.Updatemoney("b17", 0, "gtype=" + gtype + " and utype=10 and IFDelete=0 and MemberId=" + ReModel.MemberId + " and hasRead=0 and Sended=0 and Seef=0 and b17>0" + strsql); } } } } if (status == "205") { /******************************** * * 自己业务处理 * *********************************/ Mtxfw.Model.user_Results ReModel = daoResults.GetModel2(1, merchantOrderNo); if (ReModel != null) { if (ReModel.Seef == 0) { ReModel.Seef = 1; daoResults.UpdateSeef(1, DateTime.Now, ReModel.Id); } } ReModel = daoResults.GetModel2(10, merchantOrderNo); if (ReModel != null) { if (ReModel.Seef == 0) { ReModel.Seef = 1; daoResults.UpdateSeef(1, DateTime.Now, ReModel.Id); if (ReModel.Sended == 1 && ReModel.Managers != "") { DateTime addtime = Convert.ToDateTime(ReModel.Managers); string mindt = addtime.ToString("yyyy-MM-dd") + " 00:00:00"; string maxdt = addtime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00"; string strsql = " And addtime>='" + mindt + "' and addtime<'" + maxdt + "'"; daoResults.Updatemoney("b17", 0, "gtype=" + gtype + " and utype=10 and IFDelete=0 and MemberId=" + ReModel.MemberId + " and hasRead=0 and Sended=0 and Seef=0 and b17>0" + strsql); daoResults.UpdateSeef(1, DateTime.Now, "gtype=" + gtype + " and utype=10 and IFDelete=0 and MemberId=" + ReModel.MemberId + " and hasRead=0 and Sended=0 and Seef=0" + strsql); } } } } } else { Model.User_Errlog mo = new Model.User_Errlog(); mo.DLID = 0; mo.ErrType = "merchant_notify"; mo.addtime = DateTime.Now; mo.ErrBody = strRequest; mo.ErrBody2 = strsign + "|" + hmac0 + "|" + hmac + "|" + status; new DAL.User_Errlog().Add(mo); } Response.Write("{\"statusCode\":\"2001\",\"message\":\"成功\"}"); } catch (Exception err) { Mtxfw.Utility.Common.WriteHtml("/weixin/weixinpayerr5.txt", err.ToString()); } } } public object Frommerchant_returnsJson(string json) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Deserialize(json); } } public class merchant_returns { public String status { get; set; } public String errorCode { get; set; } public String errorCodeDesc { get; set; } public String userNo { get; set; } public String merchantOrderNo { get; set; } public String platformSerialNo { get; set; } public String receiverAccountNoEnc { get; set; } public String receiverNameEnc { get; set; } public String paidAmount { get; set; } public String fee { get; set; } public String hmac { get; set; } } }