vue——关于url造成签名错误:由于ios浏览器保存历史url造成的错误,解决方案使用js去调用config和设置自定义分享
api.js页 wxConfig (callback, errorCallback) { let params = { url: location.href } this.getJSSDKConfig(params).then((response) => { wx.config({ debug: false, appId: response.appId, timestamp: response.timestamp, nonceStr: response.nonceStr, signature: response.signature, jsApiList: ['chooseWXPay', 'updateTimelineShareData', 'onMenuShareAppMessage'] }) wx.ready(callback) wx.error(errorCallback) }) }, wxShare (title, link, imgUrl, desc) { wx.updateTimelineShareData({ title: title, // 分享标题 desc: desc, // 分享描述 link: link, imgUrl: imgUrl, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) wx.onMenuShareAppMessage({
title: title, // 分享标题 desc: desc, // 分享描述 link: link, // 分享链接 imgUrl: imgUrl, // 分享图标 success: function () { }, cancel: function () { } }) }
分享页
let that = this
this.getShop(() => {
let ua = navigator.userAgent
let isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1
if (isAndroid) {
that.config()
return
}
if (this.$route.query.share === 'sha') {
that.config()
return
}
that.share()
})
config () {
let that = this
this.$http.wxConfig(() => {
that.getUser()
that.share()
})
},
share () {
let title = (this.shop.shopName == undefined || this.shop.shopName == '' || this.shop.shopName == null) ? '购物' : this.productInfo.title
let link = 'http://www.baidu.cn/get-weixin-code.html?appid=748945878qwer&scope=snsapi_userinfo&state=ch&redirect_uri=' +
encodeURIComponent(location.href + '&share=sha')
let imgUrl = (this.sharePhoto == undefined || this.sharePhoto == '' || this.sharePhoto == null) ? location.protocol + location.host + '/logo.png' : location.protocol + location.host + this.sharePhoto
let desc = this.shop.introduction
desc = (desc == undefined || desc == '' || desc == null) ? '购物' : desc
this.$http.wxShare(title, link, imgUrl, desc)//参数必须有数据,格式要正确
}
分享link注意事项
link的url是重定向的url中可以带端口号,如果不是重定向的url不能带端口号,不然永远提示分享配置OK,分享出去的不是自定义的
Url签名错误解决方法2
const userAgent = global.navigator.userAgent;
const inIOS = /iPhone|iPad|iPod/i.test(userAgent);
beforeRouteEnter(to, from, next){
let allPath = "/XXX/mobile" + to.path
if (inIOS && allPath !== location.pathname) {
// 此处不可使用location.replace
location.assign("/XXX/mobile"+to.fullPath)
} else {
next()
}
}
此方法是让ios浏览器刷新加载当前页,使路由变成当前页!
文档可以自由分享请注明出处