后台获取支付参数 option
$tools = new \JsApiPay();
$wechat_pay = cmf_get_option('wechat_pay');
$input = new \WxPayUnifiedOrder();
$input->SetBody($info['Body']);//商品描述
$input->SetAttach($info['Attach']);//附加数据,作为自定义参数使用。
$input->SetOut_trade_no($info['Out_trade_no']);//作为自定义参数使用。
$input->SetTotal_fee($info['Total_fee'] * 100);//标价金额
$input->SetTime_start(date("YmdHis"));//交易起始时间
$input->SetTime_expire(date("YmdHis", time() + 600));//交易结束时间
$input->SetNotify_url($wechat_pay['Notify_url']);//通知地址,异步接收微信支付结果通知的回调地址
$input->SetTrade_type("JSAPI");//交易类型
$input->SetOpenid($info['openid']);//用户openid
$order = \WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools->GetJsApiParameters($order);
$this->success('微信支付数据', json_decode($jsApiParameters, true));
调用 wechatReday函数 ,传入从后台获取支付数据
this.wechatReday(option)
//微信h5支付
wechatReday(option) {
var that = this;
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', that.onBridgeReady(option), false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', that.onBridgeReady(option));
document.attachEvent('onWeixinJSBridgeReady', that.onBridgeReady(option));
}
} else {
that.onBridgeReady(option);
}
},
onBridgeReady(option) {
var that = this;
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId": option.appId, //公众号ID,由商户传入
"timeStamp": option.timeStamp, //时间戳,自1970年以来的秒数
"nonceStr": option.nonceStr, //随机串
"package": option.package,
"signType": option.signType, //微信签名方式:
"paySign": option.paySign, //微信签名
},
function(res) {
if (res.err_msg == 'get_brand_wcpay_request:ok') {
this.$commonjs.tipshow(that, '支付成功', 'success')
uni.navigateTo({
url:"/pages/order/info?id"+that.order_id
})
}
if (res.err_msg == 'get_brand_wcpay_request:cancel') {
this.$commonjs.tipshow(that, '用户取消', 'error')
}
if (res.err_msg == 'get_brand_wcpay_request:fail') {
this.$commonjs.tipshow(that, '支付失败', 'error')
}
});
},