小程序web-view支付完整流程

  1. 小程序的web-view中页面发起支付:
    该小程序的执行代码主要是引入web-view:

被引入的服务器页面:/pay.html

支付模板 微信支付

}

这个被引入的页面上的按钮:触发后带着订单支付参数跳转到小程序的支付逻辑页面(注意:是跳转到了小程序的支付页面)
  1. 小程序的web-view中页面发起支付:/pages/wepay/wepay
    页面渲染第一件事:抽取出传来的参数
    onLoad: function (options) {
    console.log(options); //接到的参数
    var pkEntEntrustsId = options.pkEntEntrustsId;//委托表主键 --回执用
    var DB_Center_Code = options.DB_Center_Code;//商家CODE–回执用
    var Price = options.Price;//支付金额
    var tradeNo = options.tradeNo;//唯一单号
    var openid = options.openid;
    var name = options.name;//名字

  2. 发起统一下单请求:
    //请求统一下单
    wx.request({
    url: ‘https://xxxxxx/public/makePay’,//统一下单服务接口
    data:{
    Price: Price*100,
    tradeNo: tradeNo,
    openid: openid,
    name:name
    },

  3. PHP开发统一下单服务:
    //统一下单接口
    public function makePay(){
    //基础配置
    $appid=config(‘pay.mini_appid’);
    $mch_id=config(‘pay.mch_id’);
    $key = config(‘pay.key’);
    //本单配置
    $openid=‘openid’;
    $name=‘商品名字’;
    $Price = ‘1’;
    t r a d e N o = x x x x x x x x x x x . t i m e ( ) ; i f ( i s s e t ( tradeNo='xxxxxxxxxxx'.time(); if(isset( _GET[‘Price’])) $Price = G E T [ P r i c e ] ; i f ( i s s e t ( _GET['Price']; if(isset( _GET[‘tradeNo’])) $tradeNo = G E T [ t r a d e N o ] ; i f ( i s s e t ( _GET['tradeNo']; if(isset( _GET[‘openid’])) $openid = G E T [ o p e n i d ] ; i f ( i s s e t ( _GET['openid']; if(isset( _GET[‘name’])) $name = $_GET[‘name’];
    $body = $name;
    $out_trade_no = $tradeNo;
    $total_fee = $Price;
    $total_fee =1;
    w e i x i n p a y = n e w W e i x i n P a y ( weixinpay = new WeixinPay( appid, o p e n i d , openid, mch_id, k e y , key, out_trade_no, b o d y , body, total_fee);
    r e t u r n = return= weixinpay->pay();
    echo json_encode($return);
    }

  4. 小程序抓取统一下单服务后的反馈 发起支付请求

//发起支付
wx.requestPayment({
‘timeStamp’: res.data.timeStamp,
‘nonceStr’: res.data.nonceStr,
‘package’: res.data.package,
‘signType’: ‘MD5’,
‘paySign’: res.data.paySign,
//支付成功后

  1. 发起支付成功付款后 异步修改数据库

//异步修改数据库
wx.request({
url: ‘https://xxxxxxxxxxxxx/public/notify’,//
7. 改库成功后 跳回web-view中

wx.navigateTo({
url: ‘…/payback/payback?pkEntEntrustsId=’ + pkEntEntrustsId + ‘&DB_Center_Code=’ + DB_Center_Code + ‘&Price=’ + Price + ‘&Serial_Number=’ + Serial_Number + ‘&tradeNo=’ + tradeNo + ‘&code=1’ + ‘&url=’+tempurl,//付款成功 异步修改成功,
success: function () { },
fail: function () { },
complete: function () { }
})

猜你喜欢

转载自blog.csdn.net/qq_17040587/article/details/89334010
今日推荐