问题描述
检测代码发现没什么问题,但是首次进入页面分享会提示"errMsg":"updateAppMessageShareData:the permission value is offline verifying",分享失败,多次刷新页面又会正常
解决办法
h5端需要使用window.location.href 进行页面跳转
代码模块
shareInterfaceFun(shareUrl, params_platform) {
let api = '/plugin/pay/gettdddd'
let res = this.$util.httpGet(api, {
url: encodeURIComponent(window.location.href),
platform: params_platform
}).then((res)=>{
if (res.code === 1) {
let data = res.data
// #ifdef H5
this.shareData(shareUrl, data)
// #endif
// #ifdef APP-PLUS
this.appShare(shareUrl, data)
// #endif
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
},
shareData(shareUrl, data) {
let jweixin = require('jweixin-module')
jweixin.config({
debug: true, // 开启调试模式
appId: this.$config.appid, // 必填,公众号的唯一标识
timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature, // 必填,签名
jsApiList: ['updateAppMessageShareData', updateTimelineShareData'] // 必填,需要使用的 JS 接口列表
});
let _this = this
jweixin.ready(function() { //需在用户可能点击分享按钮前就先调用
jweixin.updateAppMessageShareData({
title: data.title, // 分享标题
desc: data.desc, // 分享描述
link: shareUrl || data.url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
imgUrl: data.share_img, // 分享图标
success: function() {
// 设置成功
console.log('成功')
},
fail: function(err) {
console.log('失败', err)
}
})
//朋友圈
jweixin.updateTimelineShareData({
title: data.title, // 分享标题
link: shareUrl || data.url,
imgUrl: data.share_img, // 分享图标
success: function() {
// 设置成功
}
})
})
}