Commit 3025bff63111108a60a3999f5e8a041e86756232
1 parent
2d44b3a2
【代码评审】SYSTEM:完善微信小程序码
Showing
3 changed files
with
39 additions
and
17 deletions
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| 1 | package cn.iocoder.yudao.module.member.controller.app.social; | 1 | package cn.iocoder.yudao.module.member.controller.app.social; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.codec.Base64; | 3 | import cn.hutool.core.codec.Base64; |
| 4 | -import cn.hutool.core.util.ObjUtil; | ||
| 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -33,13 +32,6 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | @@ -33,13 +32,6 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | ||
| 33 | @Validated | 32 | @Validated |
| 34 | public class AppSocialUserController { | 33 | public class AppSocialUserController { |
| 35 | 34 | ||
| 36 | - public static final String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | ||
| 37 | - private static final String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里) | ||
| 38 | - private static final Integer WIDTH = 430; // 二维码宽度 | ||
| 39 | - private static final Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||
| 40 | - private static final Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在 | ||
| 41 | - private static final Boolean HYALINE = true; // 是否需要透明底色, hyaline 为true时,生成透明底色的小程序码 | ||
| 42 | - | ||
| 43 | @Resource | 35 | @Resource |
| 44 | private SocialUserApi socialUserApi; | 36 | private SocialUserApi socialUserApi; |
| 45 | @Resource | 37 | @Resource |
| @@ -76,12 +68,7 @@ public class AppSocialUserController { | @@ -76,12 +68,7 @@ public class AppSocialUserController { | ||
| 76 | @PostMapping("/wxa-qrcode") | 68 | @PostMapping("/wxa-qrcode") |
| 77 | @Operation(summary = "获得微信小程序码(base64 image)") | 69 | @Operation(summary = "获得微信小程序码(base64 image)") |
| 78 | public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { | 70 | public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { |
| 79 | - byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath()) | ||
| 80 | - .setEnvVersion(ENV_VERSION).setWidth(ObjUtil.defaultIfNull(reqVO.getWidth(), WIDTH)) | ||
| 81 | - .setScene(ObjUtil.defaultIfNull(reqVO.getScene(), SCENE)) | ||
| 82 | - .setAutoColor(ObjUtil.defaultIfNull(reqVO.getAutoColor(), AUTO_COLOR)) | ||
| 83 | - .setHyaline(ObjUtil.defaultIfNull(reqVO.getHyaline(), HYALINE)) | ||
| 84 | - .setCheckPath(ObjUtil.defaultIfNull(reqVO.getCheckPath(), CHECK_PATH))); | 71 | + byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath())); |
| 85 | return success(Base64.encode(wxQrcode)); | 72 | return success(Base64.encode(wxQrcode)); |
| 86 | } | 73 | } |
| 87 | 74 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxQrcodeReqDTO.java
| @@ -13,6 +13,35 @@ import lombok.Data; | @@ -13,6 +13,35 @@ import lombok.Data; | ||
| 13 | public class SocialWxQrcodeReqDTO { | 13 | public class SocialWxQrcodeReqDTO { |
| 14 | 14 | ||
| 15 | /** | 15 | /** |
| 16 | + * 小程序版本 | ||
| 17 | + * | ||
| 18 | + * 正式版为 "release";体验版为 "trial";开发版为 "develop" | ||
| 19 | + */ | ||
| 20 | + public static final String ENV_VERSION = "release"; | ||
| 21 | + /** | ||
| 22 | + * 页面路径不能携带参数(参数请放在scene字段里) | ||
| 23 | + */ | ||
| 24 | + public static final String SCENE = ""; | ||
| 25 | + /** | ||
| 26 | + * 二维码宽度 | ||
| 27 | + */ | ||
| 28 | + public static final Integer WIDTH = 430; | ||
| 29 | + /** | ||
| 30 | + * 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||
| 31 | + */ | ||
| 32 | + public static final Boolean AUTO_COLOR = true; | ||
| 33 | + /** | ||
| 34 | + * 检查 page 是否存在 | ||
| 35 | + */ | ||
| 36 | + public static final Boolean CHECK_PATH = true; | ||
| 37 | + /** | ||
| 38 | + * 是否需要透明底色 | ||
| 39 | + * | ||
| 40 | + * hyaline 为 true 时,生成透明底色的小程序码 | ||
| 41 | + */ | ||
| 42 | + public static final Boolean HYALINE = true; | ||
| 43 | + | ||
| 44 | + /** | ||
| 16 | * 场景 | 45 | * 场景 |
| 17 | */ | 46 | */ |
| 18 | @NotEmpty(message = "场景不能为空") | 47 | @NotEmpty(message = "场景不能为空") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| @@ -233,9 +233,15 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -233,9 +233,15 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 233 | public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { | 233 | public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { |
| 234 | WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue()); | 234 | WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue()); |
| 235 | try { | 235 | try { |
| 236 | - return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), | ||
| 237 | - reqVO.getCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getAutoColor(), | ||
| 238 | - null, reqVO.getHyaline()); | 236 | + return service.getQrcodeService().createWxaCodeUnlimitBytes( |
| 237 | + ObjUtil.defaultIfEmpty(reqVO.getScene(), SocialWxQrcodeReqDTO.SCENE), | ||
| 238 | + reqVO.getPath(), | ||
| 239 | + ObjUtil.defaultIfNull(reqVO.getCheckPath(), SocialWxQrcodeReqDTO.CHECK_PATH), | ||
| 240 | + ObjUtil.defaultIfBlank(reqVO.getEnvVersion(), SocialWxQrcodeReqDTO.ENV_VERSION), | ||
| 241 | + ObjUtil.defaultIfNull(reqVO.getWidth(), SocialWxQrcodeReqDTO.WIDTH), | ||
| 242 | + ObjUtil.defaultIfNull(reqVO.getAutoColor(), SocialWxQrcodeReqDTO.AUTO_COLOR), | ||
| 243 | + null, | ||
| 244 | + ObjUtil.defaultIfNull(reqVO.getHyaline(), SocialWxQrcodeReqDTO.HYALINE)); | ||
| 239 | } catch (WxErrorException e) { | 245 | } catch (WxErrorException e) { |
| 240 | log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e); | 246 | log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e); |
| 241 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR); | 247 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR); |