Commit 4c05bd340ef2ec1b42ebfac427fc05df71f32634
1 parent
4a0ad205
fix: 获得微信小程序码(base64 image)
Showing
10 changed files
with
33 additions
and
38 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,6 +8,7 @@ import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBind | ||
| 8 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; | 8 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; |
| 9 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | 9 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; |
| 10 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO; | 10 | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO; |
| 11 | +import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | ||
| 11 | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; | 12 | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; |
| 12 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | 13 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 13 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | 14 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; |
| @@ -34,6 +35,8 @@ public class AppSocialUserController { | @@ -34,6 +35,8 @@ public class AppSocialUserController { | ||
| 34 | 35 | ||
| 35 | @Resource | 36 | @Resource |
| 36 | private SocialUserApi socialUserApi; | 37 | private SocialUserApi socialUserApi; |
| 38 | + @Resource | ||
| 39 | + private SocialClientApi socialClientApi; | ||
| 37 | 40 | ||
| 38 | @PostMapping("/bind") | 41 | @PostMapping("/bind") |
| 39 | @Operation(summary = "社交绑定,使用 code 授权码") | 42 | @Operation(summary = "社交绑定,使用 code 授权码") |
| @@ -63,14 +66,12 @@ public class AppSocialUserController { | @@ -63,14 +66,12 @@ public class AppSocialUserController { | ||
| 63 | return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class)); | 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 | public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { | 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 | + .setUserId(getLoginUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType())); | ||
| 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
| @@ -12,8 +12,9 @@ import lombok.Data; | @@ -12,8 +12,9 @@ import lombok.Data; | ||
| 12 | @Data | 12 | @Data |
| 13 | public class AppSocialWxQrcodeReqVO { | 13 | public class AppSocialWxQrcodeReqVO { |
| 14 | 14 | ||
| 15 | - // TODO @puhui999:这个后续不用前端传递,应该是后端搞的 | ||
| 16 | - private static String SCENE = "1011"; // 默认场景值 1011 扫描二维码 | 15 | + // TODO @puhui999:这个后续不用前端传递,应该是后端搞的。 |
| 16 | + // 页面路径不能携带参数(参数请放在scene字段里) | ||
| 17 | + private static String SCENE = ""; // 默认场景值 1011 扫描二维码 | ||
| 17 | // TODO @puhui999:这个默认是不是 release 哈? | 18 | // TODO @puhui999:这个默认是不是 release 哈? |
| 18 | private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | 19 | private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" |
| 19 | // TODO @puhui999:这个去掉;因为本身就是 430 啦; | 20 | // TODO @puhui999:这个去掉;因为本身就是 430 啦; |
| @@ -28,6 +29,10 @@ public class AppSocialWxQrcodeReqVO { | @@ -28,6 +29,10 @@ public class AppSocialWxQrcodeReqVO { | ||
| 28 | @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") | 29 | @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") |
| 29 | private String scene = SCENE; | 30 | private String scene = SCENE; |
| 30 | 31 | ||
| 32 | + /** | ||
| 33 | + * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里), | ||
| 34 | + * 如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置 | ||
| 35 | + */ | ||
| 31 | @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index") | 36 | @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index") |
| 32 | @NotEmpty(message = "页面路径不能为空") | 37 | @NotEmpty(message = "页面路径不能为空") |
| 33 | private String path; | 38 | private String path; |
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,7 +2,9 @@ package cn.iocoder.yudao.module.system.api.social; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 5 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | ||
| 5 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 6 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 7 | +import jakarta.validation.Valid; | ||
| 6 | 8 | ||
| 7 | /** | 9 | /** |
| 8 | * 社交应用的 API 接口 | 10 | * 社交应用的 API 接口 |
| @@ -39,4 +41,12 @@ public interface SocialClientApi { | @@ -39,4 +41,12 @@ public interface SocialClientApi { | ||
| 39 | */ | 41 | */ |
| 40 | SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode); | 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,12 +52,4 @@ public interface SocialUserApi { | ||
| 52 | */ | 52 | */ |
| 53 | SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state); | 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-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,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | ||
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 7 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | ||
| 7 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; | 8 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 8 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 9 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| @@ -40,4 +41,9 @@ public class SocialClientApiImpl implements SocialClientApi { | @@ -40,4 +41,9 @@ public class SocialClientApiImpl implements SocialClientApi { | ||
| 40 | return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class); | 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,10 +43,4 @@ public class SocialUserApiImpl implements SocialUserApi { | ||
| 43 | return socialUserService.getSocialUserByCode(userType, socialType, code, state); | 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,7 +67,7 @@ public interface SocialClientService { | ||
| 67 | * @param reqVO 请求信息 | 67 | * @param reqVO 请求信息 |
| 68 | * @return 小程序二维码 | 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
| @@ -229,7 +229,7 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -229,7 +229,7 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | @Override | 231 | @Override |
| 232 | - public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) { | 232 | + public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { |
| 233 | WxMaService service = getWxMaService(reqVO.getUserType()); | 233 | WxMaService service = getWxMaService(reqVO.getUserType()); |
| 234 | try { | 234 | try { |
| 235 | return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), | 235 | return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), |
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,12 +87,4 @@ public interface SocialUserService { | ||
| 87 | */ | 87 | */ |
| 88 | PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO); | 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,9 +171,4 @@ public class SocialUserServiceImpl implements SocialUserService { | ||
| 171 | return socialUserMapper.selectPage(pageReqVO); | 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 | } |