收藏
回答

/wxa/getwxacodeunlimit接口总返回412 Precondition Fail?

调用这个接口,总是返回412,求助,代码如下:

String accessToken = wechatClient.getAccessToken();
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;

Map<String, Object> params = new HashMap<>();
params.put("scene", "test");
params.put("page", "pages/home/home");
params.put("check_path", false);
params.put("env_version", "trial");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(params, headers);

ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
// ResponseEntity<byte[]> response = restTemplate.postForEntity(url, requestEntity, byte[].class);

Map<String, Object> result = new HashMap<>();
result.put("success", response.getStatusCode().is2xxSuccessful());
result.put("statusCode", response.getStatusCode().value());
result.put("responseBody", response.getBody());

if (response.getBody() != null && response.getBody().trim().startsWith("{")) {
    JSONObject json = JSONUtil.parseObj(response.getBody());
    result.put("errcode", json.getInt("errcode"));
    result.put("errmsg", json.getStr("errmsg"));
}

return R.ok("原始二维码测试完成", result);


具体日志:

2025-09-29 21:34:24 [XNIO-1 task-2] DEBUG o.s.web.client.RestTemplate
 - HTTP POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=96_D-TSbDE1S-T0N1MO1LU9aZG6U26JI_RsD8BYVJUkzok4junXQXeJP3Q1wsvaX17KtqQ-b5gObrqvZXL4gr3bzDyb4pVqlq-usvHYtWEgJsswsJNES_vRpjly-DsYXGaAEATSB
2025-09-29 21:34:24 [XNIO-1 task-2] DEBUG o.s.web.client.RestTemplate
 - Accept=[text/plain, application/json, application/yaml, application/*+json, */*]
2025-09-29 21:34:24 [XNIO-1 task-2] DEBUG o.s.web.client.RestTemplate
 - Writing [{check_path=false, page=pages/home/home, scene=test, env_version=trial}] as "application/json"
2025-09-29 21:34:24 [XNIO-1 task-2] DEBUG o.s.web.client.RestTemplate
 - Response 412 PRECONDITION_FAILED

 

这是我小程序状态,没发布过,但是审核通过了,现在在测试阶段!

回答关注问题邀请回答
收藏

2 个回答

  • Mr.Zhao
    Mr.Zhao
    发表于小程序端
    2025-09-30

    代码问题,跟发布没关系。换个 springboot 版本,或者 httpcilent 就不报错了

    2025-09-30
    有用 1
    回复 3
    • Fion
      Fion
      2025-09-30
      我去,还真是,换了个httpclient就行了!
      感谢大佬!
      话说这个到底啥原因啊,有说法么
      2025-09-30
      回复
    • Mr.Zhao
      Mr.Zhao
      2025-09-30回复Fion
      content-length 问题,spring升级了,框架取消自动计算长度了
      2025-09-30
      1
      回复
    • Fion
      Fion
      2025-09-30回复Mr.Zhao
      👍🏻 非常感谢
      2025-09-30
      回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-09-29
    有用
登录 后发表内容