fix: 获得微信小程序码(base64 image)

This commit is contained in:
puhui999
2024-05-14 23:28:44 +08:00
parent 4a0ad205ae
commit 4c05bd340e
10 changed files with 33 additions and 38 deletions

View File

@ -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.AppSocialUserUnbindReqVO;
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.dto.SocialUserBindReqDTO;
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
@ -34,6 +35,8 @@ public class AppSocialUserController {
@Resource
private SocialUserApi socialUserApi;
@Resource
private SocialClientApi socialClientApi;
@PostMapping("/bind")
@Operation(summary = "社交绑定,使用 code 授权码")
@ -63,14 +66,12 @@ public class AppSocialUserController {
return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class));
}
// TODO @puhui999是不是 url 叫 wxa-qrcode然后相关的方法都做下调整哈因为是微信小程序的二维码
@PostMapping("/wxacode")
@Operation(summary = "获得微信小程序码")
@PreAuthenticated // TODO @puhui999可能不需要登录
@PostMapping("/wxa-qrcode")
@Operation(summary = "获得微信小程序码(base64 image)")
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
byte[] wxQrcode = socialUserApi.getWxQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class).setUserId(getLoginUserId())
.setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType()));
return success(Base64.getEncoder().encodeToString(wxQrcode));
byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)
.setUserId(getLoginUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setSocialType(reqVO.getType()));
return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode));
}
}

View File

@ -12,8 +12,9 @@ import lombok.Data;
@Data
public class AppSocialWxQrcodeReqVO {
// TODO @puhui999这个后续不用前端传递应该是后端搞的
private static String SCENE = "1011"; // 默认场景值 1011 扫描二维码
// TODO @puhui999这个后续不用前端传递应该是后端搞的
// 页面路径不能携带参数参数请放在scene字段里
private static String SCENE = ""; // 默认场景值 1011 扫描二维码
// TODO @puhui999这个默认是不是 release 哈?
private static String ENV_VERSION = "develop"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
// TODO @puhui999这个去掉因为本身就是 430 啦;
@ -28,6 +29,10 @@ public class AppSocialWxQrcodeReqVO {
@Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
private String scene = SCENE;
/**
* 默认是主页,页面 page例如 pages/index/index根路径前不要填加 /不能携带参数参数请放在scene字段里
* 如果不填写这个字段默认跳主页面。scancode_time为系统保留参数不允许配置
*/
@Schema(description = "页面路径", requiredMode = Schema.RequiredMode.REQUIRED, example = "pages/goods/index")
@NotEmpty(message = "页面路径不能为空")
private String path;