- 公众号创建的云托管环境并使用 express 作为 webapi 服务器
- 通过公众号创建了小程序账号
- 云托管环境配置了小程序资源共享
- 小程序本地调试 调用 一键获取手机号 报错,内容为 Error: self-signed certificate
- 已传递 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)
})