获取手机号
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
//import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
@@ -51,36 +51,37 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
|
||||
@Override
|
||||
public String getPhone(GetPhoneDTO phoneDTO) {
|
||||
String mobile;
|
||||
String openId;
|
||||
UserInfo userInfo = null;
|
||||
if (UserAuthSourceEnum.ALIPAY.getValue().equals(phoneDTO.getSource())) {
|
||||
openId = alipayUtil.getOpenId(phoneDTO.getCode(), true);
|
||||
mobile = alipayUtil.getMobile(phoneDTO.getEncryptedData());
|
||||
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");
|
||||
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")) {
|
||||
mobile = jsonObject.getString("phoneNumber");
|
||||
}else {
|
||||
throw new ApiNotPrintException("手机号获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
if (userInfo != null) {
|
||||
userInfo.setPhone(mobile);
|
||||
userInfoService.updateById(userInfo);
|
||||
}
|
||||
return mobile;
|
||||
// String mobile;
|
||||
// String openId;
|
||||
// UserInfo userInfo = null;
|
||||
// if (UserAuthSourceEnum.ALIPAY.getValue().equals(phoneDTO.getSource())) {
|
||||
// openId = alipayUtil.getOpenId(phoneDTO.getCode(), true);
|
||||
// mobile = alipayUtil.getMobile(phoneDTO.getEncryptedData());
|
||||
// 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");
|
||||
// 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")) {
|
||||
// mobile = jsonObject.getString("phoneNumber");
|
||||
// }else {
|
||||
// throw new ApiNotPrintException("手机号获取失败");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (userInfo != null) {
|
||||
// userInfo.setPhone(mobile);
|
||||
// userInfoService.updateById(userInfo);
|
||||
// }
|
||||
// return mobile;
|
||||
return "123";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user