ios分享问题

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浏览器刷新加载当前页,使路由变成当前页!

文档可以自由分享请注明出处

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值