支付提交页面:

        [HttpPost]
public ActionResult index(decimal amount)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
string order_no = DateTime.Now.ToString("yyyyMMddHHmmss") + TenpayUtil.BuildRandomStr(4);
//这里是数据操作,代码已删除 ViewData["weixin_pay_qr_code"] = string.Format("/get_qrcode?product_id={0}", order_no);
return View();
}

输出二维码:

        public void get_qrcode(string product_id)
{
WxPayHelper helper = new WxPayHelper();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("appid", config_util.mp_weixin_appid);
dic.Add("mch_id", config_util.weixin_mch_id);
dic.Add("nonce_str", TenpayUtil.getNoncestr());
dic.Add("product_id", product_id);
dic.Add("time_stamp", TenpayUtil.getTimestamp());
dic.Add("sign", helper.GetSign(dic));
string url = WxPayHelper.FormatBizQueryParaMap(dic, false);//这里不要url编码 string code = "weixin://wxpay/bizpayurl?" + url;
var qrc = Create_ImgCode(code, 6);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
qrc.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer(); //byte[] bytes= ms.ToArray(); 这两句都可以,至于区别么,下面有解释
ms.Close(); Response.BinaryWrite(bytes);
return;
}

原生拉取微信支付代码:

        public ContentResult index()
{ if (Request.RequestType == "POST")
{
try
{
WxPayHelper helper = new WxPayHelper();
StreamReader reader = new StreamReader(Request.InputStream);
String xmlData = reader.ReadToEnd();
helper.ReceivePostXmlData(xmlData);
common_util.WriteLog("接收post来的xmlData=" + xmlData);
if (helper.CheckSign())
{
common_util.WriteLog("签名验证通过");
string product_id = helper.GetProductId();
common_util.WriteLog("产品id=" + product_id);
string order_no = product_id;if (产品ID存在)
{
#region 业务处理
helper.SetParameter("body", "用户充值,用户号:" + item.user_id);
helper.SetParameter("out_trade_no", order_no);
helper.SetParameter("total_fee", (item.amount * 100).ToString("#"));//这里单位是分
helper.SetParameter("notify_url", "http//www.openweixin.com.cn/notify");
helper.SetParameter("trade_type", "NATIVE");
string prepay_id = helper.GetPrepayId();
common_util.WriteLog("prepay_id=" + prepay_id);
if (!string.IsNullOrEmpty(prepay_id))
{
helper.SetReturnParameter("return_code", "SUCCESS");
helper.SetReturnParameter("result_code", "SUCCESS");
helper.SetReturnParameter("prepay_id", prepay_id);
helper.SetReturnParameter("appid", helper.GetAppId);
helper.SetReturnParameter("mch_id", helper.GetMch_Id);
helper.SetReturnParameter("nonce_str", TenpayUtil.getNoncestr());
}
else
{
helper.SetReturnParameter("return_code", "SUCCESS");//返回状态码
helper.SetReturnParameter("result_code", "FAIL");//业务结果
helper.SetReturnParameter("err_code_des", "预订单生产失败");
}
#endregion
}
else
{
helper.SetReturnParameter("return_code", "SUCCESS");//返回状态码
helper.SetReturnParameter("result_code", "FAIL");//业务结果
helper.SetReturnParameter("err_code_des", "此商品无效");//业务结果
}
}
else
{
helper.SetReturnParameter("return_code", "FAIL");
helper.SetReturnParameter("return_msg", "签名失败");
common_util.WriteLog("签名验证没有通过");
}
string xmlStr = helper.GetReturnXml();
common_util.WriteLog("返回xml=" + xmlStr);
Response.ContentType = "text/xml";
Response.Clear();
Response.Write(xmlStr);
Response.End();
}
catch (Exception ex)
{
common_util.WriteLog("异常了" + ex);
}
}
return Content("OK");
}

支付成功通知页面:

            if (Request.RequestType == "POST")
{
try
{
WxPayHelper helper = new WxPayHelper();
StreamReader reader = new StreamReader(Request.InputStream);
String xmlData = reader.ReadToEnd();
helper.ReceivePostXmlData(xmlData);
common_util.WriteLog("Notify_接收post来的xmlData=" + xmlData);
if (helper.CheckSign())
{
Dictionary<string, string> dicBack = helper.GetParameter();//获取所有参数
if (dicBack != null && dicBack.Keys.Contains("return_code"))
{
if (dicBack["return_code"] == "SUCCESS")
{
common_util.WriteLog("return_code=SUCCESS");
if (dicBack["result_code"] == "SUCCESS")
{
common_util.WriteLog("result_code=SUCCESS");
string out_trade_no = dicBack["out_trade_no"];//商户订单号
common_util.WriteLog("out_trade_no=" + out_trade_no); //1.验证商户订单号是否被处理
//2.处理过直接返回成功,否则返回
//此处根据out_trade_no 处理业务数据
//处理业务数据结束 common_util.WriteLog("Notify_验证签名成功");
helper.SetReturnParameter("return_code", "SUCCESS");
helper.SetReturnParameter("return_msg", "");
}
}
if (dicBack["return_code"] == "FAIL")
{
common_util.WriteLog("Notify_验证签名成功");
helper.SetReturnParameter("return_code", "SUCCESS");
helper.SetReturnParameter("return_msg", dicBack["return_msg"]);
}
}
}
else
{
common_util.WriteLog("Notify_验证签名失败");
helper.SetReturnParameter("return_code", "FAIL");
helper.SetReturnParameter("return_msg", "签名失败");
}
string xmlStr = helper.GetReturnXml();
common_util.WriteLog("Notify_返回xml=" + xmlStr);
Response.ContentType = "text/xml";
Response.Clear();
Response.Write(xmlStr);
Response.End();
}
catch (Exception ex)
{
common_util.WriteLog("Notify_异常了" + ex);
}
}
return Content("OK");

以上代码全部经过实体网站测试成功运行。

微信扫码支付asp.net(C#)实现步骤的更多相关文章

  1. 微信扫码支付+Asp.Net MVC

    这里的扫码支付指的是PC网站上面使用微信支付,也就是官方的模式二,网站是Asp.net MVC,整理如下.(demo在最下方) 一.准备工作 使用的微信API中的统一下单方法,关键的参数是‘公众账号I ...

  2. Net MVC微信扫码支付

    微信扫码支付+Asp.Net MVC 这里的扫码支付指的是PC网站上面使用微信支付,也就是官方的模式二,网站是Asp.net MVC,整理如下. 一.准备工作 使用的微信API中的统一下单方法,关键的 ...

  3. ASP.NET Core Web 支付功能接入 微信-扫码支付篇

    这篇文章将介绍ASP.NET Core中使用 开源项目 Payment,实现接入微信-扫码支付及异步通知功能. 开发环境:Win 10 x64.VS2017 15.6.4..NET Core SDK ...

  4. 【转载】ASP.NET Core Web 支付功能接入 微信-扫码支付篇

    转自:http://www.cnblogs.com/essenroc/p/8630730.html 这篇文章将介绍ASP.NET Core中使用 开源项目 Payment,实现接入微信-扫码支付及异步 ...

  5. asp.net core 微信扫码支付(扫码支付,H5支付,公众号支付,app支付)之1

    2018-08-13更新生成二维码的方法 在做微信支付前,首先要了解你需要什么方式的微信支付,目前本人做过的支付包含扫码支付.H5支付.公众号支付.App支付等,本人使用的是asp.net mvc c ...

  6. ASP.NET Core Web 支付功能接入 微信-扫码支付篇(转)

    原文 https://www.cnblogs.com/essenroc/p/8630730.html // 随着版本更迭,新版本可能无法完全适用,请参考仓库内的示例. 这篇文章将介绍ASP.NET C ...

  7. .NET微信扫码支付模式二API接口开发测试

    主要实现微信扫码支付,官网的SDKdemo 就不要使用 一直不能调试通过的,还是自己按照API接口文档一步一步来实现,吐槽下微信一点责任感都木有,能不能demo搞个正常的吗,不要坑惨了一大群码农们有点 ...

  8. MVC 微信扫码支付

    微信扫码支付有两种模式, 模式一和模式二, 两者具体的区别可参考官网文档:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4 微 ...

  9. C# 微信扫码支付 回调页面

    .NET版 微信扫码支付,官方推荐使用[模式二] 一.微信扫码支付模式一: 1.回调页面:官方demo中example文件下的NativeNotifyPage.aspx 2.微信回调地址:http:/ ...

随机推荐

  1. UNICODE字符串与多字节字符串的转换

    相互转换的两个函数的声明: 1. 多字节字符串与宽字符串的转换 int MultiByteToWideChar( UINT CodePage, // code page,一般设为 CP_ACP DWO ...

  2. max subquence sum(n^2)

    #include<cstdio>#include<cstring>const int maxn=100005;int buf[maxn];int main(){ freopen ...

  3. ANTLR4权威参考手册

    ANTLR4权威参考手册(一) - 活在当下 乐在其中 - 博客频道 - CSDN.NET ANTLR4权威参考手册

  4. JavaCC首页、文档和下载 - 语法分析生成器 - 开源中国社区

    JavaCC首页.文档和下载 - 语法分析生成器 - 开源中国社区

  5. VS2013 试用版到期 解决办法

    摘自:http://jingyan.baidu.com/article/fec7a1e5100b481190b4e7d9.html 输入密钥:BWG7X-J98B3-W34RT-33B3R-JVYW9

  6. Android IOS WebRTC 音视频开发总结(五一)-- 降噪基本原理

    文章主要介绍噪声消除,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,欢迎关注微信公众号blacker,更多详见www.rtc.help ---------------------- ...

  7. css3 2d

    CSS3 2D 转换   通过 CSS3 转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. 以下是 2D 转换 1 translate()通过 translate() 方法,元素从其当前位置移动 ...

  8. luigi学习7--running from command line

    最简单去运行一个luigi task的方式是通过luigi命令行工具. 示例代码: # my_module.py, available in your sys.path import luigi cl ...

  9. web.xml中的url-pattern映射规则

    Servlet和filter是J2EE开发中常用的技术,使用方便,配置简单.servlet和filter中的url-pattern有一些文章在里面的,总结了一些东西,以免遇到问题又要浪费时间. 一,s ...

  10. cassandra 之 jdbc 使用【java、scala】

    1.数据库创建 参考接上文cassandra入门 http://www.cnblogs.com/piaolingzxh/p/4197833.html 2.下载jdbc驱动源码,构建jar包 源码下载地 ...