mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 #3345 【小程序】获取手机号 getPhoneNoInfo方法兼容旧版本
This commit is contained in:
parent
748c19f108
commit
e6ec2a5173
@ -45,7 +45,19 @@ public interface WxMaUserService {
|
|||||||
void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid) throws WxErrorException;
|
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>
|
* @param code 每个code只能使用一次,code的有效期为5min。code获取方式参考<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">手机号快速验证组件</a>
|
||||||
* @return 用户手机号信息
|
* @return 用户手机号信息
|
||||||
@ -55,7 +67,7 @@ public interface WxMaUserService {
|
|||||||
WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException;
|
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>
|
* @param code 每个code只能使用一次,code的有效期为5min。code获取方式参考<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">手机号快速验证组件</a>
|
||||||
* @return 用户手机号信息
|
* @return 用户手机号信息
|
||||||
|
@ -57,6 +57,11 @@ public class WxMaUserServiceImpl implements WxMaUserService {
|
|||||||
this.service.post(url, params);
|
this.service.post(url, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr) {
|
||||||
|
return WxMaPhoneNumberInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException {
|
public WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
@ -67,7 +72,6 @@ public class WxMaUserServiceImpl implements WxMaUserService {
|
|||||||
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
|
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
|
||||||
WxMaPhoneNumberInfo.class);
|
WxMaPhoneNumberInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,16 @@ public class WxMaUserServiceImplTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPhoneNoInfo() throws WxErrorException {
|
public void testGetPhoneNoInfo() {
|
||||||
|
WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo("tiihtNczf5v6AKRyjwEUhQ==",
|
||||||
|
"CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew==",
|
||||||
|
"r7BXXKkLb8qrSNn05n0qiA==");
|
||||||
|
assertNotNull(phoneNoInfo);
|
||||||
|
System.out.println(phoneNoInfo.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPhoneInfo() throws WxErrorException {
|
||||||
WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNumber("tiihtNczf5v6AKRyjwEUhQ==");
|
WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNumber("tiihtNczf5v6AKRyjwEUhQ==");
|
||||||
assertNotNull(phoneNoInfo);
|
assertNotNull(phoneNoInfo);
|
||||||
System.out.println(phoneNoInfo.toString());
|
System.out.println(phoneNoInfo.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user