Commit 380ec112217a442b31172a527fb7f0c2ead7d428

Authored by puhui999
1 parent 52b97290

完善微信小程序码

yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
@@ -70,7 +70,7 @@ public class AppSocialUserController { @@ -70,7 +70,7 @@ public class AppSocialUserController {
70 @Operation(summary = "获得微信小程序码(base64 image)") 70 @Operation(summary = "获得微信小程序码(base64 image)")
71 public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { 71 public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
72 byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class) 72 byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)
73 - .setUserId(getLoginUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType())); 73 + .setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION));
74 return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode)); 74 return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode));
75 } 75 }
76 76
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java
1 package cn.iocoder.yudao.module.member.controller.app.social.vo; 1 package cn.iocoder.yudao.module.member.controller.app.social.vo;
2 2
3 -import cn.iocoder.yudao.framework.common.validation.InEnum;  
4 -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;  
5 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
6 import jakarta.validation.constraints.NotEmpty; 4 import jakarta.validation.constraints.NotEmpty;
7 -import jakarta.validation.constraints.NotNull;  
8 import lombok.Data; 5 import lombok.Data;
9 6
10 -// TODO @芋艿:需要精简下参数; 7 +
11 @Schema(description = "用户 APP - 获得获取小程序码 Request VO") 8 @Schema(description = "用户 APP - 获得获取小程序码 Request VO")
12 @Data 9 @Data
13 public class AppSocialWxQrcodeReqVO { 10 public class AppSocialWxQrcodeReqVO {
14 11
15 - // TODO @puhui999:这个后续不用前端传递,应该是后端搞的。  
16 - // 页面路径不能携带参数(参数请放在scene字段里)  
17 - private static String SCENE = ""; // 默认场景值 1011 扫描二维码  
18 - // TODO @puhui999:这个默认是不是 release 哈?  
19 - private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"  
20 - // TODO @puhui999:这个去掉;因为本身就是 430 啦; 12 + // TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣
  13 + public static String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
  14 + private static String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里)
21 private static Integer WIDTH = 430; // 二维码宽度 15 private static Integer WIDTH = 430; // 二维码宽度
22 - // TODO @puhui999:这个去掉;因为本身就是 true 啦;  
23 private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 16 private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
24 - // TODO @puhui999:这个去掉;因为本身就是 true 啦;  
25 private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在 17 private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
26 - // TODO @puhui999:这个去掉;因为本身就是 true 啦;  
27 - private static Boolean IS_HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 18 + private static Boolean HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
28 19
  20 + /**
  21 + * 页面路径不能携带参数(参数请放在scene字段里)
  22 + */
29 @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") 23 @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
30 private String scene = SCENE; 24 private String scene = SCENE;
31 25
@@ -37,25 +31,16 @@ public class AppSocialWxQrcodeReqVO { @@ -37,25 +31,16 @@ public class AppSocialWxQrcodeReqVO {
37 @NotEmpty(message = "页面路径不能为空") 31 @NotEmpty(message = "页面路径不能为空")
38 private String path; 32 private String path;
39 33
40 - // TODO @puhui999:这个应该不传递哈  
41 - @Schema(description = "小程序版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "develop")  
42 - private String envVersion = ENV_VERSION;  
43 -  
44 @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430") 34 @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
45 private Integer width = WIDTH; 35 private Integer width = WIDTH;
46 36
47 @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") 37 @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
48 - private Boolean isAutoColor = AUTO_COLOR; 38 + private Boolean autoColor = AUTO_COLOR;
49 39
50 @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") 40 @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
51 - private Boolean isCheckPath = CHECK_PATH; 41 + private Boolean checkPath = CHECK_PATH;
52 42
53 @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") 43 @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
54 - private Boolean isHyaline = IS_HYALINE;  
55 -  
56 - @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")  
57 - @InEnum(SocialTypeEnum.class)  
58 - @NotNull(message = "社交平台的类型不能为空")  
59 - private Integer type; 44 + private Boolean hyaline = HYALINE;
60 45
61 } 46 }
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxQrcodeReqDTO.java
1 package cn.iocoder.yudao.module.system.api.social.dto; 1 package cn.iocoder.yudao.module.system.api.social.dto;
2 2
3 -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;  
4 -import cn.iocoder.yudao.framework.common.validation.InEnum;  
5 -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;  
6 import jakarta.validation.constraints.NotEmpty; 3 import jakarta.validation.constraints.NotEmpty;
7 -import jakarta.validation.constraints.NotNull;  
8 import lombok.Data; 4 import lombok.Data;
9 5
10 /** 6 /**
11 * 获取小程序码 Request DTO 7 * 获取小程序码 Request DTO
12 * 8 *
13 - * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html">获取不限制的小程序码</a>  
14 - *  
15 * @author HUIHUI 9 * @author HUIHUI
  10 + * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html">获取不限制的小程序码</a>
16 */ 11 */
17 @Data 12 @Data
18 public class SocialWxQrcodeReqDTO { 13 public class SocialWxQrcodeReqDTO {
19 14
20 - // TODO @puhui999:userId、userType 应该后续要搞成抽象参数;说白了,就是 path 的参数; socialType 应该去掉,因为就是微信的;  
21 - /**  
22 - * 用户编号  
23 - */  
24 - @NotNull(message = "用户编号不能为空")  
25 - private Long userId;  
26 - /**  
27 - * 用户类型  
28 - */  
29 - @InEnum(UserTypeEnum.class)  
30 - @NotNull(message = "用户类型不能为空")  
31 - private Integer userType;  
32 -  
33 - /**  
34 - * 社交平台的类型  
35 - */  
36 - @InEnum(SocialTypeEnum.class)  
37 - @NotNull(message = "社交平台的类型不能为空")  
38 - private Integer socialType;  
39 -  
40 /** 15 /**
41 * 场景 16 * 场景
42 */ 17 */
@@ -56,23 +31,17 @@ public class SocialWxQrcodeReqDTO { @@ -56,23 +31,17 @@ public class SocialWxQrcodeReqDTO {
56 */ 31 */
57 private Integer width; 32 private Integer width;
58 33
59 - // TODO @puhui999:autoColor  
60 -  
61 /** 34 /**
62 * 是否需要透明底色 35 * 是否需要透明底色
63 */ 36 */
64 - private Boolean isAutoColor;  
65 -  
66 - // TODO @puhui999: checkPath 37 + private Boolean autoColor;
67 /** 38 /**
68 * 是否检查 page 是否存在 39 * 是否检查 page 是否存在
69 */ 40 */
70 - private Boolean isCheckPath;  
71 -  
72 - // TODO @puhui999: hyaline 41 + private Boolean checkPath;
73 /** 42 /**
74 * 是否需要透明底色 43 * 是否需要透明底色
75 */ 44 */
76 - private Boolean isHyaline; 45 + private Boolean hyaline;
77 46
78 } 47 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
@@ -9,6 +9,7 @@ import cn.hutool.core.lang.Assert; @@ -9,6 +9,7 @@ import cn.hutool.core.lang.Assert;
9 import cn.hutool.core.util.ObjUtil; 9 import cn.hutool.core.util.ObjUtil;
10 import cn.hutool.core.util.ReflectUtil; 10 import cn.hutool.core.util.ReflectUtil;
11 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 11 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  12 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
12 import cn.iocoder.yudao.framework.common.pojo.PageResult; 13 import cn.iocoder.yudao.framework.common.pojo.PageResult;
13 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; 14 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
14 import cn.iocoder.yudao.framework.common.util.http.HttpUtils; 15 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
@@ -230,11 +231,11 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -230,11 +231,11 @@ public class SocialClientServiceImpl implements SocialClientService {
230 231
231 @Override 232 @Override
232 public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { 233 public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
233 - WxMaService service = getWxMaService(reqVO.getUserType()); 234 + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
234 try { 235 try {
235 return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), 236 return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(),
236 - reqVO.getIsCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getIsAutoColor(),  
237 - null, reqVO.getIsHyaline()); 237 + reqVO.getCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getAutoColor(),
  238 + null, reqVO.getHyaline());
238 } catch (WxErrorException e) { 239 } catch (WxErrorException e) {
239 log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e); 240 log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
240 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR); 241 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);