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

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

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