调用getuserphonenumber一直是40029?
// 获取用户手机号
public static JSONObject getPhoneNumber(String appId, String secret, String code) {
//通过appid和secret来获取token
//WXContent.APPID是自定义的全局变量
String tokenUrl = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId, secret);
com.alibaba.fastjson.JSONObject token = JSON.parseObject(HttpUtil.get(tokenUrl));
//通过token和code来获取用户手机号
String url = "https://api.weixin.qq.com/wxa/business/
?access_token=" + token.getString("access_token");
//封装请求体
Map paramMap = new HashMap<>();
paramMap.put("code", code);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity> httpEntity = new HttpEntity<>(paramMap,headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity response = restTemplate.postForEntity(url, httpEntity, Object.class);
return new JSONObject(response.getBody());
}