zoukankan      html  css  js  c++  java
  • 微信H5支付

    微信H5支付

    微信H5支付真是躺了无数坑,扫了无数雷。。。

    说白了,就是向微信发起请求,它返回一个mweb_url,这个就是我们想要的一个拉起微信支付的链接。

            WxPayData pd = new WxPayData();
            pd.SetValue("appid", WxPayConfig.APPID);
            pd.SetValue("mch_id", WxPayConfig.MCHID);
            pd.SetValue("nonce_str", StringHelper.GenerateNonceStr()); //生成随机字符串
            pd.SetValue("body", "充值");
            pd.SetValue("device_info", "WEB");
            pd.SetValue("out_trade_no", ro.Id);
            pd.SetValue("total_fee", decimal.ToInt32(input.Amount * 100).ToString());
            pd.SetValue("spbill_create_ip", WxPayConfig.IP);
            pd.SetValue("notify_url", input.Url);
            pd.SetValue("trade_type", WxPayConfig.H5_trade_type);
            //wapurl( test.)当前为测试地址
            pd.SetValue("scene_info", "{"h5_info": {"type":"Wap","wap_url": "你的H5域名","wap_name": "qq"}} ");
            pd.SetValue("sign", pd.MakeSign()); //生成签名   
    

    其中scene_info 字段的wap_url属性一定要在公众号设置的域名下。

    请求微信并获得返回结果

             string xml = pd.ToXml();
            string response = HttpService.Post(xml, ‘统一下单地址’, false, 6); //post向微信发起请求 
            //接收回传来的请求
            WxPayData wpd = new WxPayData();
            wpd.FromXml(response);
    

    返回来的return_code 和result_code 都是SUCCESS时返回参数会一个mweb_url地址

    这个mweb_url地址就是返回前台拉起支付界面的地址

            string gotourl = WxPayConfig.H5_redirect_url; //支付成功的跳转页面
            string url = System.Web.HttpUtility.UrlEncode(gotourl, System.Text.Encoding.UTF8);
            callkurl = callkurl + "&redirect_url=" + url + "";
    

    解析: 如果想要在支付完成后跳转到自己的支付界面可以再mweb_url后面加一个redirect_url参数,这个参数一定要经过URL的UTF-8的编码。

    把这个地址链接返回到前台后进行跳转就可以支付啦!!!!!

  • 相关阅读:
    DM8168通过GPMC接口与FPGA高速数据通信实现
    2016年 我在浙大计算机学院在职研究生学习经历
    CCS Font 知识整理总结
    Hexo 博客部署到 GitHub
    树莓派配置 USB 无线网卡
    树莓派搭建 Hexo 博客(二)
    树莓派搭建 Hexo 博客(一)
    树莓派初次使用的基本配置.md
    语法测试cnblogs使用Markdown
    硬件工程师-面试笔记0305
  • 原文地址:https://www.cnblogs.com/lxyang/p/9093498.html
Copyright © 2011-2022 走看看