🎨 规范化代码

This commit is contained in:
Binary Wang 2022-10-31 11:42:38 +08:00
parent bf9c0571f8
commit ae08833323
2 changed files with 25 additions and 6 deletions

View File

@ -51,7 +51,9 @@ public interface WxMaUserService {
* @param encryptedData 消息密文 * @param encryptedData 消息密文
* @param ivStr 加密算法的初始向量 * @param ivStr 加密算法的初始向量
* @return . * @return .
* @deprecated 请使用替代方法 {@link #getPhoneNoInfo(String)}
*/ */
@Deprecated
WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr); WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr);
/** /**
@ -61,6 +63,17 @@ public interface WxMaUserService {
* @return . * @return .
* @throws WxErrorException . * @throws WxErrorException .
*/ */
WxMaPhoneNumberInfo getPhoneNoInfo(String code) throws WxErrorException;
/**
* 获取手机号信息,基础库:2.21.2及以上
*
* @param code 动态令牌
* @return .
* @throws WxErrorException .
* @deprecated 命名有些复杂请使用替代方法 {@link #getPhoneNoInfo(String)}
*/
@Deprecated
WxMaPhoneNumberInfo getNewPhoneNoInfo(String code) throws WxErrorException; WxMaPhoneNumberInfo getNewPhoneNoInfo(String code) throws WxErrorException;
/** /**

View File

@ -26,6 +26,7 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.SET_USE
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMaUserServiceImpl implements WxMaUserService { public class WxMaUserServiceImpl implements WxMaUserService {
private static final String PHONE_INFO = "phone_info";
private final WxMaService service; private final WxMaService service;
@Override @Override
@ -62,17 +63,22 @@ public class WxMaUserServiceImpl implements WxMaUserService {
} }
@Override @Override
public WxMaPhoneNumberInfo getNewPhoneNoInfo(String code) throws WxErrorException { public WxMaPhoneNumberInfo getPhoneNoInfo(String code) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("code", code); param.addProperty("code", code);
String responseContent = this.service.post(GET_PHONE_NUMBER_URL, param.toString()); String responseContent = this.service.post(GET_PHONE_NUMBER_URL, param.toString());
JsonObject response = GsonParser.parse(responseContent); JsonObject response = GsonParser.parse(responseContent);
boolean hasPhoneInfo = response.has("phone_info"); if (response.has(PHONE_INFO)) {
if (hasPhoneInfo) { return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject("phone_info"), WxMaPhoneNumberInfo.class); WxMaPhoneNumberInfo.class);
} else { }
return null; return null;
} }
@Override
public WxMaPhoneNumberInfo getNewPhoneNoInfo(String code) throws WxErrorException {
return this.getPhoneNoInfo(code);
} }
@Override @Override