微信小程序 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 ...
随机推荐
- 开源应用框架BitAdminCore:更新日志20180817
索引 NET Core应用框架之BitAdminCore框架应用篇系列 框架演示:http://bit.bitdao.cn 框架源码:https://github.com/chenyinxin/coo ...
- mysql--mysql的安装与目录介绍
一.mysql的下载安装 1.下载安装 1.windows10下安装 我们采用绿色免安装版, 打开你的mysql文件夹中的bin目录,我的是这个样子的 将这个路径添加入系统环境变量,首先右键此电脑-- ...
- NOIP2013PUZZLE
#include<cstdio> #include<cstring> #define MIN(A,B) (A)<(B)?(A):(B) using namespace s ...
- 八.linux系统文件属性知识
1.文件属性权限是12位,现在只看9位,其中每3个一组,为:属主权限.属组权限.其他权限,其中r可读,w可写,x可执行,如图: 2.文件属性之软硬链接 linux系统中有两种链接,为硬链接(ln) ...
- 七、linux目录结构知识---实战
1.企业面试题:一个100M的磁盘分区,分别写入1k文件,及写入1M的文件,分别可以写多少个? 一块磁盘被分区格式化成系统文件后,有Inode和Block:一个文件一般占用一个Inode和一个Bloc ...
- Net Manager测试连接测试没有成功,用户权限问题,以管理员身份运行后测试成功
Net Manager测试连接测试没有成功,截图如下:
- git log 与 git reflog 的 区别
git log: commit 的版本日志 包含提交的版本 操作者 日期 (方便查看commit的版本,但是版本回退后,使用git log 看不到回退版本号之后的版本记录) commit ce0d69 ...
- 注解中用于@target的方法annotation/--ElementType.METHOD,ElementType.TYPE对应方法,类接
@Target: @Target说明了Annotation所修饰的对象范围:Annotation可被用于 packages.types(类.接口.枚举.Annotation类型).类型成员(方法.构造 ...
- 数据挖掘 Apriori Algorithm python实现
该算法主要是处理关联分析的: 大多书上面都会介绍,这里就不赘述了: dataset=[[1,2,5],[2,4],[2,3],[1,2,4],[1,3],[2,3],[1,3],[1,2,3,5],[ ...
- ubuntu 16.04安装后的简单优化
1.更换更新源为国内源: sudo vim /etc/apt/sources.list vim 打开更新源配置文件添加国内源进去,这里添加阿里源 deb http://mirrors.aliyun.c ...