最近公司開發(fā)一個app,需要從app跳轉(zhuǎn)到小程序去微信支付,當(dāng)時在網(wǎng)上看了好長時間沒有看到適合自己的,在這里記錄一下,也方便自己以后可以再復(fù)習(xí)一下,畢竟本人腦子不太好使,只能記下來。文章來源地址http://www.zghlxwxcb.cn/news/detail-590703.html
小程序微信支付:
// #ifdef MP
//小程序 微信
uni.requestPayment({
// timeStamp,nonceStr,package,signType,paySign皆為后端返回
provider: type, // type:wxpay
timeStamp: data.timeStamp,
nonceStr: data.nonceStr,
package: data.package,
signType: data.signType,
paySign: data.paySign,
success: (e) => {
uni.redirectTo({
url: "/pagesB/payment/paySuccess?orderNos="+this.payIds+"&price="+this.price
})
},
fail: (e) => {
//用戶取消支付 不做處理
console.log("fail", e);
this.subLoading = false;
this.subDisabled = false;
},
complete: (e) => {
console.log(e)
}
})
// #endif
app跳轉(zhuǎn)小程序微信支付
- app跳轉(zhuǎn)頁面攜帶參數(shù)到小程序
data() {
return {
weixin: null,
};
},
onLoad(options) {
// #ifdef APP-PLUS
plus.share.getServices((s) => {
console.log(s)
let shares = {};
for (let i = 0; i < s.length; i++) {
let t = s[i];
shares[t.id] = t;
}
let sweixin = shares['weixin'];
this.weixin = sweixin
console.log(this.weixin)
}, function(e) {
console.log("獲取分享服務(wù)列表失敗:" + e.message);
});
//#endif
},
methods:{
// 確認(rèn)支付
payment() {
.........
// #ifdef APP-PLUS
this.weixin ? this.weixin.launchMiniProgram({
path: `pagesB/payment/pay?price=${this.price}`,
type: 2, //可取值: 0-正式版; 1-測試版; 2-體驗版。 默認(rèn)值為0。
id: '............', //小程序的原始id
success(res) {
console.log('成功')
}
}) : plus.nativeUI.alert('當(dāng)前環(huán)境不支持微信操作!');
return
// #endife
}
// path里面的是路徑由自己決定需要跳轉(zhuǎn)到小程序哪一個頁面,此處也可以傳參哦!
}
- 小程序接收參數(shù),拉起微信支付
onLoad(option) {
// #ifdef MP
// app跳轉(zhuǎn)小程序支付 判斷
this.weixinFlag = options.weixinFlag
if (this.weixinFlag == '1') {
console.log('app跳轉(zhuǎn)小程序支付')
let data = res.data
//小程序 微信
uni.requestPayment({
provider: 'wxpay',
timeStamp: data.time_stamp,
nonceStr: data.nonce_str,
package: data.package,
signType: data.sign_type,
paySign: data.pay_sign,
success: (e) => {
console.log('支付成功')
},
fail: (e) => {
//用戶取消支付 不做處理
console.log("fail", e);
},
complete: (e) => {
console.log(e)
}
})
}
// #endif
}
?
文章來源:http://www.zghlxwxcb.cn/news/detail-590703.html
到了這里,關(guān)于app第三方支付,微信小程序支付的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!