Commit 73ef9211f92a105290c92cc49114a620fe553b17

Authored by puhui999
1 parent 52c86cd2

feat:新增获取小程序码相关接口

yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
@@ -7,18 +7,21 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; @@ -7,18 +7,21 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
7 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; 7 import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO;
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.system.api.social.SocialUserApi; 11 import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
11 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 12 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
12 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; 13 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
13 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; 14 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
  15 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
  16 +import io.swagger.v3.oas.annotations.Operation;
14 import io.swagger.v3.oas.annotations.Parameter; 17 import io.swagger.v3.oas.annotations.Parameter;
15 import io.swagger.v3.oas.annotations.tags.Tag; 18 import io.swagger.v3.oas.annotations.tags.Tag;
16 -import io.swagger.v3.oas.annotations.Operation; 19 +import jakarta.annotation.Resource;
  20 +import jakarta.validation.Valid;
17 import org.springframework.validation.annotation.Validated; 21 import org.springframework.validation.annotation.Validated;
18 import org.springframework.web.bind.annotation.*; 22 import org.springframework.web.bind.annotation.*;
19 23
20 -import jakarta.annotation.Resource;  
21 -import jakarta.validation.Valid; 24 +import java.util.Base64;
22 25
23 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
24 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 27 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@@ -60,4 +63,13 @@ public class AppSocialUserController { @@ -60,4 +63,13 @@ public class AppSocialUserController {
60 return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class)); 63 return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class));
61 } 64 }
62 65
  66 + @PostMapping("/wxacode")
  67 + @Operation(summary = "获得微信小程序码")
  68 + @PreAuthenticated
  69 + public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
  70 + byte[] wxQrcode = socialUserApi.getWxQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class).setUserId(getLoginUserId())
  71 + .setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType()));
  72 + return success(Base64.getEncoder().encodeToString(wxQrcode));
  73 + }
  74 +
63 } 75 }
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.member.controller.app.social.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import jakarta.validation.constraints.NotEmpty;
  7 +import jakarta.validation.constraints.NotNull;
  8 +import lombok.Data;
  9 +
  10 +@Schema(description = "用户 APP - 获得获取小程序码 Request VO")
  11 +@Data
  12 +public class AppSocialWxQrcodeReqVO {
  13 +
  14 + private static String SCENE = "1011"; // 默认场景值 1011 扫描二维码
  15 + private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
  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 IS_HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
  20 +
  21 + /**
  22 + * 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~, 其它字符请自行编码为合法字符
  23 + * (因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
  24 + */
  25 + @Schema(description = "场景值/页面参数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
  26 + private String scene = SCENE;
  27 + /**
  28 + * 页面路径
  29 + */
  30 + @Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index")
  31 + @NotEmpty(message = "页面路径不能为空")
  32 + private String path;
  33 + /**
  34 + * 要打开的小程序版本。默认是开发版。
  35 + */
  36 + @Schema(description = "小程序版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "develop")
  37 + private String envVersion = ENV_VERSION;
  38 + /**
  39 + * 二维码宽度
  40 + */
  41 + @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
  42 + private Integer width = WIDTH;
  43 + /**
  44 + * 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
  45 + */
  46 + @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  47 + private Boolean isAutoColor = AUTO_COLOR;
  48 + /**
  49 + * 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
  50 + * 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
  51 + */
  52 + @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  53 + private Boolean isCheckPath = CHECK_PATH;
  54 + /**
  55 + * 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
  56 + */
  57 + @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  58 + private Boolean isHyaline = IS_HYALINE;
  59 +
  60 + @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  61 + @InEnum(SocialTypeEnum.class)
  62 + @NotNull(message = "社交平台的类型不能为空")
  63 + private Integer type;
  64 +
  65 +}
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
7 - 7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
8 import jakarta.validation.Valid; 8 import jakarta.validation.Valid;
9 9
10 /** 10 /**
@@ -32,8 +32,8 @@ public interface SocialUserApi { @@ -32,8 +32,8 @@ public interface SocialUserApi {
32 /** 32 /**
33 * 获得社交用户,基于 userId 33 * 获得社交用户,基于 userId
34 * 34 *
35 - * @param userType 用户类型  
36 - * @param userId 用户编号 35 + * @param userType 用户类型
  36 + * @param userId 用户编号
37 * @param socialType 社交平台的类型 37 * @param socialType 社交平台的类型
38 * @return 社交用户 38 * @return 社交用户
39 */ 39 */
@@ -44,12 +44,20 @@ public interface SocialUserApi { @@ -44,12 +44,20 @@ public interface SocialUserApi {
44 * 44 *
45 * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常 45 * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常
46 * 46 *
47 - * @param userType 用户类型 47 + * @param userType 用户类型
48 * @param socialType 社交平台的类型 48 * @param socialType 社交平台的类型
49 - * @param code 授权码  
50 - * @param state state 49 + * @param code 授权码
  50 + * @param state state
51 * @return 社交用户 51 * @return 社交用户
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 +
55 } 63 }
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxQrcodeReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.api.social.dto;
  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 +import jakarta.validation.constraints.NotEmpty;
  7 +import jakarta.validation.constraints.NotNull;
  8 +import lombok.Data;
  9 +
  10 +@Data
  11 +public class SocialWxQrcodeReqDTO {
  12 +
  13 + /**
  14 + * 用户编号
  15 + */
  16 + @NotNull(message = "用户编号不能为空")
  17 + private Long userId;
  18 + /**
  19 + * 用户类型
  20 + */
  21 + @InEnum(UserTypeEnum.class)
  22 + @NotNull(message = "用户类型不能为空")
  23 + private Integer userType;
  24 +
  25 + /**
  26 + * 社交平台的类型
  27 + */
  28 + @InEnum(SocialTypeEnum.class)
  29 + @NotNull(message = "社交平台的类型不能为空")
  30 + private Integer socialType;
  31 +
  32 + /**
  33 + * 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~, 其它字符请自行编码为合法字符
  34 + * (因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
  35 + */
  36 + private String scene;
  37 + /**
  38 + * 页面路径
  39 + */
  40 + @NotEmpty(message = "页面路径不能为空")
  41 + private String path;
  42 + /**
  43 + * 要打开的小程序版本。默认是开发版。
  44 + */
  45 + private String envVersion;
  46 + /**
  47 + * 二维码宽度
  48 + */
  49 + private Integer width;
  50 + /**
  51 + * 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
  52 + */
  53 + private Boolean isAutoColor;
  54 + /**
  55 + * 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
  56 + * 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
  57 + */
  58 + private Boolean isCheckPath;
  59 + /**
  60 + * 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
  61 + */
  62 + private Boolean isHyaline;
  63 +
  64 +}
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
@@ -120,8 +120,10 @@ public interface ErrorCodeConstants { @@ -120,8 +120,10 @@ public interface ErrorCodeConstants {
120 ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户"); 120 ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户");
121 121
122 ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); 122 ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败");
123 - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在");  
124 - ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_202, "社交客户端已存在配置"); 123 + ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败");
  124 + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_202, "社交客户端不存在");
  125 + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_203, "社交客户端已存在配置");
  126 +
125 127
126 // ========== OAuth2 客户端 1-002-020-000 ========= 128 // ========== OAuth2 客户端 1-002-020-000 =========
127 ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在"); 129 ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在");
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social;
3 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 3 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
  6 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
6 import cn.iocoder.yudao.module.system.service.social.SocialUserService; 7 import cn.iocoder.yudao.module.system.service.social.SocialUserService;
7 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
8 import org.springframework.validation.annotation.Validated; 9 import org.springframework.validation.annotation.Validated;
@@ -42,4 +43,9 @@ public class SocialUserApiImpl implements SocialUserApi { @@ -42,4 +43,9 @@ public class SocialUserApiImpl implements SocialUserApi {
42 return socialUserService.getSocialUserByCode(userType, socialType, code, state); 43 return socialUserService.getSocialUserByCode(userType, socialType, code, state);
43 } 44 }
44 45
  46 + @Override
  47 + public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
  48 + return socialUserService.getWxQrcode(reqVO);
  49 + }
  50 +
45 } 51 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
@@ -2,14 +2,14 @@ package cn.iocoder.yudao.module.system.service.social; @@ -2,14 +2,14 @@ package cn.iocoder.yudao.module.system.service.social;
2 2
3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; 3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
5 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; 6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
7 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; 8 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
8 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; 9 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
9 import com.xingyuv.jushauth.model.AuthUser; 10 import com.xingyuv.jushauth.model.AuthUser;
10 -import me.chanjar.weixin.common.bean.WxJsapiSignature;  
11 -  
12 import jakarta.validation.Valid; 11 import jakarta.validation.Valid;
  12 +import me.chanjar.weixin.common.bean.WxJsapiSignature;
13 13
14 /** 14 /**
15 * 社交应用 Service 接口 15 * 社交应用 Service 接口
@@ -21,8 +21,8 @@ public interface SocialClientService { @@ -21,8 +21,8 @@ public interface SocialClientService {
21 /** 21 /**
22 * 获得社交平台的授权 URL 22 * 获得社交平台的授权 URL
23 * 23 *
24 - * @param socialType 社交平台的类型 {@link SocialTypeEnum}  
25 - * @param userType 用户类型 24 + * @param socialType 社交平台的类型 {@link SocialTypeEnum}
  25 + * @param userType 用户类型
26 * @param redirectUri 重定向 URL 26 * @param redirectUri 重定向 URL
27 * @return 社交平台的授权 URL 27 * @return 社交平台的授权 URL
28 */ 28 */
@@ -32,9 +32,9 @@ public interface SocialClientService { @@ -32,9 +32,9 @@ public interface SocialClientService {
32 * 请求社交平台,获得授权的用户 32 * 请求社交平台,获得授权的用户
33 * 33 *
34 * @param socialType 社交平台的类型 34 * @param socialType 社交平台的类型
35 - * @param userType 用户类型  
36 - * @param code 授权码  
37 - * @param state 授权 state 35 + * @param userType 用户类型
  36 + * @param code 授权码
  37 + * @param state 授权 state
38 * @return 授权的用户 38 * @return 授权的用户
39 */ 39 */
40 AuthUser getAuthUser(Integer socialType, Integer userType, String code, String state); 40 AuthUser getAuthUser(Integer socialType, Integer userType, String code, String state);
@@ -45,7 +45,7 @@ public interface SocialClientService { @@ -45,7 +45,7 @@ public interface SocialClientService {
45 * 创建微信公众号的 JS SDK 初始化所需的签名 45 * 创建微信公众号的 JS SDK 初始化所需的签名
46 * 46 *
47 * @param userType 用户类型 47 * @param userType 用户类型
48 - * @param url 访问的 URL 地址 48 + * @param url 访问的 URL 地址
49 * @return 签名 49 * @return 签名
50 */ 50 */
51 WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url); 51 WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url);
@@ -55,12 +55,20 @@ public interface SocialClientService { @@ -55,12 +55,20 @@ public interface SocialClientService {
55 /** 55 /**
56 * 获得微信小程序的手机信息 56 * 获得微信小程序的手机信息
57 * 57 *
58 - * @param userType 用户类型 58 + * @param userType 用户类型
59 * @param phoneCode 手机授权码 59 * @param phoneCode 手机授权码
60 * @return 手机信息 60 * @return 手机信息
61 */ 61 */
62 WxMaPhoneNumberInfo getWxMaPhoneNumberInfo(Integer userType, String phoneCode); 62 WxMaPhoneNumberInfo getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
63 63
  64 + /**
  65 + * 获得小程序二维码
  66 + *
  67 + * @param reqVO 请求信息
  68 + * @return 小程序二维码
  69 + */
  70 + byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO);
  71 +
64 // =================== 客户端管理 =================== 72 // =================== 客户端管理 ===================
65 73
66 /** 74 /**
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
@@ -13,6 +13,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -13,6 +13,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
13 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; 13 import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
14 import cn.iocoder.yudao.framework.common.util.http.HttpUtils; 14 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
15 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 15 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  16 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
16 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; 17 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
17 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; 18 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
18 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; 19 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
@@ -139,7 +140,7 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -139,7 +140,7 @@ public class SocialClientServiceImpl implements SocialClientService {
139 * 构建 AuthRequest 对象,支持多租户配置 140 * 构建 AuthRequest 对象,支持多租户配置
140 * 141 *
141 * @param socialType 社交类型 142 * @param socialType 社交类型
142 - * @param userType 用户类型 143 + * @param userType 用户类型
143 * @return AuthRequest 对象 144 * @return AuthRequest 对象
144 */ 145 */
145 @VisibleForTesting 146 @VisibleForTesting
@@ -196,7 +197,7 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -196,7 +197,7 @@ public class SocialClientServiceImpl implements SocialClientService {
196 /** 197 /**
197 * 创建 clientId + clientSecret 对应的 WxMpService 对象 198 * 创建 clientId + clientSecret 对应的 WxMpService 对象
198 * 199 *
199 - * @param clientId 微信公众号 appId 200 + * @param clientId 微信公众号 appId
200 * @param clientSecret 微信公众号 secret 201 * @param clientSecret 微信公众号 secret
201 * @return WxMpService 对象 202 * @return WxMpService 对象
202 */ 203 */
@@ -227,6 +228,19 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -227,6 +228,19 @@ public class SocialClientServiceImpl implements SocialClientService {
227 } 228 }
228 } 229 }
229 230
  231 + @Override
  232 + public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
  233 + WxMaService service = getWxMaService(reqVO.getUserType());
  234 + try {
  235 + return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(),
  236 + reqVO.getIsCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getIsAutoColor(),
  237 + null, reqVO.getIsHyaline());
  238 + } catch (WxErrorException e) {
  239 + log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
  240 + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);
  241 + }
  242 + }
  243 +
230 /** 244 /**
231 * 获得 clientId + clientSecret 对应的 WxMpService 对象 245 * 获得 clientId + clientSecret 对应的 WxMpService 对象
232 * 246 *
@@ -248,7 +262,7 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -248,7 +262,7 @@ public class SocialClientServiceImpl implements SocialClientService {
248 /** 262 /**
249 * 创建 clientId + clientSecret 对应的 WxMaService 对象 263 * 创建 clientId + clientSecret 对应的 WxMaService 对象
250 * 264 *
251 - * @param clientId 微信小程序 appId 265 + * @param clientId 微信小程序 appId
252 * @param clientSecret 微信小程序 secret 266 * @param clientSecret 微信小程序 secret
253 * @return WxMaService 对象 267 * @return WxMaService 对象
254 */ 268 */
@@ -310,8 +324,8 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -310,8 +324,8 @@ public class SocialClientServiceImpl implements SocialClientService {
310 * 324 *
311 * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求 325 * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求
312 * 326 *
313 - * @param id 编号  
314 - * @param userType 用户类型 327 + * @param id 编号
  328 + * @param userType 用户类型
315 * @param socialType 社交类型 329 * @param socialType 社交类型
316 */ 330 */
317 private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) { 331 private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) {
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  7 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; 8 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
8 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
9 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; 10 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
@@ -86,4 +87,12 @@ public interface SocialUserService { @@ -86,4 +87,12 @@ public interface SocialUserService {
86 */ 87 */
87 PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO); 88 PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
88 89
  90 + /**
  91 + * 获得小程序二维码
  92 + *
  93 + * @param reqVO 请求信息
  94 + * @return 小程序二维码
  95 + */
  96 + byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO);
  97 +
89 } 98 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 7 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
8 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; 8 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  9 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
9 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; 10 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
10 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; 11 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
11 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; 12 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
@@ -170,4 +171,9 @@ public class SocialUserServiceImpl implements SocialUserService { @@ -170,4 +171,9 @@ public class SocialUserServiceImpl implements SocialUserService {
170 return socialUserMapper.selectPage(pageReqVO); 171 return socialUserMapper.selectPage(pageReqVO);
171 } 172 }
172 173
  174 + @Override
  175 + public byte[] getWxQrcode(SocialWxQrcodeReqDTO reqVO) {
  176 + return socialClientService.getWxQrcode(reqVO);
  177 + }
  178 +
173 } 179 }