微信扫码支付asp.net(C#)实现步骤

支付提交页面:

        [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");

 

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

转载于:https://www.cnblogs.com/valu/p/4339939.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
众所周到,目前微信支付已经十分普及,无论是商场、超市、网站上,微信支付的发展十分迅速,而ASP版微信支付微信公众平台上并没有提供,而目前基于ASP语言开发的网站又十分普遍,因此这类网站集成微信支付就十分不便。 基于此,我们根据微信提供的开放SDK,独立开发了微信支付的各种支付接口,包括:微信扫码支付、H5支付微信公众号支付微信红包支付微信刷卡支付等一系列接口,供所有ASP代码的网站使用。 ASP扫码支付是用的最普遍的一种接口,所有ASP的网站都可以整合使用,微信扫码支付结果会实时在微信中回调显示,同时实现支付下单结果返回,并入库自动更新订单操作。 微信公众号支付是基于微信公众号而开发的支付接口,在已有的公众号里可以添加ASP的公众号支付微信中生成订单后,直接调出微信钱包支付,非常方便,同样支持自动更新订单状态。 H5支付是手机浏览器使用的接口,常用于手机版网站,通过手机浏览器点击链接自动唤醒微信支付;刷卡支付则适用于商场类的POS机操作,一般网站上不需要。 ASP微信支付接口代码纯ASP代码,完全开源,代码易于整合,只需要简单几步即可整合在各类网站,微信支付无须第三方任何插件,虚拟主机即可使用,纯代码,体积小,运行速度快安全性高。 Asp微信支付接口代码 v5.4.5: 增加对HTTPS协议的支持

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值