mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	fix: 获得微信小程序码(base64 image)
This commit is contained in:
		| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBind | |||||||
| import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; | ||||||
| import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | ||||||
| import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO; | import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO; | ||||||
|  | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | ||||||
| import cn.iocoder.yudao.module.system.api.social.SocialUserApi; | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | ||||||
| @@ -34,6 +35,8 @@ public class AppSocialUserController { | |||||||
|  |  | ||||||
|     @Resource |     @Resource | ||||||
|     private SocialUserApi socialUserApi; |     private SocialUserApi socialUserApi; | ||||||
|  |     @Resource | ||||||
|  |     private SocialClientApi socialClientApi; | ||||||
|  |  | ||||||
|     @PostMapping("/bind") |     @PostMapping("/bind") | ||||||
|     @Operation(summary = "社交绑定,使用 code 授权码") |     @Operation(summary = "社交绑定,使用 code 授权码") | ||||||
| @@ -63,14 +66,12 @@ public class AppSocialUserController { | |||||||
|         return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class)); |         return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @puhui999:是不是 url 叫 wxa-qrcode?然后相关的方法,都做下调整哈;因为是微信小程序的二维码 |     @PostMapping("/wxa-qrcode") | ||||||
|     @PostMapping("/wxacode") |     @Operation(summary = "获得微信小程序码(base64 image)") | ||||||
|     @Operation(summary = "获得微信小程序码") |  | ||||||
|     @PreAuthenticated // TODO @puhui999:可能不需要登录 |  | ||||||
|     public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { |     public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { | ||||||
|         byte[] wxQrcode = socialUserApi.getWxQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class).setUserId(getLoginUserId()) |         byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class) | ||||||
|                 .setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType())); |                 .setUserId(getLoginUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType())); | ||||||
|         return success(Base64.getEncoder().encodeToString(wxQrcode)); |         return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -12,8 +12,9 @@ import lombok.Data; | |||||||
| @Data | @Data | ||||||
| public class AppSocialWxQrcodeReqVO { | public class AppSocialWxQrcodeReqVO { | ||||||
|  |  | ||||||
|     // TODO @puhui999:这个后续不用前端传递,应该是后端搞的 |     // TODO @puhui999:这个后续不用前端传递,应该是后端搞的。 | ||||||
|     private static String SCENE = "1011"; // 默认场景值 1011 扫描二维码 |     //      页面路径不能携带参数(参数请放在scene字段里) | ||||||
|  |     private static String SCENE = ""; // 默认场景值 1011 扫描二维码 | ||||||
|     // TODO @puhui999:这个默认是不是 release 哈? |     // TODO @puhui999:这个默认是不是 release 哈? | ||||||
|     private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" |     private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | ||||||
|     // TODO @puhui999:这个去掉;因为本身就是 430 啦; |     // TODO @puhui999:这个去掉;因为本身就是 430 啦; | ||||||
| @@ -28,6 +29,10 @@ public class AppSocialWxQrcodeReqVO { | |||||||
|     @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") |     @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") | ||||||
|     private String scene = SCENE; |     private String scene = SCENE; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里), | ||||||
|  |      * 如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置 | ||||||
|  |      */ | ||||||
|     @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index") |     @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index") | ||||||
|     @NotEmpty(message = "页面路径不能为空") |     @NotEmpty(message = "页面路径不能为空") | ||||||
|     private String path; |     private String path; | ||||||
|   | |||||||
| @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.system.api.social; | |||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | ||||||
|  | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | ||||||
| import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | ||||||
|  | import jakarta.validation.Valid; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 社交应用的 API 接口 |  * 社交应用的 API 接口 | ||||||
| @@ -39,4 +41,12 @@ public interface SocialClientApi { | |||||||
|      */ |      */ | ||||||
|     SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode); |     SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得小程序二维码 | ||||||
|  |      * | ||||||
|  |      * @param reqVO 请求信息 | ||||||
|  |      * @return 小程序二维码 | ||||||
|  |      */ | ||||||
|  |     byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -52,12 +52,4 @@ public interface SocialUserApi { | |||||||
|      */ |      */ | ||||||
|     SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state); |     SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 获得小程序二维码 |  | ||||||
|      * |  | ||||||
|      * @param reqVO 请求信息 |  | ||||||
|      * @return 小程序二维码 |  | ||||||
|      */ |  | ||||||
|     byte[] getWxQrcode(@Valid SocialWxQrcodeReqDTO reqVO); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | |||||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | ||||||
| import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | ||||||
|  | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | ||||||
| import cn.iocoder.yudao.module.system.service.social.SocialClientService; | import cn.iocoder.yudao.module.system.service.social.SocialClientService; | ||||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| @@ -40,4 +41,9 @@ public class SocialClientApiImpl implements SocialClientApi { | |||||||
|         return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class); |         return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { | ||||||
|  |         return socialClientService.getWxaQrcode(reqVO); | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -43,10 +43,4 @@ public class SocialUserApiImpl implements SocialUserApi { | |||||||
|        return socialUserService.getSocialUserByCode(userType, socialType, code, state); |        return socialUserService.getSocialUserByCode(userType, socialType, code, state); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @puhui999:貌似搞到 SocialClientApiImpl 更合适,二维码和用户关系不大;这样 socialUserService 也不用绕一次了 |  | ||||||
|     @Override |  | ||||||
|     public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) { |  | ||||||
|         return socialUserService.getWxQrcode(reqVO); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -67,7 +67,7 @@ public interface SocialClientService { | |||||||
|      * @param reqVO 请求信息 |      * @param reqVO 请求信息 | ||||||
|      * @return 小程序二维码 |      * @return 小程序二维码 | ||||||
|      */ |      */ | ||||||
|     byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO); |     byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO); | ||||||
|  |  | ||||||
|     // =================== 客户端管理 =================== |     // =================== 客户端管理 =================== | ||||||
|  |  | ||||||
|   | |||||||
| @@ -229,7 +229,7 @@ public class SocialClientServiceImpl implements SocialClientService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) { |     public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) { | ||||||
|         WxMaService service = getWxMaService(reqVO.getUserType()); |         WxMaService service = getWxMaService(reqVO.getUserType()); | ||||||
|         try { |         try { | ||||||
|             return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), |             return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(), | ||||||
|   | |||||||
| @@ -87,12 +87,4 @@ public interface SocialUserService { | |||||||
|      */ |      */ | ||||||
|     PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO); |     PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 获得小程序二维码 |  | ||||||
|      * |  | ||||||
|      * @param reqVO 请求信息 |  | ||||||
|      * @return 小程序二维码 |  | ||||||
|      */ |  | ||||||
|     byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -171,9 +171,4 @@ public class SocialUserServiceImpl implements SocialUserService { | |||||||
|         return socialUserMapper.selectPage(pageReqVO); |         return socialUserMapper.selectPage(pageReqVO); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) { |  | ||||||
|         return socialClientService.getWxQrcode(reqVO); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999