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

NativeNotifyPage.aspx打开网页中的代码页如图:

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

  1. public partial class NativeNotifyPage : System.Web.UI.Page
  2. {
  3. public static string wxJsApiParam { get; set; } //前段显示
  4. public string return_result = "";
  5. protected void Page_Load(object sender, EventArgs e)
  6. {
  7. Response.ContentType = "text/plain";
  8. Response.Write("Hello World");
  9.  
  10. LogHelper.WriteLog(typeof(NativeNotifyPage), "可以运行1-1");
  11.  
  12. String xmlData = getPostStr();//获取请求数据
  13. if (xmlData == "")
  14. {
  15.  
  16. }
  17. else
  18. {
  19. var dic = new Dictionary<string, string>
  20. {
  21. {"return_code", "SUCCESS"},
  22. {"return_msg","OK"}
  23.  
  24. };
  25. var sb = new StringBuilder();
  26. sb.Append("<xml>");
  27.  
  28. foreach (var d in dic)
  29. {
  30. sb.Append("<" + d.Key + ">" + d.Value + "</" + d.Key + ">");
  31. }
  32. sb.Append("</xml>");
  33.  
  34. //把数据重新返回给客户端
  35. DataSet ds = new DataSet();
  36. StringReader stram = new StringReader(xmlData);
  37. XmlTextReader datareader = new XmlTextReader(stram);
  38. ds.ReadXml(datareader);
  39. if (ds.Tables[].Rows[]["return_code"].ToString() == "SUCCESS")
  40. {
  41.  
  42. LogHelper.WriteLog(typeof(NativeNotifyPage), "数据能返回");
  43.  
  44. string wx_appid = "";//微信开放平台审核通过的应用APPID
  45. string wx_mch_id = "";//微信支付分配的商户号
  46.  
  47. string wx_nonce_str = "";// 随机字符串,不长于32位
  48. string wx_sign = "";//签名,详见签名算法
  49. string wx_result_code = "";//SUCCESS/FAIL
  50.  
  51. string wx_return_code = "";
  52. string wx_openid = "";//用户在商户appid下的唯一标识
  53. string wx_is_subscribe = "";//用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
  54. string wx_trade_type = "";// APP
  55. string wx_bank_type = "";// 银行类型,采用字符串类型的银行标识,银行类型见银行列表
  56. string wx_fee_type = "";// 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
  57.  
  58. string wx_transaction_id = "";//微信支付订单号
  59. string wx_out_trade_no = "";//商户系统的订单号,与请求一致。
  60. string wx_time_end = "";// 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
  61. int wx_total_fee = ;// 订单总金额,单位为分
  62. int wx_cash_fee = ;//现金支付金额订单现金支付金额,详见支付金额
  63.  
  64. #region 数据解析
  65. //列 是否存在
  66. string signstr = "";//需要前面的字符串
  67. //wx_appid
  68. if (ds.Tables[].Columns.Contains("appid"))
  69. {
  70. wx_appid = ds.Tables[].Rows[]["appid"].ToString();
  71. if (!string.IsNullOrEmpty(wx_appid))
  72. {
  73. signstr += "appid=" + wx_appid;
  74. }
  75. }
  76.  
  77. //wx_bank_type
  78. if (ds.Tables[].Columns.Contains("bank_type"))
  79. {
  80. wx_bank_type = ds.Tables[].Rows[]["bank_type"].ToString();
  81. if (!string.IsNullOrEmpty(wx_bank_type))
  82. {
  83. signstr += "&bank_type=" + wx_bank_type;
  84. }
  85. }
  86. //wx_cash_fee
  87. if (ds.Tables[].Columns.Contains("cash_fee"))
  88. {
  89. wx_cash_fee = Convert.ToInt32(ds.Tables[].Rows[]["cash_fee"].ToString());
  90.  
  91. signstr += "&cash_fee=" + wx_cash_fee;
  92. }
  93.  
  94. //wx_fee_type
  95. if (ds.Tables[].Columns.Contains("fee_type"))
  96. {
  97. wx_fee_type = ds.Tables[].Rows[]["fee_type"].ToString();
  98. if (!string.IsNullOrEmpty(wx_fee_type))
  99. {
  100. signstr += "&fee_type=" + wx_fee_type;
  101. }
  102. }
  103.  
  104. //wx_is_subscribe
  105. if (ds.Tables[].Columns.Contains("is_subscribe"))
  106. {
  107. wx_is_subscribe = ds.Tables[].Rows[]["is_subscribe"].ToString();
  108. if (!string.IsNullOrEmpty(wx_is_subscribe))
  109. {
  110. signstr += "&is_subscribe=" + wx_is_subscribe;
  111. }
  112. }
  113.  
  114. //wx_mch_id
  115. if (ds.Tables[].Columns.Contains("mch_id"))
  116. {
  117. wx_mch_id = ds.Tables[].Rows[]["mch_id"].ToString();
  118. if (!string.IsNullOrEmpty(wx_mch_id))
  119. {
  120. signstr += "&mch_id=" + wx_mch_id;
  121. }
  122. }
  123.  
  124. //wx_nonce_str
  125. if (ds.Tables[].Columns.Contains("nonce_str"))
  126. {
  127. wx_nonce_str = ds.Tables[].Rows[]["nonce_str"].ToString();
  128. if (!string.IsNullOrEmpty(wx_nonce_str))
  129. {
  130. signstr += "&nonce_str=" + wx_nonce_str;
  131. }
  132. }
  133.  
  134. //wx_openid
  135. if (ds.Tables[].Columns.Contains("openid"))
  136. {
  137. wx_openid = ds.Tables[].Rows[]["openid"].ToString();
  138. if (!string.IsNullOrEmpty(wx_openid))
  139. {
  140. signstr += "&openid=" + wx_openid;
  141. }
  142. }
  143.  
  144. //wx_out_trade_no
  145. if (ds.Tables[].Columns.Contains("out_trade_no"))
  146. {
  147. wx_out_trade_no = ds.Tables[].Rows[]["out_trade_no"].ToString();
  148. if (!string.IsNullOrEmpty(wx_out_trade_no))
  149. {
  150. signstr += "&out_trade_no=" + wx_out_trade_no;
  151. }
  152.  
  153. }
  154.  
  155. //wx_result_code
  156. if (ds.Tables[].Columns.Contains("result_code"))
  157. {
  158. wx_result_code = ds.Tables[].Rows[]["result_code"].ToString();
  159. if (!string.IsNullOrEmpty(wx_result_code))
  160. {
  161. signstr += "&result_code=" + wx_result_code;
  162. }
  163. }
  164.  
  165. //wx_result_code
  166. if (ds.Tables[].Columns.Contains("return_code"))
  167. {
  168. wx_return_code = ds.Tables[].Rows[]["return_code"].ToString();
  169. if (!string.IsNullOrEmpty(wx_return_code))
  170. {
  171. signstr += "&return_code=" + wx_return_code;
  172. }
  173. LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_return_code" + wx_return_code);
  174. }
  175.  
  176. //wx_sign
  177. if (ds.Tables[].Columns.Contains("sign"))
  178. {
  179. wx_sign = ds.Tables[].Rows[]["sign"].ToString();
  180. //if (!string.IsNullOrEmpty(wx_sign))
  181. //{
  182. // signstr += "&sign=" + wx_sign;
  183. //}
  184. }
  185.  
  186. //wx_time_end
  187. if (ds.Tables[].Columns.Contains("time_end"))
  188. {
  189. wx_time_end = ds.Tables[].Rows[]["time_end"].ToString();
  190. if (!string.IsNullOrEmpty(wx_time_end))
  191. {
  192. signstr += "&time_end=" + wx_time_end;
  193. }
  194. LogHelper.WriteLog(typeof(NativeNotifyPage), "time_end" + wx_time_end);
  195. }
  196.  
  197. //wx_total_fee
  198. if (ds.Tables[].Columns.Contains("total_fee"))
  199. {
  200. wx_total_fee = Convert.ToInt32(ds.Tables[].Rows[]["total_fee"].ToString());
  201.  
  202. signstr += "&total_fee=" + wx_total_fee;
  203.  
  204. LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_total_fee" + wx_total_fee);
  205. }
  206.  
  207. //wx_trade_type
  208. if (ds.Tables[].Columns.Contains("trade_type"))
  209. {
  210. wx_trade_type = ds.Tables[].Rows[]["trade_type"].ToString();
  211. if (!string.IsNullOrEmpty(wx_trade_type))
  212. {
  213. signstr += "&trade_type=" + wx_trade_type;
  214. }
  215. }
  216.  
  217. //wx_transaction_id
  218. if (ds.Tables[].Columns.Contains("transaction_id"))
  219. {
  220. wx_transaction_id = ds.Tables[].Rows[]["transaction_id"].ToString();
  221. if (!string.IsNullOrEmpty(wx_transaction_id))
  222. {
  223. signstr += "&transaction_id=" + wx_transaction_id;
  224. }
  225. LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_transaction_id" + wx_transaction_id);
  226. }
  227.  
  228. #endregion
  229.  
  230. //追加key 密钥
  231. signstr += "&key=" + System.Web.Configuration.WebConfigurationManager.AppSettings["key"].ToString();
  232. //签名正确
  233. string orderStrwhere = "ordernumber='" + wx_out_trade_no + "'";
  234.  
  235. if (wx_sign == System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signstr, "MD5").ToUpper())
  236. {
  237. //签名正确 处理订单操作逻辑
  238.  
  239. }
  240. else
  241. {
  242. //追加备注信息
  243.  
  244. }
  245.  
  246. }
  247. else
  248. {
  249. // 返回信息,如非空,为错误原因 签名失败 参数格式校验错误
  250. string return_msg = ds.Tables[].Rows[]["return_msg"].ToString();
  251.  
  252. }
  253.  
  254. return_result = sb.ToString();
  255. }
  256.  
  257. }
  258.  
  259. public bool IsReusable
  260. {
  261. get
  262. {
  263. return false;
  264. }
  265. }
  266.  
  267. //获得Post过来的数据
  268. public string getPostStr()
  269. {
  270. Int32 intLen = Convert.ToInt32(System.Web.HttpContext.Current.Request.InputStream.Length);
  271. byte[] b = new byte[intLen];
  272. System.Web.HttpContext.Current.Request.InputStream.Read(b, , intLen);
  273. return System.Text.Encoding.UTF8.GetString(b);
  274. }
  275.  
  276. }

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

微信小程序 c#后台支付结果回调的更多相关文章

  1. [转]微信小程序 c#后台支付结果回调

    本文转自:http://www.cnblogs.com/weizhiing/p/7700723.html 又为大家带来简单的c#后台支付结果回调方法,首先还是要去微信官网下载模板(WxPayAPI), ...

  2. 微信小程序结合后台数据管理实现商品数据的动态展示、维护

    微信小程序给我们提供了一个很好的开发平台,可以用于展现各种数据和实现丰富的功能,本篇随笔介绍微信小程序结合后台数据管理实现商品数据的动态展示.维护,介绍如何实现商品数据在后台管理系统中的维护管理,并通 ...

  3. 微信小程序+java后台

    博主是大四学生,毕业设计做的是微信小程序+java后台.陆陆续续经历了三个月(因为白天要实习又碰上过年玩了一阵子),从对微信小程序一无所知到完成毕设,碰到许多问题,在跟大家分享一下自己的经历和一个小程 ...

  4. 微信小程序管理后台介绍

    微信小程序的管理后台,每次进入都需要扫码,还是特别不爽,现在微信小程序还没正式发布,很多人都还没看到管理后台,这里抢先发布出来 ------------------------------------ ...

  5. 微信小程序之后台https域名绑定以及免费的https证书申请

    微信小程序在11月3号发布了,这是一个全新的生态,没有赶上微信公众号红利的开发者,运营者可别错过这趟车了. 但是微信的后台需要全https,之前我还不相信,后台注册了后进后台才发现,服务器配置如下图 ...

  6. 让你的微信小程序具有在线支付功能

    前言 最近需要在微信小程序中用到在线支付功能,于是看了一下官方的文档,发现要在小程序里实现微信支付还是很方便的,如果你以前开发过服务号下的微信支付,那么你会发现其实小程序里的微信支付和服务号里的开发过 ...

  7. (二)校园信息通微信小程序从后台获取首页的数据笔记

    在从后台获取数据之前,需要先搭建好本地服务器的环境. 确保Apache,MySql处于开启状态.下图为Apache,MySql处于开启时状态 然后进入后台管理平台进行字段和列表的定义 然后在后台添加数 ...

  8. 微信小程序php后台实现

    这里简单介绍用php后台实现获取openid并保存到数据库: 微信的登陆流程是这样的 首先前端发送请求到服务器: wx.login({ success: function (res) { var co ...

  9. 微信小程序-展示后台传来的json格式数据

    昨天粗粗的写了下后台数据传到微信小程序显示,用来熟悉这个过程,适合刚入门学习案例: 需了解的技术:javaSE,C3p0,jdbcTemplate,fastjson,html,javaScript,c ...

随机推荐

  1. cesium编程入门(九)实体 Entity

    cesium编程入门(九)实体 Entity 在cesium编程入门(五)绘制形状提到过添加实体的方法,这一节聊一聊实体相关的一些内容: 先来看 Entity 的各个属性 id 唯一标志,如果没设置, ...

  2. Impala源码之订阅发布系统的实现

    本文由  网易云发布. 作者:冯宇 本篇文章仅限内部分享,如需转载,请联系网易获取授权. 本文是Impala源码笔记的第一篇,本文主要根据源代码学习一下statestored模块的实现,众所周知,Im ...

  3. php如何进行多进程与异步调用方法

    浏览器和服务器之间只一种面向无连接的HTTP协议进行通讯的,面向无连接的程序的特点是客户端请求服务端,服务端根据请求输出相应的程序,不能保持持久连接. 这样就出现了一个问题,一个客户端的相应服务端可能 ...

  4. JUC中Executor基本知识

    Future And Callable 引用 http://www.cnblogs.com/dolphin0520/p/3949310.html http://www.iocoder.cn/JUC/ ...

  5. BZOJ 4002--有意义的字符串(矩阵乘法)

    4002: [JLOI2015]有意义的字符串 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 963  Solved: 416[Submit][Sta ...

  6. Mac下安装HomeBrew

    本文章为菲利克斯猫(Felix.mao)原创,转载务必在明显处注明:原文链接:http://blog.csdn.net/maojudong/article/details/7918291 1.  前言 ...

  7. django入门-视图-part3

    尊重作者的劳动,转载请注明作者及原文地址 http://www.cnblogs.com/txwsqk/p/6511384.html 完全翻译自官方文档 https://docs.djangoproje ...

  8. dbus-launch(转)

    *NAME* dbus-launch - Utility to start a message bus from a shell script dbus-launch - 从shell脚本启动一个消息 ...

  9. python --爬虫基础 --爬取今日头条 使用 requests 库的基本操作, Ajax

    '''思路一: 由于是Ajax的网页,需要先往下划几下看看XHR的内容变化二:分析js中的代码内容三:获取一页中的内容四:获取图片五:保存在本地 使用的库1. requests 网页获取库 2.fro ...

  10. iOS中生成随机的UUID

    + (NSString *)uuidString { CFUUIDRef uuid_ref = CFUUIDCreate(NULL); CFStringRef uuid_string_ref= CFU ...