最近有个需求,要在公众号做定位功能。接的高德api。
万事俱备,安卓完美。但是一到ios调用wx.config的时候就报错config:invalid signature
在网上找了很久,说是url不一样导致,但是打印出来的url都是一样的啊
但又琢磨一会儿发现这打印出的是假象
因为首页调用时ios是可以的,但进入另一个页面再调用wx.config就不行了
其实在其他页面做个判断就行了,是ios就不调wx.config

let getSystemInfoSync = uni.getSystemInfoSync();
            console.log('获取设备 getSystemInfoSync: ', getSystemInfoSync);
            if(getSystemInfoSync.platform == "ios"){
                this.isIos = true;
            }
if(!this.isIos){
                    getWechatConfig(params, (res) => {
                        let wechatCustomerVo = res.data.result;
                        //var str = JSON.stringify(obj);
                        this.theWechatCustomerVoResObj = JSON.stringify(res);

                        wx.config({
                            debug: false,
                            appId: wechatCustomerVo.mpAppId,
                            timestamp: wechatCustomerVo.mpTimestamp,
                            nonceStr: wechatCustomerVo.mpNonceStr,
                            signature:  wechatCustomerVo.mpSignature,
                            jsApiList: ["getLocation","openLocation",'updateTimelineShareData']
                        })
                        wx.error(function(err){
                            // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
                            console.log("微信config配置失败 err: ", err);
                            that.wxErr = JSON.stringify(err);
                            that.wxConfigData = '微信config配置失败';
                            uni.showToast({
                                icon: 'none',
                                title: `微信配置失败`
                            })
                        });
                    })
                }
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐