最近在在做微擎模块转tpwe模块开发,需要了解微擎支付的流程,一般小程序前端请求对应模块下面 wxapp.php 指定的方法,然后再指定方法里面调用微擎本身自带的$pay_params = $this->pay($order);方法返回支付签名即可。所以tpwe做的时候最重要是做pay方法即可!
pay.wxml
pay: function (orderId) {
var that = this
app.util.request({
'url': 'entry/wxapp/pay', //调用模块里面wxapp.php中的doPagePay方法获取支付参数
data: {
orderid: orderId //订单id
},
'cachetime': '0',
success(res) {
if (res.data && res.data.data && !res.data.errno) {
//发起支付
wx.requestPayment({
'timeStamp': res.data.data.timeStamp,
'nonceStr': res.data.data.nonceStr,
'package': res.data.data.package,
'signType': 'MD5',
'paySign': res.data.data.paySign,
'success': function (res) {
//订单支付成功,修改订单状态至代发货
app.util.request({
url: 'entry/wxapp/orderstatus',//调用模块里面wxapp.php中的doPagePay方法获取支付参数
data: {
orderId: orderId
},
success(res) {
that.setData({
})
}
})
wx.showToast({
title: '支付成功',
icon: 'success',
duration: 2000
})
setTimeout(function () {
wx.navigateTo({
url: 'payresult/index?id='+orderId,
})
}, 2000)
},
'fail': function (res) {
console.log('支付失败')
}
})
}
},
fail(res) {
wx.showModal({
title: '系统提示',
content: res.data.message ? res.data.message : '错误',
showCancel: false,
success: function (res) {
if (res.confirm) {
backApp()
}
}
})
}
})
},
wxapp.php
// 调用微信支付接口
public function doPagePay() {
global $_GPC, $_W;
//获取订单号,保证在业务模块中唯一即可
$orderid = $_GPC['orderid'];
//查询
$order = pdo_get('order',array('orderid'=>$orderid));
//构造支付参数
$order = array(
'tid' => $orderid,
'user' => $_W['openid'], //用户OPENID
'fee' => floatval($order['price']), //金额
'title' => 'tpwe系统',
);
//生成支付参数,返回给小程序端
$pay_params = $this->pay($order);
if (is_error($pay_params)) {
return $this->result(1, '支付失败,请重试');
}
return $this->result(0, '', $pay_params);
}
承接微擎模块开发,微擎模块独立 微信:tpwe8888