1.微信权限注入
(1) 引入js包文件, npm install jweixin-module --save
引入 let jweixin = require(‘jweixin-module’);
(2) 请求后端接口获取签名
/**
* @desc 微信注入授权
* */
wxAuth(){
let _this = this;
let url = location.href.split('#')[0]
_this.$u.api.wxauthApi({url:url}).then(res=>{
let pay = res.data;
jweixin.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: res.data.appId, // 必填,公众号的唯一标识
timestamp: res.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature, // 必填,签名
jsApiList: [ //这里是需要用到的接口名称
'checkJsApi',
'updateTimelineShareData',
'hideOptionMenu',
'updateAppMessageShareData',
'hideMenuItems',
'showMenuItems',
'chooseWXPay'
], // 必填,需要使用的JS接口列表
// openId: t_openid
})
})
},
2.调用分享函数或者支付函数
(1)示例支付函数
/**
* 测试微信支付
* */
callPay(response) {
// uni.hideLoading();
jweixin.chooseWXPay({
timestamp: response.timeStamp, // 支付签名时间戳,注意微信 jssdk 中的所有使用 timestamp 字段均为小写。但最新版的支付后台生成签名使用的 timeStamp 字段名需大写其中的 S 字符
nonceStr: response.nonceStr, // 支付签名随机串,不长于 32 位
package: response.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
signType: response.signType, // 微信支付V3的传入 RSA ,微信支付V2的传入格式与V2统一下单的签名格式保持一致
paySign: response.paySign, // 支付签名
success: function (res) {
// 支付成功后的回调函数
this.$navTo('/pages/shop/order/detail',{id:response.order_id});
}
});
}
(2)分享示例
我还没写呢,写了再更新吧