- 如何解决ios系统在刷新公众号页面后签名失败的问题?
手机系统:ios16.5.1;开发框架:Vue2 路由模式:history 问题描述: ios设备做公众号开发时,正常打开公众号页面能正确加载jssdk,可以正常授权。但当在任意授权后的页面刷新页面过后,此时再次加载jssdk时报错invalid config,原因是微信判断当前页面是B,而后端传递的是A,所以导致授权链接无法验签成功。 问题复现描述: 1、打开A页面,将A页面的url记录进sessionStorage中 2、加签时提交sessionStorage中的记录给后端进行加签 3、返回签名结果再设置到wx.config中,此时签名加载结果为"errMsg":"config:ok" 4、打开B页面,签名加载结果为config:ok,当点击右上角三个小点,选择刷新按钮后,此时签名加载结果为"errMsg":"config:invalid signature" 问题复现视频: https://qhyg-test-1258702188.cos.ap-chengdu.myqcloud.com/upload/common/20200616/31-909068682.mp4 问题产生原因: 在ios下,vue-router切换的时候都是浏览器的历史记录,所以url其实都是一开始进入的url,每次签名只能使用首次打开SPA的url,也就是当你第一次打开A页面,再跳到B页面,需要拿A页面做签名。刷新B页面以后sessionStorage中地址没变还是A,但浏览器认定首次打开的是B页面,所以导致加签失败。 出现该问题应该如何处理! 部分实现代码 // router.js router.afterEach((to, from) => { const currentUrl = wechatUtil.montageUrl(to.fullPath) //IOS浏览器记录的是第一次进来的url if (wechatUtil.isIOS() && !wechatUtil.isWeChatDevTools()) { if (!store.state.page.initLink) { store.commit('setPageInitLink', currentUrl) } } else { store.commit('setPageInitLink', currentUrl) } }) //wechatUtil.js montageUrl(vueRouterTo) { const currentHostname = window.location.hostname; // 获取当前页面的域名 //协议部分(http 或 https) const protocol = window.location.protocol; // 完整的域名(包括协议和端口号,如果有的话) const fullUrlWithoutPath = `${protocol}//${currentHostname}${window.location.port ? `:${window.location.port}` : ''}`; return fullUrlWithoutPath + vueRouterTo; } //使用store.state.page.initLink 获取url传递给后台进行加签
01-24 - 公众号开发订阅标签wx-open-subscribe偶尔不显示问题?
操作系统:Windows11;开发者工具:Stable 1.06.2412050;微信jssdk:1.6.0;开发框架:js+vue2;appId:wx48c8d09b8960c309 问题描述:使用开发标签中订阅标签wx-open-subscribe,微信开发者工具时常会出现按钮不显示问题。真机调试时不会有该问题存在! 问题复现步骤,1:挂号历史页面点击再次挂号,进入挂号页【提交】按钮能正常显示。2:返回再次进入能正常显示【提交】按钮。但在第二次尝试后再次进入挂号页面【提交】按钮不在显示。从控制台中也可以看到每次jssdk的加签结果成功!复现视频如下图: [图片] 订阅标签部分实现代码 <!-- Vue 虚拟Dom代码 --> <wx-open-subscribe template="订阅模板id" @success="subscribeSuccess" @error="subscribeError" id="subscribe-btn" v-if="isWX"> <script type="text/wxtag-template"> <div style="background: #287AED;width: 325px;height: 40px;border-radius: 20px;font-size: 16px;color: #FFFFFF;display:flex;align-items:center;justify-content:center;"> 提交 </div> </script> </wx-open-subscribe> //Vue mounted事件 mounted() { //getSignature方法调取后端进行jssdk加签,currentUrl即当前页面的url this.getSignature(currentUrl).then(res => { wx.config({ debug: false, appId: res.appId, timestamp: res.timestamp, nonceStr: res.noncestr, signature: res.signature, jsApiList: ['checkJsApi'], openTagList: ['wx-open-subscribe','wx-open-subscribe-dialog'] }) wx.ready(() => { console.log("微信sdk准备完毕") }) wx.error(errRes => { console.log("微信sdk签名错误", errRes) }) }) }
01-23 - wx.navigateTo 说明文档中事例误导
测试机型:iPhone 8 puls 基础库: 问题描述: Page({ onLoad: function(option){ console.log(option.query) //实际跳转打开的新页面接值的参数在option参数中,按照前后文档描述,当前建议修改为:console.log(option.id) const eventChannel = this.getOpenerEventChannel() eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'}); eventChannel.emit('someEvent', {data: 'test'}); eventChannel.on('acceptDataFromOpenerPage', function(data) { console.log(data) }) } })
2020-04-16