试过spring boot 3.3.0、3.2.6和3.1.2,最终3.1.2是可以的,没有找到具体的原因,希望有大神能够解决。
小程序手机号解析接口一直报 412 Precondition Failed: [no body]?public String getPhoneNumber(String phoneCode) { JSONObject params = new JSONObject(); params.put("code", phoneCode); String url = MessageFormat.format("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={0}", getAccessToken()); JSONObject reObj = restTemplate.postForObject(url, params, JSONObject.class); if (reObj != null && reObj.containsKey("errcode")) { log.info(reObj.toJSONString()); if (reObj.getInteger("errcode") == 0) { Code2PhoneNumberResponse code2PhoneNumberResponse = JSONObject.parseObject(reObj.toJSONString(), Code2PhoneNumberResponse.class); return code2PhoneNumberResponse.getPhoneInfo().getPurePhoneNumber(); } } return null; }
2024-06-15