fix bug
This commit is contained in:
@ -19,7 +19,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode ORDER_PAY_FINISH = new ErrorCode(1008007010, "该订单已支付");
|
||||
|
||||
ErrorCode USER_NOT_BINDING_WX_APPLET = new ErrorCode(1008007011, "该用户未绑定微信小程序!openid为空!");
|
||||
ErrorCode USER_NOT_BINDING_WX = new ErrorCode(1008007011, "该用户未绑定微信手机号无法调起支付");
|
||||
ErrorCode USER_NOT_BINDING_WX = new ErrorCode(1008007011, "该用户未支持支付,请使用小程序或其他浏览器登录");
|
||||
ErrorCode PAY_YUE_NOT = new ErrorCode(1008007011, "余额不足");
|
||||
ErrorCode ORDER_STATUS_ERROR = new ErrorCode(1008007012, "订单状态错误");
|
||||
ErrorCode COMMENT_PRODUCT_NOT_EXISTS = new ErrorCode(1008007013, "评价产品不存在");
|
||||
|
@ -61,4 +61,7 @@ public class AppAuthSmsLoginReqVO {
|
||||
return socialType == null || StrUtil.isNotEmpty(socialState);
|
||||
}
|
||||
|
||||
@Schema(description = "登录 code,小程序通过 wx.login 方法获得", requiredMode = Schema.RequiredMode.REQUIRED, example = "word")
|
||||
private String loginCode;
|
||||
|
||||
}
|
||||
|
@ -106,7 +106,8 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
||||
}
|
||||
|
||||
// 获得获得注册用户
|
||||
MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, reqVO.getFrom(), reqVO.getInvitationCode());
|
||||
MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, reqVO.getFrom(),
|
||||
reqVO.getInvitationCode(), reqVO.getLoginCode());
|
||||
Assert.notNull(user, "获取用户失败,结果为空");
|
||||
|
||||
// 如果 socialType 非空,说明需要绑定社交用户
|
||||
@ -166,7 +167,7 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
||||
if (memberUserDO == null) {
|
||||
// 获得获得注册用户
|
||||
memberUserDO = userService.createUserIfAbsent(phoneNumberInfo.getPhoneNumber(), getClientIP(),
|
||||
LoginTypeEnum.WXAPP.getValue(), reqVO.getInvitationCode());
|
||||
LoginTypeEnum.WXAPP.getValue(), reqVO.getInvitationCode(), null);
|
||||
memberUserDO.setNickname("用户_" + memberUserDO.getId());
|
||||
}
|
||||
memberUserDO.setRoutineOpenId(session.getOpenid());
|
||||
|
@ -43,9 +43,10 @@ public interface MemberUserService extends IService<MemberUserDO> {
|
||||
* @param mobile 手机号
|
||||
* @param registerIp 注册 IP
|
||||
* @param invitationCode 邀请码
|
||||
* @param loginCode 登录 code
|
||||
* @return 用户对象
|
||||
*/
|
||||
MemberUserDO createUserIfAbsent(@Mobile String mobile, String registerIp, String from, String invitationCode);
|
||||
MemberUserDO createUserIfAbsent(@Mobile String mobile, String registerIp, String from, String invitationCode, String loginCode);
|
||||
|
||||
/**
|
||||
* 更新用户的最后登陆信息
|
||||
|
@ -1,5 +1,7 @@
|
||||
package co.yixiang.yshop.module.member.service.user;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
@ -29,6 +31,8 @@ import co.yixiang.yshop.module.system.service.dict.DictDataService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
@ -46,8 +50,7 @@ import java.util.Objects;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static co.yixiang.yshop.module.member.enums.ErrorCodeConstants.NOT_ENOUGH_INTEGRAL;
|
||||
import static co.yixiang.yshop.module.member.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
||||
import static co.yixiang.yshop.module.member.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 会员 User Service 实现类
|
||||
@ -82,6 +85,8 @@ public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberU
|
||||
private UserInviteLogService userInviteLogService;
|
||||
@Resource
|
||||
private UserBillService userBillService;
|
||||
@Resource
|
||||
private WxMaService wxMaService;
|
||||
|
||||
|
||||
@Override
|
||||
@ -95,19 +100,42 @@ public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberU
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemberUserDO createUserIfAbsent(String mobile, String registerIp, String from, String invitationCode) {
|
||||
public MemberUserDO createUserIfAbsent(String mobile, String registerIp, String from, String invitationCode, String loginCode) {
|
||||
// 用户已经存在
|
||||
MemberUserDO user = memberUserMapper.selectByMobile(mobile);
|
||||
if (!StringUtils.isNotBlank(user.getRoutineOpenId()) && StringUtils.isNotBlank(loginCode)) {
|
||||
this.updateOpenId(user.getId(), loginCode);
|
||||
}
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
// 用户不存在,则进行创建
|
||||
user = this.createUser(mobile, registerIp, from);
|
||||
if (StringUtils.isNotBlank(loginCode)) {
|
||||
this.updateOpenId(user.getId(), loginCode);
|
||||
}
|
||||
// 处理其他逻辑
|
||||
handlerAfterRegister(user, invitationCode);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新小程序openId
|
||||
*
|
||||
* @param id 用户id
|
||||
* @param loginCode 登录code
|
||||
*/
|
||||
private void updateOpenId(Long id, String loginCode) {
|
||||
WxMaJscode2SessionResult session;
|
||||
try {
|
||||
session = wxMaService.getUserService().getSessionInfo(loginCode);
|
||||
} catch (WxErrorException e) {
|
||||
log.error(e.getMessage());
|
||||
throw exception(MINI_AUTH_LOGIN_BAD);
|
||||
}
|
||||
this.updateById(new MemberUserDO().setId(id).setRoutineOpenId(session.getOpenid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理注册完成之后其他墨迹
|
||||
*
|
||||
|
@ -96,7 +96,7 @@ public class AppPayController {
|
||||
}
|
||||
if (PayTypeEnum.WEIXIN.getType().equals(param.getPayType())) {
|
||||
//小程序支付需要openid
|
||||
if (Objects.isNull(user.getRoutineOpenId())) throw exception(USER_NOT_BINDING_WX);
|
||||
if (Objects.isNull(user.getRoutineOpenId())) throw exception(USER_NOT_BINDING_WX);
|
||||
}
|
||||
payParam.setType(param.getPayType());
|
||||
payParam.setMerchantDetailsDO(merchantDetailsDO);
|
||||
|
@ -168,19 +168,19 @@ wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-sta
|
||||
|
||||
--- #微信支付配置
|
||||
weixin:
|
||||
#小程序appid
|
||||
#小程序appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
appid:
|
||||
#APP端的appid
|
||||
#APP端的appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
app_appid:
|
||||
#小程序秘钥
|
||||
#小程序秘钥,在后台支付配置中配在merchant_details表中,对应密钥
|
||||
secret:
|
||||
#商户号
|
||||
#商户号,在后台支付配置中配在merchant_details表中,对应微信商户id
|
||||
mchid:
|
||||
#证书路径
|
||||
certurl:
|
||||
certurl: /yshop-server/apiclient_cert.p12
|
||||
#订单取消退款回调地址
|
||||
order_refund_notifyurl:
|
||||
#APP回调地址
|
||||
#APP回调地址,在后台支付配置中配在merchant_details表中,对应异步回调地址
|
||||
app_notifyurl:
|
||||
#商户秘钥
|
||||
key:
|
||||
|
@ -180,19 +180,19 @@ wx:
|
||||
|
||||
--- #微信支付配置
|
||||
weixin:
|
||||
#小程序appid
|
||||
#小程序appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
appid:
|
||||
#APP端的appid
|
||||
#APP端的appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
app_appid:
|
||||
#小程序秘钥
|
||||
#小程序秘钥,在后台支付配置中配在merchant_details表中,对应密钥
|
||||
secret:
|
||||
#商户号
|
||||
#商户号,在后台支付配置中配在merchant_details表中,对应微信商户id
|
||||
mchid:
|
||||
#证书路径
|
||||
certurl:
|
||||
certurl: /yshop-server/apiclient_cert.p12
|
||||
#订单取消退款回调地址
|
||||
order_refund_notifyurl:
|
||||
#APP回调地址
|
||||
#APP回调地址,在后台支付配置中配在merchant_details表中,对应异步回调地址
|
||||
app_notifyurl:
|
||||
#商户秘钥
|
||||
key:
|
||||
|
@ -179,24 +179,24 @@ wx:
|
||||
|
||||
--- #微信支付配置
|
||||
weixin:
|
||||
#appid
|
||||
#小程序appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
appid:
|
||||
#APP端的appid
|
||||
#APP端的appid,在后台支付配置中配在merchant_details表中,对应应用id
|
||||
app_appid:
|
||||
#小程序秘钥
|
||||
#小程序秘钥,在后台支付配置中配在merchant_details表中,对应密钥
|
||||
secret:
|
||||
#商户号
|
||||
#商户号,在后台支付配置中配在merchant_details表中,对应微信商户id
|
||||
mchid:
|
||||
#证书路径
|
||||
certurl: /yshop-server/apiclient_cert.p12
|
||||
#订单取消退款回调地址
|
||||
order_refund_notifyurl:
|
||||
#APP回调地址
|
||||
#APP回调地址,在后台支付配置中配在merchant_details表中,对应异步回调地址
|
||||
app_notifyurl:
|
||||
#商户秘钥
|
||||
key:
|
||||
#h5支付之后跳转地址
|
||||
redirect_url:
|
||||
redirect_url: http://localhost:8080/
|
||||
--- #################### yshop相关配置 ####################
|
||||
|
||||
# yshop配置项,设置当前项目所有自定义的配置
|
||||
|
Reference in New Issue
Block a user