mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🎨 #3345 【小程序】获取手机号 getPhoneNoInfo方法兼容旧版本
This commit is contained in:
@@ -45,7 +45,19 @@ public interface WxMaUserService {
|
||||
void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取手机号信息,2023年8月28日起
|
||||
* 解密用户手机号信息.
|
||||
*
|
||||
* @param sessionKey 会话密钥
|
||||
* @param encryptedData 消息密文
|
||||
* @param ivStr 加密算法的初始向量
|
||||
* @return .
|
||||
* @deprecated 当前(基础库2.21.2以下使用)旧版本,以上请使用替代方法 {@link #getPhoneNoInfo(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr);
|
||||
|
||||
/**
|
||||
* 获取手机号信息,基础库:2.21.2及以上或2023年8月28日起
|
||||
*
|
||||
* @param code 每个code只能使用一次,code的有效期为5min。code获取方式参考<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">手机号快速验证组件</a>
|
||||
* @return 用户手机号信息
|
||||
@@ -55,7 +67,7 @@ public interface WxMaUserService {
|
||||
WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取手机号信息,2023年8月28日起
|
||||
* 获取手机号信息,基础库:2.21.2及以上或2023年8月28日起
|
||||
*
|
||||
* @param code 每个code只能使用一次,code的有效期为5min。code获取方式参考<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">手机号快速验证组件</a>
|
||||
* @return 用户手机号信息
|
||||
|
||||
@@ -57,6 +57,11 @@ public class WxMaUserServiceImpl implements WxMaUserService {
|
||||
this.service.post(url, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr) {
|
||||
return WxMaPhoneNumberInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException {
|
||||
JsonObject param = new JsonObject();
|
||||
@@ -67,7 +72,6 @@ public class WxMaUserServiceImpl implements WxMaUserService {
|
||||
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
|
||||
WxMaPhoneNumberInfo.class);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user