• 微信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的编码。

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

  • 相关阅读:
    OSI七层模型详解 TCP/IP协议
    ZT 第一范式,第二范式,第三范式
    思杰20140522
    Correspondence / ˏkɔris'pɔndәns / dictionary10-800.doc
    闲着没事,贴贴图
    心情闲适,发几个tatanic的图
    005 Python 基础特性
    017 虚拟内存 64位及内存对其 3
    004 Python 文件操作 字典 自定义函数
    003 Python list 索引
  • 原文地址:https://www.cnblogs.com/lxyang/p/9093498.html
Copyright © 2020-2023  润新知