url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+a_token['access_token']
params = {
"access_token": a_token['access_token'],
"code": f_dict["code"]
}
p_str = json.dumps(params)
resp = requests.post(url, data=p_str, headers=wx.header)
{"errcode":47001,"errmsg":"data format error hint: [WHDbJHnre-rck.] rid: 622717cc-7aa1a32b-0d8e9d72"}
如果我把params中access_token去掉就报
{"errcode":40013,"errmsg":"invalid appid hint: [0HDbr7Ore-cJd_9a] rid: 62271988-655b0736-6866f5e7"}
请问一定需要企业身份才能获取手机号吗
//JAVA HttpUtil类中
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type","application/json;charset=UTF-8");
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
//WechatUtil类中
public static JSONObject getPhoneNumber(String code){
JSONObject accessMessage=WechatUtil.getAccessToken();
String accessToken=accessMessage.getString("access_token");
System.out.println(accessToken);
System.out.println(code);
String requestUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+accessToken;
JSONObject obj = new JSONObject();
//小程序发来的code
obj.put("code", code);
//发送Post请求读取调用微信接口获取用户手机号
JSONObject jsonObject = JSONObject.fromObject(HttpClientUtil.doPostJson(requestUrl, obj.toString()));
return jsonObject;
}
url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={}".format(access_token) r = requests.post(url, data=json.dumps({'code': code}), headers={'Content-Type': 'application/json'}) res = r.json() # 按照这个方法请求,可行测过
我也遇到这个问题了,但绝不是appId不一致,真日了狗,WX 的技术不是一般的乱七八糟啊
json里面只有code. invalid appid是手机号这个接口报出来的?