在后台调用getuserphonenumber接口一直报错,是不能在后台用吗?

小程序 文章 2022-03-07 14:20 689 0 全屏看文

AI助手支持GPT4.0

在后台调用getuserphonenumber接口一直报错,是不能在后台用吗?Calling the getuserphonenumber interface in the background keeps reporting an error. Can it be used in the background?

在后台调用getuserphonenumber接口一直报错,是不能在后台用吗?

小程序需要获取手机号,通过界面按钮获取code值后,提交给后台获取手机号:

1、通过接口:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=""&secret=""获取到access_token值后调用接口:

2、https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token='+access_token+"&code="+phoneCode,调用后提示:

data format error hint: [Wgdbr7Ore-oEm.7] rid: 62259c4a-7c28684e-6eb764dc

The applet needs to obtain the mobile phone number. After obtaining the code value through the interface button, submit it to the background to obtain the mobile phone number: 1. Through the interface: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= "" & Secret = "" get access "_ Token value after calling interface: 2, https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token= '+access_ Token + "& code =" + phonecode, prompt after calling: data format error hint: [wgdbr7ore OEM. 7] rid: 62259c4a-7c28684e-6eb764dc

回答:

拾忆:

需要通过用户触发button按钮返回的code才可以。

再见,电脑崽:

微信的请求都是POST的而且数据是json格式,文档稍微有点误导:

curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"code": "e31968a7f94cc5ee25fafc2aef2773f0bb8c3937b22520eb8ee345274d00c144"}' https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN
VBit:

code不要写在url里面

~^_^~:去掉了提示错误码40029,invalid code hint: [DGdb9_I2e-ve1C6a] rid: 6225a161-6f4c1862-196a5fd3
~^_^~:可以了,谢谢,code值用过一次了

-EOF-

AI助手支持GPT4.0