手机版

微信小程序c#后台支付结果回调

时间:2021-12-12 来源:互联网 编辑:宝哥软件园 浏览:

又为大家带来简单的c#后台支付结果回调方法,首先还是要去微信官网下载模板(WxPayAPI),将模板(WxPayAPI)添加到服务器上,然后在打开WxPayAPI项目中的例子文件下的

本地enotifypage。aspx打开网页中的代码页如图:

将以下代码加入进去就能完成:

{公共静态字符串wxJsApiParam { get设置;} //前段显示公共字符串return _ result=受保护的无效页面加载(对象发送者,事件参数){响应内容类型=“文本/纯文本”;回应。写('你好世界');日志助手.写日志(类型为(NativeNotifyPage),"可以运行1-1');string XMldata=GetPostStr();//获取请求数据if(xmlData==' '){ } else { var DIC=new dictionary string,string { {'return_code ',' SUCCESS'},{'return_msg ',' OK ' } } var sb=new StringBuilder();某人(某人的简写)追加(“XML”);驾驶员信息中心中的(某人).追加(' d。键d。值/' d。键' ');}某人。追加('/XML ');//把数据重新返回给客户端数据集ds=新数据集();字符串读取器stram=新的字符串读取器(XMldata);XmlTextReader数据读取器=新的XmlTextReader(stram);ds .读取XML(数据读取器);if (ds .表[0]。行[0]["return _ code"].ToString()==' SUCCESS '){ LogHelper .写日志(类型为(nativenodifypage),"数据能返回');字符串wx _ appid=//微信开放平台审核通过的应用APPID字符串wx _ mch _ id=//微信支付分配的商户号字符串wx _ nonce _ str=//随机字符串,不长于32位字符串wx _ sign=//签名,详见签名算法字符串wx _ result _ code=//SUCCESS/FAIL字符串wx _ return _代码=字符串wx _ openid=//用户在商户appid下的唯一标识字符串wx _ is _ subscribe=//用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效字符串wx _ trade _ type=//APP字符串wx _ bank _ type=//银行类型,采用字符串类型的银行标识,银行类型见银行列表

string wx_fee_type = "";// 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 string wx_transaction_id = "";//微信支付订单号 string wx_out_trade_no = "";//商户系统的订单号,与请求一致。 string wx_time_end = "";// 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则 int wx_total_fee = 1;// 订单总金额,单位为分 int wx_cash_fee = 1;//现金支付金额订单现金支付金额,详见支付金额 #region 数据解析 //列 是否存在 string signstr = "";//需要前面的字符串 //wx_appid if (ds.Tables[0].Columns.Contains("appid")) { wx_appid = ds.Tables[0].Rows[0]["appid"].ToString(); if (!string.IsNullOrEmpty(wx_appid)) { signstr += "appid=" + wx_appid; } } //wx_bank_type if (ds.Tables[0].Columns.Contains("bank_type")) { wx_bank_type = ds.Tables[0].Rows[0]["bank_type"].ToString(); if (!string.IsNullOrEmpty(wx_bank_type)) { signstr += "&bank_type=" + wx_bank_type; } } //wx_cash_fee if (ds.Tables[0].Columns.Contains("cash_fee")) { wx_cash_fee = Convert.ToInt32(ds.Tables[0].Rows[0]["cash_fee"].ToString()); signstr += "&cash_fee=" + wx_cash_fee; } //wx_fee_type if (ds.Tables[0].Columns.Contains("fee_type")) { wx_fee_type = ds.Tables[0].Rows[0]["fee_type"].ToString(); if (!string.IsNullOrEmpty(wx_fee_type)) { signstr += "&fee_type=" + wx_fee_type; } } //wx_is_subscribe if (ds.Tables[0].Columns.Contains("is_subscribe")) { wx_is_subscribe = ds.Tables[0].Rows[0]["is_subscribe"].ToString(); if (!string.IsNullOrEmpty(wx_is_subscribe)) { signstr += "&is_subscribe=" + wx_is_subscribe; } } //wx_mch_id if (ds.Tables[0].Columns.Contains("mch_id")) { wx_mch_id = ds.Tables[0].Rows[0]["mch_id"].ToString(); if (!string.IsNullOrEmpty(wx_mch_id)) { signstr += "&mch_id=" + wx_mch_id; } } //wx_nonce_str if (ds.Tables[0].Columns.Contains("nonce_str")) { wx_nonce_str = ds.Tables[0].Rows[0]["nonce_str"].ToString(); if (!string.IsNullOrEmpty(wx_nonce_str)) { signstr += "&nonce_str=" + wx_nonce_str; } } //wx_openid if (ds.Tables[0].Columns.Contains("openid")) { wx_openid = ds.Tables[0].Rows[0]["openid"].ToString(); if (!string.IsNullOrEmpty(wx_openid)) { signstr += "&openid=" + wx_openid; } } //wx_out_trade_no if (ds.Tables[0].Columns.Contains("out_trade_no")) { wx_out_trade_no = ds.Tables[0].Rows[0]["out_trade_no"].ToString(); if (!string.IsNullOrEmpty(wx_out_trade_no)) { signstr += "&out_trade_no=" + wx_out_trade_no; } } //wx_result_code if (ds.Tables[0].Columns.Contains("result_code")) { wx_result_code = ds.Tables[0].Rows[0]["result_code"].ToString(); if (!string.IsNullOrEmpty(wx_result_code)) { signstr += "&result_code=" + wx_result_code; } } //wx_result_code if (ds.Tables[0].Columns.Contains("return_code")) { wx_return_code = ds.Tables[0].Rows[0]["return_code"].ToString(); if (!string.IsNullOrEmpty(wx_return_code)) { signstr += "&return_code=" + wx_return_code; } LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_return_code" + wx_return_code); } //wx_sign if (ds.Tables[0].Columns.Contains("sign")) { wx_sign = ds.Tables[0].Rows[0]["sign"].ToString(); //if (!string.IsNullOrEmpty(wx_sign)) //{ // signstr += "&sign=" + wx_sign; //} } //wx_time_end if (ds.Tables[0].Columns.Contains("time_end")) { wx_time_end = ds.Tables[0].Rows[0]["time_end"].ToString(); if (!string.IsNullOrEmpty(wx_time_end)) { signstr += "&time_end=" + wx_time_end; } LogHelper.WriteLog(typeof(NativeNotifyPage), "time_end" + wx_time_end); } //wx_total_fee if (ds.Tables[0].Columns.Contains("total_fee")) { wx_total_fee = Convert.ToInt32(ds.Tables[0].Rows[0]["total_fee"].ToString()); signstr += "&total_fee=" + wx_total_fee; LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_total_fee" + wx_total_fee); } //wx_trade_type if (ds.Tables[0].Columns.Contains("trade_type")) { wx_trade_type = ds.Tables[0].Rows[0]["trade_type"].ToString(); if (!string.IsNullOrEmpty(wx_trade_type)) { signstr += "&trade_type=" + wx_trade_type; } } //wx_transaction_id if (ds.Tables[0].Columns.Contains("transaction_id")) { wx_transaction_id = ds.Tables[0].Rows[0]["transaction_id"].ToString(); if (!string.IsNullOrEmpty(wx_transaction_id)) { signstr += "&transaction_id=" + wx_transaction_id; } LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_transaction_id" + wx_transaction_id); } #endregion //追加key 密钥 signstr += "&key=" + System.Web.Configuration.WebConfigurationManager.AppSettings["key"].ToString(); //签名正确 string orderStrwhere = "ordernumber='" + wx_out_trade_no + "'"; if (wx_sign == System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signstr, "MD5").ToUpper()) { //签名正确 处理订单操作逻辑 } else { //追加备注信息 } } else { // 返回信息,如非空,为错误原因 签名失败 参数格式校验错误 string return_msg = ds.Tables[0].Rows[0]["return_msg"].ToString(); } return_result = sb.ToString(); } } public bool IsReusable { get { return false; } } //获得Post过来的数据 public string getPostStr() { Int32 intLen = Convert.ToInt32(System.Web.HttpContext.Current.Request.InputStream.Length); byte[] b = new byte[intLen]; System.Web.HttpContext.Current.Request.InputStream.Read(b, 0, intLen); return System.Text.Encoding.UTF8.GetString(b); }}

备注:记得将方法地址加入到统一下单的中去如图

微信小程序 c#后台支付结果回调(图1)

版权声明:微信小程序c#后台支付结果回调是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。