uniapp 微信浏览器下调取支付

后台获取支付参数  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')
						}
					});
			},

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值