收藏
回答

wx.getLocation ios端报错getLocation invalid signatur?

在安卓端和开发工具里面都能正常获取到经纬度,传入的url就是页面初始进入的url


let url

if (navigator.userAgent.indexOf('iPhone') !== -1) { // BUG: IOS获取签名传递的URL必须是项目一打开的首页URL,否则签名无效

  url = Cache.get('href') ? Cache.get('href') : location.href

} else { // 安卓传递当前页面URL

  url = location.href

}

// 此处存在BUG如果url中存在参数需要陷阱行转码才能传给后端,否则生成的签名错误 encodeURIComponent(url)

getJsSdk({ url: encodeURIComponent(url)}).then(res=>{

wx.config({

  debug: false,

  appId: res?.data?.appId,

  timestamp: res?.data?.timestamp,

  nonceStr: res?.data?.noncestr,

  signature: res?.data?.signature,

  jsApiList: ['getLocation']

})

wx.ready(()=>{

wx.checkJsApi({

jsApiList: ['getLocation'],

success: function(res){

console.log(res)

if (res.checkResult['getLocation']) {

wx.getLocation({

type: 'wgs84',

isHighAccuracy: true,

altitude: true,

success: function(res){

const latitude = res.latitude

const longitude = res.longitude

map.value.setCenter([res.longitude, res.latitude]);

showInfoClick({

lnglat: [res.longitude, res.latitude]

})

},

fail(res) {

title.value = JSON.stringify(res)

}

})

} else {

alert('你的微信版本过低,请更新至最新版本。');

}

}

})


})

}).catch(err=>{

})


回答关注问题邀请回答
收藏

2 个回答

  • LS
    LS
    2025-10-10

    最后你是怎么处理的?

    2025-10-10
    有用
    回复
  • Mr.Zhao
    Mr.Zhao
    2025-07-09

    vue的问题,跟jssdk没关系

    2025-07-09
    有用
    回复 4
    • 灰太狼
      灰太狼
      2025-07-09
      啥问题呢?我现在进入首页后再跳转到jssdk注入的页面就能正常获取经纬度,但是我直接在地址栏输入jssdk注入的页面地址就获取失败
      2025-07-09
      回复
    • Mr.Zhao
      Mr.Zhao
      发表于小程序端
      2025-07-09回复灰太狼

      问题就是你写注释的那句话

      2025-07-09
      回复
    • LS
      LS
      2025-10-10
      陷阱行转码 是什么个处理方式?
      2025-10-10
      回复
    • Mr.Zhao
      Mr.Zhao
      2025-10-10回复LS
      他估计有口音打错字了,需要url需要encode
      2025-10-10
      回复
登录 后发表内容