Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
6773c10fa5
|
|
@ -37,7 +37,12 @@ public class UserAuthorizationController {
|
|||
return CzgResult.success(userAuthorizationService.login(userAuthorizationLoginDTO));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
/**
|
||||
* 获取手机号
|
||||
* @param getPhoneDTO 获取手机号信息
|
||||
* @return 手机号
|
||||
*/
|
||||
@PostMapping("/phone")
|
||||
public CzgResult<String> getPhone(@RequestBody @Validated GetPhoneDTO getPhoneDTO) {
|
||||
return CzgResult.success(userAuthorizationService.getPhone(getPhoneDTO));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.czg.account.dto.auth;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -10,8 +11,19 @@ public class GetPhoneDTO {
|
|||
/**
|
||||
* 来源 alipay支付宝 wechat微信
|
||||
*/
|
||||
@NotBlank(message = "来源不能为空")
|
||||
private String source;
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
@NotBlank(message = "数据不能为空")
|
||||
private String encryptedData;
|
||||
/**
|
||||
* 获取到的凭证code
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 仅微信传递
|
||||
*/
|
||||
private String iv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@ package com.czg.service.account.service.impl;
|
|||
|
||||
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.czg.account.dto.auth.GetPhoneDTO;
|
||||
import com.czg.account.dto.auth.LoginTokenDTO;
|
||||
import com.czg.account.dto.auth.UserAuthorizationLoginDTO;
|
||||
|
|
@ -22,7 +20,6 @@ import com.czg.sa.StpKit;
|
|||
import com.czg.service.account.util.AlipayUtil;
|
||||
import com.czg.service.account.util.WechatAuthUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -56,16 +53,20 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
|||
public String getPhone(GetPhoneDTO phoneDTO) {
|
||||
String mobile;
|
||||
String openId;
|
||||
UserInfo userInfo;
|
||||
UserInfo userInfo = null;
|
||||
if (UserAuthSourceEnum.ALIPAY.getValue().equals(phoneDTO.getSource())) {
|
||||
openId = alipayUtil.getOpenId(phoneDTO.getCode(), true);
|
||||
mobile = alipayUtil.getMobile(phoneDTO.getEncryptedData());
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getWechatOpenId, openId).one();
|
||||
if (StrUtil.isNotBlank(openId)) {
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getWechatOpenId, openId).one();
|
||||
}
|
||||
} else {
|
||||
JSONObject session = wechatAuthUtil.getSession(phoneDTO.getCode());
|
||||
String sessionKey = session.getString("session_key");
|
||||
openId = session.getString("openid");
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getAlipayOpenId, openId).one();
|
||||
if (StrUtil.isNotBlank(openId)) {
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getAlipayOpenId, openId).one();
|
||||
}
|
||||
String data = WxMaCryptUtils.decrypt(sessionKey, phoneDTO.getEncryptedData(), phoneDTO.getIv());
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
if (jsonObject.containsKey("phoneNumber")) {
|
||||
|
|
@ -74,6 +75,11 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
|||
throw new ApiNotPrintException("手机号获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
if (userInfo != null) {
|
||||
userInfo.setPhone(mobile);
|
||||
userInfoService.updateById(userInfo);
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue