核心代码
public GenerateQrcodeRespVO generateQrcode(SocialWxQrcodeReqDTO reqVO) {
try {
GenerateQrcodeRespVO qrcodeReqDTO = new GenerateQrcodeRespVO();
String businessId = RandomUtil.randomString(20);
qrcodeReqDTO.setBusinessId(businessId);
stringRedisTemplate.opsForValue().set("businessSign:signatureGenerateId:" + businessId, businessId, 10, TimeUnit.MINUTES);
reqVO.setScene(businessId);
reqVO.setPath("pagesMain/views/businessSign/index");
reqVO.setCheckPath(false);
byte[] qrcodeByte = socialClientService.getWxaQrcode(reqVO);
qrcodeReqDTO.setQrcodeByte(qrcodeByte);
return qrcodeReqDTO;
} catch (Exception e) {
log.error("[getWxQrcode][reqVO({}) 获得小程序码失败]", reqVO, e);
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR);
}
}
public byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO) {
WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
try {
return service.getQrcodeService().createWxaCodeUnlimitBytes(
ObjUtil.defaultIfEmpty(reqVO.getScene(), SocialWxQrcodeReqDTO.SCENE),
reqVO.getPath(),
ObjUtil.defaultIfNull(reqVO.getCheckPath(), SocialWxQrcodeReqDTO.CHECK_PATH),
envVersion,
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);
}
}
报错信息:
me.chanjar.weixin.common.error.WxErrorException: 错误代码:40097, 错误信息:参数错误,微信原始报文:{"errcode":40097,"errmsg":"invalid args rid: 695f0568-5de47e63-3eef7ff9"}
postman截个图吧
750504 【请求地址】: https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=99_oae69LvLYHoih1Si_JyEeooTUY-b2f3U4HMId0TNLVbiGq7c-GMhl9vWUroaG84QgQ3MzhyqHooZnkBwKwTe6tri88HjsS9Qw5wUjwRpXFxsSGN20R3mZgv7nq8SSXaAIANNS
750505 【请求参数】:WxaCodeUnlimit(scene=70545877011c4a968d58d3d6bf13868e, page=pagesMain/views/businessSign/index, checkPath=false, envVersion=formal, width=430, autoColor=true, isHyaline=true, lineColor=null)
750506 【错误信息】:错误代码:40097, 错误信息:参数错误,微信原始报文:{"errcode":40097,"errmsg":"invalid args rid: 695f0568-5de47e63-3eef7ff9"}
750507 2026-01-08 09:16:24.633 | ^[[1;31mERROR 1301759^[[0;39m | ^[[1;33mhttp-nio-48086-exec-6 [TID: N/A]^[[0;39m ^[[1;32mc.s.m.s.s.s.SocialClientServiceImpl ^[[0;39m | [getWxQrcode][reqVO(SocialWxQrcodeReqDTO(scene=70545877011c4a968d58d3d6bf13868e, path=pagesMain/v iews/businessSign/index, width=null, autoColor=null, checkPath=false, hyaline=null)) 获得小程序码失败]