收藏
回答

微信小程序资源复用情况下一键获取手机号接口签名错误如何解决?

  1. 公众号创建的云托管环境并使用 express 作为 webapi 服务器
  2. 通过公众号创建了小程序账号
  3. 云托管环境配置了小程序资源共享
  4. 小程序本地调试 调用 一键获取手机号 报错,内容为 Error: self-signed certificate
  5. 已传递 frome-appid (query)和 openid (body)

如下是 express 请求代码

app.all('/api/wx/getuserphonenumber', async (req, res) => {
  const openid = req.headers['x-wx-openid'] // 小程序直接callcontainer请求会存在
  const { code } = req.body


  const options = {
    method: 'POST',
    url:
      'https://api.weixin.qq.com/wxa/business/getuserphonenumber?' +
      new URLSearchParams({
        from_appid: req.headers['x-wx-from-appid'],
      }),
    data: {
      code,
      openid,
    },
  }


  console.log('20250405192151', JSON.stringify(options))


  const response = await axios.request(options)


  const result = response.data
  res.send(result)
})

回答关注问题邀请回答
收藏
登录 后发表内容