- 小程序的web-view中页面发起支付:
该小程序的执行代码主要是引入web-view:
被引入的服务器页面:/pay.html
}
-
小程序的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;//名字 -
发起统一下单请求:
//请求统一下单
wx.request({
url: ‘https://xxxxxx/public/makePay’,//统一下单服务接口
data:{
Price: Price*100,
tradeNo: tradeNo,
openid: openid,
name:name
}, -
PHP开发统一下单服务:
//统一下单接口
public function makePay(){
//基础配置
$appid=config(‘pay.mini_appid’);
$mch_id=config(‘pay.mch_id’);
$key = config(‘pay.key’);
//本单配置
$openid=‘openid’;
$name=‘商品名字’;
$Price = ‘1’;
_GET[‘Price’])) $Price = _GET[‘tradeNo’])) $tradeNo = _GET[‘openid’])) $openid = _GET[‘name’])) $name = $_GET[‘name’];
$body = $name;
$out_trade_no = $tradeNo;
$total_fee = $Price;
$total_fee =1;
appid, mch_id, out_trade_no, total_fee);
weixinpay->pay();
echo json_encode($return);
} -
小程序抓取统一下单服务后的反馈 发起支付请求
//发起支付
wx.requestPayment({
‘timeStamp’: res.data.timeStamp,
‘nonceStr’: res.data.nonceStr,
‘package’: res.data.package,
‘signType’: ‘MD5’,
‘paySign’: res.data.paySign,
//支付成功后
- 发起支付成功付款后 异步修改数据库
//异步修改数据库
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 () { }
})