提交 ab8c24ee 编写于 作者: 智布道's avatar 智布道 👁

🍻 调整过获取用户性别的逻辑

上级 cd24cbdd
...@@ -141,7 +141,7 @@ public class RestAuthController { ...@@ -141,7 +141,7 @@ public class RestAuthController {
"email": null, "email": null,
"remark": null, "remark": null,
"gender": "MALE", "gender": "MALE",
"source": "WECHAT", "source": "WECHAT_OPEN",
"token": { "token": {
"accessToken": "28_Bzvt4UxxxxFElOxxxxgTqIJmSE5LxB2Az7stFqYVnFoIhL7RbevA0Urc", "accessToken": "28_Bzvt4UxxxxFElOxxxxgTqIJmSE5LxB2Az7stFqYVnFoIhL7RbevA0Urc",
"expireIn": 7200, "expireIn": 7200,
......
...@@ -18,25 +18,21 @@ public enum AuthUserGender { ...@@ -18,25 +18,21 @@ public enum AuthUserGender {
* MALE/FAMALE为正常值,通过{@link AuthUserGender#getRealGender(String)}方法获取真实的性别 * MALE/FAMALE为正常值,通过{@link AuthUserGender#getRealGender(String)}方法获取真实的性别
* UNKNOWN为容错值,部分平台不会返回用户性别,为了方便统一,使用UNKNOWN标记所有未知或不可测的用户性别信息 * UNKNOWN为容错值,部分平台不会返回用户性别,为了方便统一,使用UNKNOWN标记所有未知或不可测的用户性别信息
*/ */
MALE(1, "男"), MALE("1", "男"),
FEMALE(0, "女"), FEMALE("0", "女"),
UNKNOWN(-1, "未知"); UNKNOWN("-1", "未知");
private int code; private String code;
private String desc; private String desc;
public static AuthUserGender getRealGender(String code) { public static AuthUserGender getRealGender(String code) {
if (code == null) { if (null == code || UNKNOWN.getCode().equals(code)) {
return UNKNOWN; return UNKNOWN;
} }
String[] males = {"m", "男", "1", "male"}; String[] males = {"m", "男", "1", "male"};
if (Arrays.asList(males).contains(code.toLowerCase())) { if (Arrays.asList(males).contains(code.toLowerCase())) {
return MALE; return MALE;
} }
String[] females = {"f", "女", "0", "female"}; return FEMALE;
if (Arrays.asList(females).contains(code.toLowerCase())) {
return FEMALE;
}
return UNKNOWN;
} }
} }
...@@ -57,25 +57,13 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest { ...@@ -57,25 +57,13 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
authToken.setUnionId(object.getString("unionid")); authToken.setUnionId(object.getString("unionid"));
} }
AuthUserGender sex;
switch (object.getString("sex")) {
case "1":
sex = AuthUserGender.MALE;
break;
case "2":
sex = AuthUserGender.FEMALE;
break;
default:
sex = AuthUserGender.UNKNOWN;
}
return AuthUser.builder() return AuthUser.builder()
.username(object.getString("nickname")) .username(object.getString("nickname"))
.nickname(object.getString("nickname")) .nickname(object.getString("nickname"))
.avatar(object.getString("headimgurl")) .avatar(object.getString("headimgurl"))
.location(location) .location(location)
.uuid(openId) .uuid(openId)
.gender(sex) .gender(AuthUserGender.getRealGender(object.getString("sex")))
.token(authToken) .token(authToken)
.source(source.toString()) .source(source.toString())
.build(); .build();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册