String url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" + accessToken; // 封装跳转小程序的参数 JSONObject param = new JSONObject(); JSONObject query = new JSONObject(); param.put("path","/pages/qrcode/qrcode"); param.put("env_version","release"); param.put("query",""); query.put("jump_wxa",param); query.put("is_expire",true); // query.put("expire_time","30"); query.put("expire_type",1); query.put("expire_interval",1); String body = JSONUtil.toJsonStr(query); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentLength(body.getBytes(StandardCharsets.UTF_8).length); HttpEntity<String> httpEntity = new HttpEntity<>(body, headers); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url,JSONUtil.toJsonStr(httpEntity),JSONObject.class); HttpStatusCode statusCode = responseEntity.getStatusCode(); //状态码 if (Objects.equals(statusCode.value(), 200)) { JSONObject responseJsonBody = responseEntity.getBody(); //响应体 assert responseJsonBody != null; log.error("responseJsonBody={}",responseJsonBody); return responseJsonBody.getStr("openlink"); }else{ log.error("请求微信服务器状态码错误"); return null; }
java后端调用generateScheme方法一直报错 47001java 后端接口调用 POST https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN 一直返回这个错误码 47001 我都是按照文档来传的参数 到后面我甚至没有传参数了 还是一直这个错误 {"errcode":47001,"errmsg":"data format error rid: 67502520-6ee766f7-2929536a"} z昨天以为贴了图片 结果没贴上去。。。 代码见评论
2024-12-05