完善微信小程序码

This commit is contained in:
puhui999 2024-05-16 16:57:43 +08:00
parent 52b972907a
commit 380ec11221
4 changed files with 20 additions and 65 deletions

View File

@ -70,7 +70,7 @@ public class AppSocialUserController {
@Operation(summary = "获得微信小程序码(base64 image)")
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)
.setUserId(getLoginUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType()));
.setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION));
return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode));
}

View File

@ -1,31 +1,25 @@
package cn.iocoder.yudao.module.member.controller.app.social.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
// TODO @芋艿需要精简下参数
@Schema(description = "用户 APP - 获得获取小程序码 Request VO")
@Data
public class AppSocialWxQrcodeReqVO {
// TODO @puhui999这个后续不用前端传递应该是后端搞的
// 页面路径不能携带参数参数请放在scene字段里
private static String SCENE = ""; // 默认场景值 1011 扫描二维码
// TODO @puhui999这个默认是不是 release
private static String ENV_VERSION = "develop"; // 小程序版本正式版为 "release"体验版为 "trial"开发版为 "develop"
// TODO @puhui999这个去掉因为本身就是 430
// TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣
public static String ENV_VERSION = "release"; // 小程序版本正式版为 "release"体验版为 "trial"开发版为 "develop"
private static String SCENE = ""; // 页面路径不能携带参数参数请放在scene字段里
private static Integer WIDTH = 430; // 二维码宽度
// TODO @puhui999这个去掉因为本身就是 true
private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色如果颜色依然是黑色则说明不建议配置主色调
// TODO @puhui999这个去掉因为本身就是 true
private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
// TODO @puhui999这个去掉因为本身就是 true
private static Boolean IS_HYALINE = true; // 是否需要透明底色 is_hyaline 为true时生成透明底色的小程序码
private static Boolean HYALINE = true; // 是否需要透明底色 is_hyaline 为true时生成透明底色的小程序码
/**
* 页面路径不能携带参数参数请放在scene字段里
*/
@Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
private String scene = SCENE;
@ -37,25 +31,16 @@ public class AppSocialWxQrcodeReqVO {
@NotEmpty(message = "页面路径不能为空")
private String path;
// TODO @puhui999这个应该不传递哈
@Schema(description = "小程序版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "develop")
private String envVersion = ENV_VERSION;
@Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
private Integer width = WIDTH;
@Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean isAutoColor = AUTO_COLOR;
private Boolean autoColor = AUTO_COLOR;
@Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean isCheckPath = CHECK_PATH;
private Boolean checkPath = CHECK_PATH;
@Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean isHyaline = IS_HYALINE;
@Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@InEnum(SocialTypeEnum.class)
@NotNull(message = "社交平台的类型不能为空")
private Integer type;
private Boolean hyaline = HYALINE;
}

View File

@ -1,42 +1,17 @@
package cn.iocoder.yudao.module.system.api.social.dto;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* 获取小程序码 Request DTO
*
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html">获取不限制的小程序码</a>
*
* @author HUIHUI
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html">获取不限制的小程序码</a>
*/
@Data
public class SocialWxQrcodeReqDTO {
// TODO @puhui999userIduserType 应该后续要搞成抽象参数说白了就是 path 的参数 socialType 应该去掉因为就是微信的
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 用户类型
*/
@InEnum(UserTypeEnum.class)
@NotNull(message = "用户类型不能为空")
private Integer userType;
/**
* 社交平台的类型
*/
@InEnum(SocialTypeEnum.class)
@NotNull(message = "社交平台的类型不能为空")
private Integer socialType;
/**
* 场景
*/
@ -56,23 +31,17 @@ public class SocialWxQrcodeReqDTO {
*/
private Integer width;
// TODO @puhui999autoColor
/**
* 是否需要透明底色
*/
private Boolean isAutoColor;
// TODO @puhui999 checkPath
private Boolean autoColor;
/**
* 是否检查 page 是否存在
*/
private Boolean isCheckPath;
// TODO @puhui999 hyaline
private Boolean checkPath;
/**
* 是否需要透明底色
*/
private Boolean isHyaline;
private Boolean hyaline;
}

View File

@ -9,6 +9,7 @@ import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
@ -230,11 +231,11 @@ public class SocialClientServiceImpl implements SocialClientService {
@Override
public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
WxMaService service = getWxMaService(reqVO.getUserType());
WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
try {
return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(),
reqVO.getIsCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getIsAutoColor(),
null, reqVO.getIsHyaline());
reqVO.getCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getAutoColor(),
null, reqVO.getHyaline());
} catch (WxErrorException e) {
log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);