获取手机号

This commit is contained in:
wangw 2025-03-11 10:39:27 +08:00
parent b4049079e0
commit 3e4ebd2039
3 changed files with 47 additions and 46 deletions

View File

@ -48,11 +48,11 @@
<artifactId>cash-common-tools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>${weixin.java.miniapp.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.binarywang</groupId>-->
<!-- <artifactId>weixin-java-miniapp</artifactId>-->
<!-- <version>${weixin.java.miniapp.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.google.zxing</groupId>

View File

@ -18,16 +18,16 @@
</properties>
<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<exclusions>
<exclusion>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.binarywang</groupId>-->
<!-- <artifactId>weixin-java-miniapp</artifactId>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>

View File

@ -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