h5等调用小程序支付

在h5端,调用支付接口会返回openlink字段,这个后台配置的小程序scheme地址,通过window.location.href=openlink可跳转到小程序

that.$http.request.post(that.$http.api.PayBond, { type: that.pay_type, id: that.Info.id }).then(res => {
   console.log(res, 'pay-bond');
   uni.hideLoading();
   let pay_info = res.data.pay_info;
    // #ifdef MP-WEIXIN
   that.$payment.pay(pay_info, that.pay_type, that.paySuccess);
	// #endif
	// #ifndef MP-WEIXIN
    let openlink = res.data.openlink
	console.log(openlink)
	window.location.href = openlink
	// #endif
});

在跳转的指定页面onload里面可以接收参数,我的就是在pages/index/index里的,因为有多个支付

onLoad(e) {
	let that = this
	console.log("=========")
	console.log(e)
	if(!!e.way){
		let {type,amount,platform,way,address_id,id,money} = e
		let fun = ''
		switch(way){
			// 充值
			case 'recharge':
				fun = 'Recharge';
				break;
			// 订单支付
			case 'payorder':
				fun = 'PayOrder';
				break;
			// 认证
			case 'authandupgrade':
				fun = 'UpgradePay';
				break;
			// 消保金
			case 'payxiaobaojin':
				fun = 'PayShopBond';
				break;
			// 保证金 
			case 'paybond':
				fun = 'PayBond';
				break;
			default:
				break;
		}
		console.log(fun)
		let data = {type: type, amount: amount,address_id:address_id,id:id,money:money }
		console.log(data)
		that.$http.request.post(that.$http.api[fun], data).then(res => {
			console.log(res, 'recharge');
			// uni.hideLoading();
			let pay_info = res.data.pay_info;
			that.$payment.pay(pay_info, type,that.init);
		})
	}
	console.log("========")
	this.init();
  },

其中this.$payment.pay是封装的调起支付函数

function pay(params, type = 1, callback) {
  console.log('pay:', params, type);
  if (type == 1) {
    uni.showToast({
      title: '支付成功'
    });
    setTimeout(() => {
      callback()
    }, 1500);
  } else if (type == 2) {
    // #ifdef MP-WEIXIN
    uni.requestPayment({
      provider: 'wxpay',
      timeStamp: params.timeStamp,
      nonceStr: params.nonceStr,
      package: params.package,
      signType: params.signType,
      paySign: params.paySign,
      success: function(res) {
        console.log(res, 'paySuccess-wx');
        uni.showToast({
          title: '支付成功!'
        });
        setTimeout(() => {
          callback()
        }, 1500);
      },
      fail: function(err) {
        console.log(err, 'payFail-wx');
        uni.showToast({
          title: '支付失败!',
          icon: 'none'
        });
      }
    });
    // #endif
   }

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值