在公众号商户平台配置 

点击立即支付:

在uniapp項目中使用

 

pay() {
			
				let charges = this.chargeItemInfoList.filter((item) => {
					return item.settlementStatus == 1
				}).map((item) => {
					return item.realityCharge
				}).reduce((prev, next) => {
					return this.plus(prev, next)
				}) * 100
				
				//调后端接口返回所需要的参数
				 this.$u.api.getWxPayConfig({
					openId:localStorage.getItem('openId'),
					businessType:1,
					businessCode:this.businessCode
				}).then((res) => {
					console.log(res,typeof(res),res.data,'获取微信支付参数');
					if(res.code!==1) return uni.showToast({
						title:res.message,
						icon:"error"
					})
					this.wxReadyToPay(res.data)
				
				})
			},
wxReadyToPay(options){
				// let that = this
				if (typeof WeixinJSBridge == "undefined"){
					if( document.addEventListener){
						 document.addEventListener('WeixinJSBridgeReady',this.onBridgeReady(options), false);
					}else if(document.attachEvent){
						document.attachEvent('WeixinJSBridgeReady',this.onBridgeReady(options));
						document.attachEvent('onWeixinJSBridgeReady',this.onBridgeReady(options));
					}
				}else{
					this.onBridgeReady(options);
				}
			},
			onBridgeReady(options){
				// console.log(options,typeof(options),'支付参数')
				  if (WeixinJSBridge && options.appId) {
				        WeixinJSBridge.invoke('getBrandWCPayRequest', options, function(res) {
				            if (res.err_msg == "get_brand_wcpay_request:ok") {
				                // 使用以上方式判断前端返回,微信团队郑重提示:
				                //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
				                // console.log('支付成功');
								this.show()
				            }
				        });
				    } else {
				        console.log('请在微信浏览器中打开支付');
				    }
				
			},


Logo

前往低代码交流专区

更多推荐