Commit b227b039c961d04ba49af8f022278c784b4c3431
1 parent
33e8c7ca
MEMBER: 根据【代码评审】完善微信小程序码
Showing
2 changed files
with
21 additions
and
20 deletions
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| 1 | 1 | package cn.iocoder.yudao.module.member.controller.app.social; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.codec.Base64; | |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| ... | ... | @@ -22,8 +24,6 @@ import jakarta.validation.Valid; |
| 22 | 24 | import org.springframework.validation.annotation.Validated; |
| 23 | 25 | import org.springframework.web.bind.annotation.*; |
| 24 | 26 | |
| 25 | -import java.util.Base64; | |
| 26 | - | |
| 27 | 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | 28 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 29 | 29 | |
| ... | ... | @@ -33,6 +33,13 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 33 | 33 | @Validated |
| 34 | 34 | public class AppSocialUserController { |
| 35 | 35 | |
| 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 | + | |
| 36 | 43 | @Resource |
| 37 | 44 | private SocialUserApi socialUserApi; |
| 38 | 45 | @Resource |
| ... | ... | @@ -69,10 +76,13 @@ public class AppSocialUserController { |
| 69 | 76 | @PostMapping("/wxa-qrcode") |
| 70 | 77 | @Operation(summary = "获得微信小程序码(base64 image)") |
| 71 | 78 | public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { |
| 72 | - byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class) | |
| 73 | - .setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION)); | |
| 74 | - // TODO @puhui999:1)是不是 base64 返回,不拼接哈 data:image/png;base64;2)cn.hutool.core.codec.Base64.encode() | |
| 75 | - return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode)); | |
| 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))); | |
| 85 | + return success(Base64.encode(wxQrcode)); | |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java
| ... | ... | @@ -9,20 +9,11 @@ import lombok.Data; |
| 9 | 9 | @Data |
| 10 | 10 | public class AppSocialWxQrcodeReqVO { |
| 11 | 11 | |
| 12 | - // TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣 | |
| 13 | - // TODO @puhui999:懂了哈;default 最好在 controller 搞;对于 VO 来说,不给默认值; | |
| 14 | - public static String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | |
| 15 | - private static String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里) | |
| 16 | - private static Integer WIDTH = 430; // 二维码宽度 | |
| 17 | - private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |
| 18 | - private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在 | |
| 19 | - private static Boolean HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 | |
| 20 | - | |
| 21 | 12 | /** |
| 22 | 13 | * 页面路径不能携带参数(参数请放在scene字段里) |
| 23 | 14 | */ |
| 24 | 15 | @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") |
| 25 | - private String scene = SCENE; | |
| 16 | + private String scene; | |
| 26 | 17 | |
| 27 | 18 | /** |
| 28 | 19 | * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里), |
| ... | ... | @@ -33,15 +24,15 @@ public class AppSocialWxQrcodeReqVO { |
| 33 | 24 | private String path; |
| 34 | 25 | |
| 35 | 26 | @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430") |
| 36 | - private Integer width = WIDTH; | |
| 27 | + private Integer width; | |
| 37 | 28 | |
| 38 | 29 | @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 39 | - private Boolean autoColor = AUTO_COLOR; | |
| 30 | + private Boolean autoColor; | |
| 40 | 31 | |
| 41 | 32 | @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 42 | - private Boolean checkPath = CHECK_PATH; | |
| 33 | + private Boolean checkPath; | |
| 43 | 34 | |
| 44 | 35 | @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 45 | - private Boolean hyaline = HYALINE; | |
| 36 | + private Boolean hyaline; | |
| 46 | 37 | |
| 47 | 38 | } | ... | ... |