Commit 668b97e4ed9bd7b263023a1398978dc482e192d2

Authored by 芋道源码
Committed by Gitee
2 parents 4a0ad205 380ec112

!975 完善微信小程序码

Merge pull request !975 from puhui999/develop
Showing 13 changed files with 59 additions and 101 deletions
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
... ... @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBind
8 8 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO;
9 9 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO;
10 10 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO;
  11 +import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
11 12 import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
12 13 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
13 14 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
... ... @@ -34,6 +35,8 @@ public class AppSocialUserController {
34 35  
35 36 @Resource
36 37 private SocialUserApi socialUserApi;
  38 + @Resource
  39 + private SocialClientApi socialClientApi;
37 40  
38 41 @PostMapping("/bind")
39 42 @Operation(summary = "社交绑定,使用 code 授权码")
... ... @@ -63,14 +66,12 @@ public class AppSocialUserController {
63 66 return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class));
64 67 }
65 68  
66   - // TODO @puhui999:是不是 url 叫 wxa-qrcode?然后相关的方法,都做下调整哈;因为是微信小程序的二维码
67   - @PostMapping("/wxacode")
68   - @Operation(summary = "获得微信小程序码")
69   - @PreAuthenticated // TODO @puhui999:可能不需要登录
  69 + @PostMapping("/wxa-qrcode")
  70 + @Operation(summary = "获得微信小程序码(base64 image)")
70 71 public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
71   - byte[] wxQrcode = socialUserApi.getWxQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class).setUserId(getLoginUserId())
72   - .setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType()));
73   - return success(Base64.getEncoder().encodeToString(wxQrcode));
  72 + byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)
  73 + .setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION));
  74 + return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode));
74 75 }
75 76  
76 77 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java
1 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 3 import io.swagger.v3.oas.annotations.media.Schema;
6 4 import jakarta.validation.constraints.NotEmpty;
7   -import jakarta.validation.constraints.NotNull;
8 5 import lombok.Data;
9 6  
10   -// TODO @芋艿:需要精简下参数;
  7 +
11 8 @Schema(description = "用户 APP - 获得获取小程序码 Request VO")
12 9 @Data
13 10 public class AppSocialWxQrcodeReqVO {
14 11  
15   - // TODO @puhui999:这个后续不用前端传递,应该是后端搞的
16   - private static String SCENE = "1011"; // 默认场景值 1011 扫描二维码
17   - // TODO @puhui999:这个默认是不是 release 哈?
18   - private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
19   - // TODO @puhui999:这个去掉;因为本身就是 430 啦;
  12 + // TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣
  13 + public static String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
  14 + private static String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里)
20 15 private static Integer WIDTH = 430; // 二维码宽度
21   - // TODO @puhui999:这个去掉;因为本身就是 true 啦;
22 16 private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
23   - // TODO @puhui999:这个去掉;因为本身就是 true 啦;
24 17 private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
25   - // TODO @puhui999:这个去掉;因为本身就是 true 啦;
26   - private static Boolean IS_HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
  18 + private static Boolean HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
27 19  
  20 + /**
  21 + * 页面路径不能携带参数(参数请放在scene字段里)
  22 + */
28 23 @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
29 24 private String scene = SCENE;
30 25  
  26 + /**
  27 + * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),
  28 + * 如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
  29 + */
31 30 @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index")
32 31 @NotEmpty(message = "页面路径不能为空")
33 32 private String path;
34 33  
35   - // TODO @puhui999:这个应该不传递哈
36   - @Schema(description = "小程序版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "develop")
37   - private String envVersion = ENV_VERSION;
38   -
39 34 @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
40 35 private Integer width = WIDTH;
41 36  
42 37 @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
43   - private Boolean isAutoColor = AUTO_COLOR;
  38 + private Boolean autoColor = AUTO_COLOR;
44 39  
45 40 @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
46   - private Boolean isCheckPath = CHECK_PATH;
  41 + private Boolean checkPath = CHECK_PATH;
47 42  
48 43 @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
49   - private Boolean isHyaline = IS_HYALINE;
50   -
51   - @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
52   - @InEnum(SocialTypeEnum.class)
53   - @NotNull(message = "社交平台的类型不能为空")
54   - private Integer type;
  44 + private Boolean hyaline = HYALINE;
55 45  
56 46 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java
... ... @@ -11,6 +11,9 @@ import lombok.NoArgsConstructor;
11 11 @AllArgsConstructor
12 12 public class AppMemberUserInfoRespVO {
13 13  
  14 + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  15 + private Long id;
  16 +
14 17 @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
15 18 private String nickname;
16 19  
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java
... ... @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
12 12 import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
13 13 import org.mapstruct.Mapper;
14 14 import org.mapstruct.Mapping;
  15 +import org.mapstruct.Mappings;
15 16 import org.mapstruct.factory.Mappers;
16 17  
17 18 import java.util.List;
... ... @@ -27,8 +28,12 @@ public interface MemberUserConvert {
27 28  
28 29 AppMemberUserInfoRespVO convert(MemberUserDO bean);
29 30  
30   - @Mapping(source = "level", target = "level")
31   - @Mapping(source = "bean.experience", target = "experience")
  31 +
  32 + @Mappings({
  33 + @Mapping(source = "level", target = "level"),
  34 + @Mapping(source = "bean.id", target = "id"),
  35 + @Mapping(source = "bean.experience", target = "experience")
  36 + })
32 37 AppMemberUserInfoRespVO convert(MemberUserDO bean, MemberLevelDO level);
33 38  
34 39 MemberUserRespDTO convert2(MemberUserDO bean);
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
... ... @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.system.api.social;
2 2  
3 3 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
4 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
  5 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
5 6 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
  7 +import jakarta.validation.Valid;
6 8  
7 9 /**
8 10 * 社交应用的 API 接口
... ... @@ -39,4 +41,12 @@ public interface SocialClientApi {
39 41 */
40 42 SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
41 43  
  44 + /**
  45 + * 获得小程序二维码
  46 + *
  47 + * @param reqVO 请求信息
  48 + * @return 小程序二维码
  49 + */
  50 + byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
  51 +
42 52 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java
... ... @@ -52,12 +52,4 @@ public interface SocialUserApi {
52 52 */
53 53 SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state);
54 54  
55   - /**
56   - * 获得小程序二维码
57   - *
58   - * @param reqVO 请求信息
59   - * @return 小程序二维码
60   - */
61   - byte[] getWxQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
62   -
63 55 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxQrcodeReqDTO.java
1 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 3 import jakarta.validation.constraints.NotEmpty;
7   -import jakarta.validation.constraints.NotNull;
8 4 import lombok.Data;
9 5  
10 6 /**
11 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 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 12 @Data
18 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 31 */
57 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 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/api/social/SocialClientApiImpl.java
... ... @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
6 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
  7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
7 8 import cn.iocoder.yudao.module.system.service.social.SocialClientService;
8 9 import me.chanjar.weixin.common.bean.WxJsapiSignature;
9 10 import org.springframework.stereotype.Service;
... ... @@ -40,4 +41,9 @@ public class SocialClientApiImpl implements SocialClientApi {
40 41 return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class);
41 42 }
42 43  
  44 + @Override
  45 + public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
  46 + return socialClientService.getWxaQrcode(reqVO);
  47 + }
  48 +
43 49 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java
... ... @@ -43,10 +43,4 @@ public class SocialUserApiImpl implements SocialUserApi {
43 43 return socialUserService.getSocialUserByCode(userType, socialType, code, state);
44 44 }
45 45  
46   - // TODO @puhui999:貌似搞到 SocialClientApiImpl 更合适,二维码和用户关系不大;这样 socialUserService 也不用绕一次了
47   - @Override
48   - public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
49   - return socialUserService.getWxQrcode(reqVO);
50   - }
51   -
52 46 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
... ... @@ -67,7 +67,7 @@ public interface SocialClientService {
67 67 * @param reqVO 请求信息
68 68 * @return 小程序二维码
69 69 */
70   - byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO);
  70 + byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO);
71 71  
72 72 // =================== 客户端管理 ===================
73 73  
... ...
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 9 import cn.hutool.core.util.ObjUtil;
10 10 import cn.hutool.core.util.ReflectUtil;
11 11 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  12 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
12 13 import cn.iocoder.yudao.framework.common.pojo.PageResult;
13 14 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
14 15 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
... ... @@ -229,12 +230,12 @@ public class SocialClientServiceImpl implements SocialClientService {
229 230 }
230 231  
231 232 @Override
232   - public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
233   - WxMaService service = getWxMaService(reqVO.getUserType());
  233 + public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
  234 + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
234 235 try {
235 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 239 } catch (WxErrorException e) {
239 240 log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
240 241 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
... ... @@ -87,12 +87,4 @@ public interface SocialUserService {
87 87 */
88 88 PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
89 89  
90   - /**
91   - * 获得小程序二维码
92   - *
93   - * @param reqVO 请求信息
94   - * @return 小程序二维码
95   - */
96   - byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO);
97   -
98 90 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
... ... @@ -171,9 +171,4 @@ public class SocialUserServiceImpl implements SocialUserService {
171 171 return socialUserMapper.selectPage(pageReqVO);
172 172 }
173 173  
174   - @Override
175   - public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
176   - return socialClientService.getWxQrcode(reqVO);
177   - }
178   -
179 174 }
... ...