& 微信支付对比

 

本文记录时间:2020年7月

Native 支付

Native支付是指商户系统按微信支付协议生成支付二维码,用户再用微信“扫一扫”完成支付的模式。该模式适用于PC网站、实体店单品或订单、媒体广告支付等场景。

  • 后台配置的参数
    • 回调通知地址
  • 整体流程
    • 1、下单
    • 2、返回二维码链接
    • 3、扫码支付
    • 4、接收回调通知

小程序支付

  • 后台配置的参数
    • https
  • 整体流程
    • 1、通过wx.login()授权登录获取code
    • 2、通过下面的链接获取openid(服务端)
    • https://api.weixin.qq.com/sns/jscode2session?appid=${APP_ID}&secret=${SECRET}&js_code=${code}&grant_type=authorization_code
    • 3、请求下单接口 返回拉起 支付参数
    • 4、小程序端wx.requestPayment拉起支付
    • wx.requestPayment({
            timeStamp: timeStamp+'',
            nonceStr: nonceStr+'',
            package: packag,
            signType: signType+'',
            paySign: sign+'',
              success (res) {
                console.log("success" + res.data);
              },
              fail (res) {
                console.log("fail" + JSON.stringify(res));
              }
        })
    • 5、接收回调通知

JSAPI支付

  • 后台配置的参数
    • 设置js接口安全域名
    • 公众号的secret
    • ip白名单
    • 支付网页授权目录(域名)
    • 回调域名
  • 整体流程
  • 1、获取code
    • window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4097a4f2c90327ea&redirect_uri=http://smartmall.xxxxxxxxxxxxxx.cn/payment/wechat/getCode&response_type=code&scope=snsapi_userinfo#wechat_redirect"
    • 在上面链接中的redirect_uri中获取code
  • 2、根据code获取openid(服务端)
  • 3、请求下单接口
    • 根据openid请求统一下单接口
    • 拉起支付的参数
  • 4、 微信内网页端拉起支付付款
    • 通过微信JSSDK发起支付:

    *

     function onBridgeReady(data) {
            WeixinJSBridge.invoke('getBrandWCPayRequest', {
                    "appId":data.appId,
                    "timeStamp": data.timeStamp,
                    "nonceStr": data.nonceStr,
                    "package": data.package,
                    "signType": data.signType,
                    "paySign": data.paySign
                },
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok") {//res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 
                        console.log(res)
                    }
                });
     }
  • 5、接收回调通知

*

H5支付

  • 后台配置的参数
    • H5支付域名
  • 整体流程
  • 1. 请求下单接口
    • 出参中有个参数为:mweb_url
  • 2. 前端跳转发起支付
    • window.location.href=mweb_url
  • 3. 接收支付成功回调通知

商家后台配置截图

image-20210715130506507

原文地址:https://www.cnblogs.com/doagain/p/15015013.html