From 3ffbdbfb5bbc87df2f34c08026375dc170cac695 Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Wed, 18 Sep 2024 09:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 10 +- hiver-admin/test-output/test-report.html | 16 +-- hiver-modules/hiver-mall/pom.xml | 6 + .../mall/controller/OrderController.java | 116 ++++++++++++++++-- .../mall/utils/ByteArrayMultipartFile.java | 58 +++++++++ 5 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/ByteArrayMultipartFile.java diff --git a/hiver-admin/src/main/resources/application.yml b/hiver-admin/src/main/resources/application.yml index 4c127a6f..ef3e36d2 100644 --- a/hiver-admin/src/main/resources/application.yml +++ b/hiver-admin/src/main/resources/application.yml @@ -25,8 +25,8 @@ spring: timeout-per-shutdown-phase: 10S # 数据源 datasource: -# url: jdbc:mysql://154.8.162.157:3306/hiver_shop?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true - url: jdbc:mysql://8.140.198.243:3306/hiver_shop?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true + url: jdbc:mysql://154.8.162.157:3306/hiver_shop?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true +# url: jdbc:mysql://8.140.198.243:3306/hiver_shop?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true username: reddoor # Jasypt加密 可到common-utils中找到JasyptUtil加解密工具类生成加密结果 格式为ENC(加密结果) 以下解密结果为123456 password: ENC(Zla4U4+yRLPhicvuX2TmiEgxEpzP4dk8BHzFDEtiEhwLQIIaftZrrEUJZce6efoe) @@ -67,8 +67,8 @@ spring: ddl-auto: update # Redis 若设有密码自行添加配置password redis: -# host: 154.8.162.157 - host: 8.140.198.243 + host: 154.8.162.157 +# host: 8.140.198.243 password: reddoor168 # 数据库索引 默认0 database: 1 @@ -339,6 +339,8 @@ ignored: - /hiver/app/customer/findByUserPhoneAndShopId # 分享页获取店铺分类 - /hiver/app/productCategory/listByShopId + # 获取微信二维码 + - /hiver/order/ow/getWechatQrcode # 临时增加 - /hiver/app/logisticsOrder/addLogisticsOrder diff --git a/hiver-admin/test-output/test-report.html b/hiver-admin/test-output/test-report.html index 03c2ceec..34ee760a 100644 --- a/hiver-admin/test-output/test-report.html +++ b/hiver-admin/test-output/test-report.html @@ -35,7 +35,7 @@ Hiver
passTest
-15:39:35 / 0.026 secs
+23:19:42 / 0.018 secs
Started
-Ended
-
@@ -358,8 +373,8 @@ public class OrderController {
final String transCompanyId = sale.getTransCompany();
final String shopId = sale.getShopId();
final String saleId = sale.getId();
- String transportType = sale.getTransportType();
- deductLogService.updateRebateAmount(workId, transCompanyId, shopId, saleId,transportType);
+ final String transportType = sale.getTransportType();
+ deductLogService.updateRebateAmount(workId, transCompanyId, shopId, saleId, transportType);
}
} else {
@@ -413,7 +428,7 @@ public class OrderController {
/**
* 转单接口
*
- * @param orderXd
+ * @param orderVO
* @return Result
* @author 王富康
* @date 2024/2/27
@@ -435,4 +450,87 @@ public class OrderController {
}
}
+
+ /**
+ * 获取不限制的小程序码
+ * 参考链接:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
+ *
+ * @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
+ * @param page 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
+ * @param envVersion 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
+ * @return byte[]
+ * @author 王富康
+ * @date 2024/9/14
+ */
+ @RequestMapping(value = "/ow/getWechatQrcode", method = RequestMethod.POST)
+ @ApiOperation("获取不限制的小程序码")
+ public Result getWechatQrcodeByOkhttp3(String scene, String page, String envVersion) {
+ // 非空校验
+ if (StringUtils.isEmpty(scene)) {
+ return ResultUtil.error("参数错误");
+ }
+
+ //获取AccessToken地址
+ String wechatQrcodeAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
+ wechatQrcodeAccessTokenUrl = wechatQrcodeAccessTokenUrl.replace("APPID", "wx6d7d4fb58d1502db").replace("APPSECRET", "3a2c8cd00926764bbd12fd7361e01f1d");
+
+ try {
+ final URL url = new URL(wechatQrcodeAccessTokenUrl);
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Accept", "application/json");
+
+ final int responseCode = connection.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String inputLine;
+ final StringBuffer content = new StringBuffer();
+ while ((inputLine = in.readLine()) != null) {
+ content.append(inputLine);
+ }
+ in.close();
+ connection.disconnect();
+
+ // 解析JSON数据
+ final JsonObject jsonObject = JsonParser.parseString(content.toString()).getAsJsonObject();
+ final String wxAccessToken = jsonObject.get("access_token").getAsString();
+ log.info("获取小程序码getQrtAccessToken成功:{}", wxAccessToken);
+ //获取小程序码地址
+ final String wechatQrcodeUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + wxAccessToken;
+ final OkHttpClient client = new OkHttpClient();
+ final JSONObject jsonBody = new JSONObject();
+ jsonBody.set("scene", scene);
+ jsonBody.set("page", page);
+ jsonBody.set("env_version", envVersion);
+ final okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(MediaType.parse("application/json"), jsonBody.toString());
+ final Request request = new Request.Builder()
+ .url(wechatQrcodeUrl)
+ .post(requestBody)
+ .build();
+ try (Response response = client.newCall(request).execute()) {
+ if (response.isSuccessful() && response.body() != null) {
+ // 上传到服务器,返回地址。
+ final byte[] bytes = response.body().bytes();
+ final String contentType = "image/png"; // 文件类型
+ // 上传至第三方云服务或服务器
+ final MultipartFile multipartFile = new ByteArrayMultipartFile(bytes, "qrcode.png", contentType);
+ final String fKey = CommonUtil.renamePic(multipartFile.getOriginalFilename());
+ final InputStream inputStream = multipartFile.getInputStream();
+ final String result = fileManageFactory.getFileManage(null).inputStreamUpload(inputStream, fKey, multipartFile);
+ return new ResultUtil