From 684baad8c62176c89f675381c28f85f742c86df0 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 27 八月 2025 13:48:53 +0800 Subject: [PATCH] bug修改 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java index 5929a93..e95f68e 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java @@ -39,6 +39,7 @@ import com.ruoyi.system.api.feignClient.SysUserClient; import com.ruoyi.system.api.model.LoginUser; import io.swagger.annotations.ApiOperation; +import org.apache.http.HttpResponse; import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; @@ -194,7 +195,7 @@ } @ApiOperation(tags = {"2.0-积分钱包"}, value = "获取小程序二维码") @PostMapping(value = "/getQrCode") - public R getQrCode() { + public R getQrCode(@RequestParam("amount") String amount ) { LoginUser loginUser = tokenService.getLoginUser(); SysUser data = sysUserClient.getSysUser(loginUser.getUserid()).getData(); // 充值手机号 @@ -203,9 +204,9 @@ OutputStream outputStream = null; String accessToken = wxAppletTools.getAccessToken(); try { - String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; +// String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; Map<String, Object> param = new HashMap<>(); - param.put("scene", "phone=" + phonenumber); + param.put("scene", "phone=" + phonenumber+",amount="+amount); param.put("check_path", false); param.put("env_version", "trial"); param.put("width", 200); //二维码尺寸 @@ -217,12 +218,18 @@ line_color.put("b", 0); param.put("line_color", line_color); System.err.println("调用生成微信URL接口传参:" + param); - MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); - HttpEntity requestEntity = new HttpEntity(param, headers); - ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); - System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody()); - byte[] result = entity.getBody(); - inputStream = new ByteArrayInputStream(result); +// MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); +// HttpEntity requestEntity = new HttpEntity(param, headers); +// ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); +// System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody()); +// byte[] result = entity.getBody(); + //路径也是固定的"https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; + //这里有个坑,需要用HttpResponse获取,不然会有问题 + HttpResponse httpResponse = HttpUtils.doPost(url, new JSONObject(param)); + //拿到httpResponse后,在获取里面的图片 + inputStream = httpResponse.getEntity().getContent(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); // 最后上传生成的文件名 String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg"; -- Gitblit v1.7.1