微信小程序 c#后台支付结果回调
又为大家带来简单的c#后台支付结果回调方法,首先还是要去微信官网下载模板(WxPayAPI),将模板(WxPayAPI)添加到服务器上,然后在打开WxPayAPI项目中的example文件下的
NativeNotifyPage.aspx打开网页中的代码页如图:
将以下代码加入进去就能完成:
public partial class NativeNotifyPage : System.Web.UI.Page
{
public static string wxJsApiParam { get; set; } //前段显示
public string return_result = "";
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
Response.Write("Hello World"); LogHelper.WriteLog(typeof(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();
sb.Append("<xml>"); foreach (var d in dic)
{
sb.Append("<" + d.Key + ">" + d.Value + "</" + d.Key + ">");
}
sb.Append("</xml>"); //把数据重新返回给客户端
DataSet ds = new DataSet();
StringReader stram = new StringReader(xmlData);
XmlTextReader datareader = new XmlTextReader(stram);
ds.ReadXml(datareader);
if (ds.Tables[].Rows[]["return_code"].ToString() == "SUCCESS")
{ LogHelper.WriteLog(typeof(NativeNotifyPage), "数据能返回"); string wx_appid = "";//微信开放平台审核通过的应用APPID
string wx_mch_id = "";//微信支付分配的商户号 string wx_nonce_str = "";// 随机字符串,不长于32位
string wx_sign = "";//签名,详见签名算法
string wx_result_code = "";//SUCCESS/FAIL string wx_return_code = "";
string wx_openid = "";//用户在商户appid下的唯一标识
string wx_is_subscribe = "";//用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
string wx_trade_type = "";// APP
string 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 = ;// 订单总金额,单位为分
int wx_cash_fee = ;//现金支付金额订单现金支付金额,详见支付金额 #region 数据解析
//列 是否存在
string signstr = "";//需要前面的字符串
//wx_appid
if (ds.Tables[].Columns.Contains("appid"))
{
wx_appid = ds.Tables[].Rows[]["appid"].ToString();
if (!string.IsNullOrEmpty(wx_appid))
{
signstr += "appid=" + wx_appid;
}
} //wx_bank_type
if (ds.Tables[].Columns.Contains("bank_type"))
{
wx_bank_type = ds.Tables[].Rows[]["bank_type"].ToString();
if (!string.IsNullOrEmpty(wx_bank_type))
{
signstr += "&bank_type=" + wx_bank_type;
}
}
//wx_cash_fee
if (ds.Tables[].Columns.Contains("cash_fee"))
{
wx_cash_fee = Convert.ToInt32(ds.Tables[].Rows[]["cash_fee"].ToString()); signstr += "&cash_fee=" + wx_cash_fee;
} //wx_fee_type
if (ds.Tables[].Columns.Contains("fee_type"))
{
wx_fee_type = ds.Tables[].Rows[]["fee_type"].ToString();
if (!string.IsNullOrEmpty(wx_fee_type))
{
signstr += "&fee_type=" + wx_fee_type;
}
} //wx_is_subscribe
if (ds.Tables[].Columns.Contains("is_subscribe"))
{
wx_is_subscribe = ds.Tables[].Rows[]["is_subscribe"].ToString();
if (!string.IsNullOrEmpty(wx_is_subscribe))
{
signstr += "&is_subscribe=" + wx_is_subscribe;
}
} //wx_mch_id
if (ds.Tables[].Columns.Contains("mch_id"))
{
wx_mch_id = ds.Tables[].Rows[]["mch_id"].ToString();
if (!string.IsNullOrEmpty(wx_mch_id))
{
signstr += "&mch_id=" + wx_mch_id;
}
} //wx_nonce_str
if (ds.Tables[].Columns.Contains("nonce_str"))
{
wx_nonce_str = ds.Tables[].Rows[]["nonce_str"].ToString();
if (!string.IsNullOrEmpty(wx_nonce_str))
{
signstr += "&nonce_str=" + wx_nonce_str;
}
} //wx_openid
if (ds.Tables[].Columns.Contains("openid"))
{
wx_openid = ds.Tables[].Rows[]["openid"].ToString();
if (!string.IsNullOrEmpty(wx_openid))
{
signstr += "&openid=" + wx_openid;
}
} //wx_out_trade_no
if (ds.Tables[].Columns.Contains("out_trade_no"))
{
wx_out_trade_no = ds.Tables[].Rows[]["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[].Columns.Contains("result_code"))
{
wx_result_code = ds.Tables[].Rows[]["result_code"].ToString();
if (!string.IsNullOrEmpty(wx_result_code))
{
signstr += "&result_code=" + wx_result_code;
}
} //wx_result_code
if (ds.Tables[].Columns.Contains("return_code"))
{
wx_return_code = ds.Tables[].Rows[]["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[].Columns.Contains("sign"))
{
wx_sign = ds.Tables[].Rows[]["sign"].ToString();
//if (!string.IsNullOrEmpty(wx_sign))
//{
// signstr += "&sign=" + wx_sign;
//}
} //wx_time_end
if (ds.Tables[].Columns.Contains("time_end"))
{
wx_time_end = ds.Tables[].Rows[]["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[].Columns.Contains("total_fee"))
{
wx_total_fee = Convert.ToInt32(ds.Tables[].Rows[]["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[].Columns.Contains("trade_type"))
{
wx_trade_type = ds.Tables[].Rows[]["trade_type"].ToString();
if (!string.IsNullOrEmpty(wx_trade_type))
{
signstr += "&trade_type=" + wx_trade_type;
}
} //wx_transaction_id
if (ds.Tables[].Columns.Contains("transaction_id"))
{
wx_transaction_id = ds.Tables[].Rows[]["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[].Rows[]["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, , intLen);
return System.Text.Encoding.UTF8.GetString(b);
} }
备注:记得将方法地址加入到统一下单的中去如图
微信小程序 c#后台支付结果回调的更多相关文章
- [转]微信小程序 c#后台支付结果回调
本文转自:http://www.cnblogs.com/weizhiing/p/7700723.html 又为大家带来简单的c#后台支付结果回调方法,首先还是要去微信官网下载模板(WxPayAPI), ...
- 微信小程序结合后台数据管理实现商品数据的动态展示、维护
微信小程序给我们提供了一个很好的开发平台,可以用于展现各种数据和实现丰富的功能,本篇随笔介绍微信小程序结合后台数据管理实现商品数据的动态展示.维护,介绍如何实现商品数据在后台管理系统中的维护管理,并通 ...
- 微信小程序+java后台
博主是大四学生,毕业设计做的是微信小程序+java后台.陆陆续续经历了三个月(因为白天要实习又碰上过年玩了一阵子),从对微信小程序一无所知到完成毕设,碰到许多问题,在跟大家分享一下自己的经历和一个小程 ...
- 微信小程序管理后台介绍
微信小程序的管理后台,每次进入都需要扫码,还是特别不爽,现在微信小程序还没正式发布,很多人都还没看到管理后台,这里抢先发布出来 ------------------------------------ ...
- 微信小程序之后台https域名绑定以及免费的https证书申请
微信小程序在11月3号发布了,这是一个全新的生态,没有赶上微信公众号红利的开发者,运营者可别错过这趟车了. 但是微信的后台需要全https,之前我还不相信,后台注册了后进后台才发现,服务器配置如下图 ...
- 让你的微信小程序具有在线支付功能
前言 最近需要在微信小程序中用到在线支付功能,于是看了一下官方的文档,发现要在小程序里实现微信支付还是很方便的,如果你以前开发过服务号下的微信支付,那么你会发现其实小程序里的微信支付和服务号里的开发过 ...
- (二)校园信息通微信小程序从后台获取首页的数据笔记
在从后台获取数据之前,需要先搭建好本地服务器的环境. 确保Apache,MySql处于开启状态.下图为Apache,MySql处于开启时状态 然后进入后台管理平台进行字段和列表的定义 然后在后台添加数 ...
- 微信小程序php后台实现
这里简单介绍用php后台实现获取openid并保存到数据库: 微信的登陆流程是这样的 首先前端发送请求到服务器: wx.login({ success: function (res) { var co ...
- 微信小程序-展示后台传来的json格式数据
昨天粗粗的写了下后台数据传到微信小程序显示,用来熟悉这个过程,适合刚入门学习案例: 需了解的技术:javaSE,C3p0,jdbcTemplate,fastjson,html,javaScript,c ...
随机推荐
- C#用 catch 捕获异类的常用类型
C#用 catch 捕获异类的常用类型 最近在书上刚刚学到了try和catch用法,然后网上找了下常用的,自己存在这里方便自己查找 Exception 类 描述 SystemException 其他 ...
- stack和stack frame
首先,我们先来了解下栈帧和栈的基本知识: 栈帧也常被称为“活动记录”(activation record),是编译器用来实现过程/函数调用的一种数据结构. 从逻辑上讲,栈帧就是一个函数执行的环境,包含 ...
- PARTITION BY函数
1.PARTITION BY 开窗函数, 使用场景,在合同表里,获取所有房源在最新的合同编号.或者获取每个班级每次考试的第一名. 区别聚合函数:对于每个每个分组返回多行,而聚合函数对于每个分组只返回一 ...
- java—在dbutils中处理事务与不确定条件的查询(46)
在dbutils中处理事务 事务是指用户的一次操作.这一次操作有可能是一个表,也有可能是多个表,也有可能是对一个表的多次操作. 只要是: 1:对数据数据库进行多次操作. 2:多个表,还是 ...
- LOJ#3085. 「GXOI / GZOI2019」特技飞行(KDtree+坐标系变换)
题面 传送门 前置芝士 请确定您会曼哈顿距离和切比雪夫距离之间的转换,以及\(KDtree\)对切比雪夫距离的操作 题解 我们发现\(AB\)和\(C\)没有任何关系,所以关于\(C\)可以直接暴力数 ...
- Python面向对象(定义类和创建对象)
day24 http://www.cnblogs.com/wupeiqi/p/4493506.html Python:函数式+面向对象,函数式编程可以做所有事,但是不一定合适. 小明,10岁,男,上山 ...
- Python(简单计算器)
参考:https://www.cnblogs.com/alex3714/articles/5169958.html import re ret = re.search('\([^()]+\)','(1 ...
- 部署LVS-DR群集
一.LVS-DR原理剖析 (一)LVS-DR数据包流向分析 1.Client向目标VIP发出请求,Director(负载均衡器)接收.此时IP包头及数据帧头信息为: 2.Director根据负载均衡算 ...
- leetcode-695-Max Area of Island(BFS)
题目描述: Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land ...
- Xcode 工程文件“.xcodeproj”文件夹解析
项目.xcodeproj 文件夹底下一般有4个文件: project.pbxproj 文件 xcuserdata 文件夹 xcshareddata 文件夹 project.xcworkspace 文件 ...