Skip to content

#3345 【小程序】获取手机号 getPhoneNoInfo 旧版本兼容 #3350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 用户手机号信息
Expand All @@ -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 用户手机号信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void setUserStorage(Map<String, String> kvMap, String sessionKey, String
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();
Expand All @@ -67,7 +72,6 @@ public WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
WxMaPhoneNumberInfo.class);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ public void testCheckUserInfo() {


@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==");
assertNotNull(phoneNoInfo);
System.out.println(phoneNoInfo.toString());
Expand Down