【代码评审】SYSTEM:完善微信小程序码
This commit is contained in:
parent
2d44b3a245
commit
3025bff631
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.member.controller.app.social;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
@ -33,13 +32,6 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|||
@Validated
|
||||
public class AppSocialUserController {
|
||||
|
||||
public static final String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
||||
private static final String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里)
|
||||
private static final Integer WIDTH = 430; // 二维码宽度
|
||||
private static final Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
||||
private static final Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
|
||||
private static final Boolean HYALINE = true; // 是否需要透明底色, hyaline 为true时,生成透明底色的小程序码
|
||||
|
||||
@Resource
|
||||
private SocialUserApi socialUserApi;
|
||||
@Resource
|
||||
|
@ -76,12 +68,7 @@ public class AppSocialUserController {
|
|||
@PostMapping("/wxa-qrcode")
|
||||
@Operation(summary = "获得微信小程序码(base64 image)")
|
||||
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
|
||||
byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath())
|
||||
.setEnvVersion(ENV_VERSION).setWidth(ObjUtil.defaultIfNull(reqVO.getWidth(), WIDTH))
|
||||
.setScene(ObjUtil.defaultIfNull(reqVO.getScene(), SCENE))
|
||||
.setAutoColor(ObjUtil.defaultIfNull(reqVO.getAutoColor(), AUTO_COLOR))
|
||||
.setHyaline(ObjUtil.defaultIfNull(reqVO.getHyaline(), HYALINE))
|
||||
.setCheckPath(ObjUtil.defaultIfNull(reqVO.getCheckPath(), CHECK_PATH)));
|
||||
byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath()));
|
||||
return success(Base64.encode(wxQrcode));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,35 @@ import lombok.Data;
|
|||
@Data
|
||||
public class SocialWxQrcodeReqDTO {
|
||||
|
||||
/**
|
||||
* 小程序版本
|
||||
*
|
||||
* 正式版为 "release";体验版为 "trial";开发版为 "develop"
|
||||
*/
|
||||
public static final String ENV_VERSION = "release";
|
||||
/**
|
||||
* 页面路径不能携带参数(参数请放在scene字段里)
|
||||
*/
|
||||
public static final String SCENE = "";
|
||||
/**
|
||||
* 二维码宽度
|
||||
*/
|
||||
public static final Integer WIDTH = 430;
|
||||
/**
|
||||
* 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
||||
*/
|
||||
public static final Boolean AUTO_COLOR = true;
|
||||
/**
|
||||
* 检查 page 是否存在
|
||||
*/
|
||||
public static final Boolean CHECK_PATH = true;
|
||||
/**
|
||||
* 是否需要透明底色
|
||||
*
|
||||
* hyaline 为 true 时,生成透明底色的小程序码
|
||||
*/
|
||||
public static final Boolean HYALINE = true;
|
||||
|
||||
/**
|
||||
* 场景
|
||||
*/
|
||||
|
|
|
@ -233,9 +233,15 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
|
||||
WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
|
||||
try {
|
||||
return service.getQrcodeService().createWxaCodeUnlimitBytes(reqVO.getScene(), reqVO.getPath(),
|
||||
reqVO.getCheckPath(), reqVO.getEnvVersion(), reqVO.getWidth(), reqVO.getAutoColor(),
|
||||
null, reqVO.getHyaline());
|
||||
return service.getQrcodeService().createWxaCodeUnlimitBytes(
|
||||
ObjUtil.defaultIfEmpty(reqVO.getScene(), SocialWxQrcodeReqDTO.SCENE),
|
||||
reqVO.getPath(),
|
||||
ObjUtil.defaultIfNull(reqVO.getCheckPath(), SocialWxQrcodeReqDTO.CHECK_PATH),
|
||||
ObjUtil.defaultIfBlank(reqVO.getEnvVersion(), SocialWxQrcodeReqDTO.ENV_VERSION),
|
||||
ObjUtil.defaultIfNull(reqVO.getWidth(), SocialWxQrcodeReqDTO.WIDTH),
|
||||
ObjUtil.defaultIfNull(reqVO.getAutoColor(), SocialWxQrcodeReqDTO.AUTO_COLOR),
|
||||
null,
|
||||
ObjUtil.defaultIfNull(reqVO.getHyaline(), SocialWxQrcodeReqDTO.HYALINE));
|
||||
} catch (WxErrorException e) {
|
||||
log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);
|
||||
|
|
Loading…
Reference in New Issue