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

🍻 调整微信平台获取用户性别的代码逻辑,单独适配微信平台

上级 ab8c24ee
......@@ -26,5 +26,6 @@ hs_err_pid*
.idea
*.iml
*.sh
bin/*
target
\ No newline at end of file
target
## v1.1x(未发布)
- 修复抖音登录取值取错层级的问题([issue#I15SIG@Gitee](https://gitee.com/yadong.zhang/JustAuth/issues/I15SIG)
- 升级相关依赖:lombok@v1.18.10,hutool@5.0.5,fastjson@1.2.62,alipay@4.8.10.ALL([PR#11@Gitee](https://gitee.com/yadong.zhang/JustAuth/pulls/11)
- 完善异常提示的逻辑,支持传入Source(平台),发生异常时显示对应的source(平台)
- `checkState`方法从`AuthDefaultRequest`中提出到`AuthChecker`
- `AuthResponseStatus`枚举类中增加`ILLEGAL_STATUS``REQUIRED_REFRESH_TOKEN`两个枚举值
- `AuthSource`接口中增加`getName`方法,用来对外提供实际`source`的字符串值
- `AuthWeiboRequest`微博授权登录中实现`revoke`方法,支持手动回收授权
- 增加微信、QQ、支付宝、微博授权登录的帮助文档
- [帮助文档](https://docs.justauth.whnb.wang)中增加自定义的404页面
- [帮助文档](https://docs.justauth.whnb.wang)中增加Gittalk插件
- [帮助文档](https://docs.justauth.whnb.wang)中增加Java代码高亮的插件
- [帮助文档](https://docs.justauth.whnb.wang)中修复[腾讯云登录]链接错误的问题
## v1.13.2
- 新增
- 增加微信、QQ、支付宝、微博授权登录的帮助文档
- 合并[PR#57](https://github.com/justauth/JustAuth/pull/57),增加微信公众号登录 by [@xkcoding](https://github.com/xkcoding)
- [帮助文档](https://docs.justauth.whnb.wang)中增加自定义的404页面
- [帮助文档](https://docs.justauth.whnb.wang)中增加Gittalk插件
- [帮助文档](https://docs.justauth.whnb.wang)中增加Java代码高亮的插件
- 增加`AuthUserGender#getWechatRealGender`方法,兼容获取微信平台的用户性别
- 修改
- 修复抖音登录取值取错层级的问题([issue#I15SIG@Gitee](https://gitee.com/yadong.zhang/JustAuth/issues/I15SIG)
- 完善异常提示的逻辑,支持传入Source(平台),发生异常时显示对应的source(平台)
- `checkState`方法从`AuthDefaultRequest`中提出到`AuthChecker`
- `AuthResponseStatus`枚举类中增加`ILLEGAL_STATUS``REQUIRED_REFRESH_TOKEN`两个枚举值
- `AuthSource`接口中增加`getName`方法,用来对外提供实际`source`的字符串值
- `AuthWeiboRequest`微博授权登录中实现`revoke`方法,支持手动回收授权
- [帮助文档](https://docs.justauth.whnb.wang)中修复[腾讯云登录]链接错误的问题
- 升级
- 升级相关依赖:lombok@v1.18.10,hutool@5.0.5,fastjson@1.2.62,alipay@4.8.10.ALL([PR#11@Gitee](https://gitee.com/yadong.zhang/JustAuth/pulls/11)
## v1.13.1
### 2019/11/12
......
......@@ -2,6 +2,7 @@ package me.zhyd.oauth.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.zhyd.oauth.utils.StringUtils;
import java.util.Arrays;
......@@ -25,14 +26,34 @@ public enum AuthUserGender {
private String code;
private String desc;
public static AuthUserGender getRealGender(String code) {
if (null == code || UNKNOWN.getCode().equals(code)) {
/**
* 获取用户的实际性别,常规网站
*
* @param originalGender 用户第三方标注的原始性别
* @return 用户性别
*/
public static AuthUserGender getRealGender(String originalGender) {
if (null == originalGender || UNKNOWN.getCode().equals(originalGender)) {
return UNKNOWN;
}
String[] males = {"m", "男", "1", "male"};
if (Arrays.asList(males).contains(code.toLowerCase())) {
if (Arrays.asList(males).contains(originalGender.toLowerCase())) {
return MALE;
}
return FEMALE;
}
/**
* 获取微信平台用户的实际性别,0表示未定义,1表示男性,2表示女性
*
* @param originalGender 用户第三方标注的原始性别
* @return 用户性别
* @since 1.13.2
*/
public static AuthUserGender getWechatRealGender(String originalGender) {
if (StringUtils.isEmpty(originalGender) || "0".equals(originalGender)) {
return AuthUserGender.UNKNOWN;
}
return getRealGender(originalGender);
}
}
......@@ -12,6 +12,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/**
......@@ -63,8 +64,6 @@ public class AuthWeChatEnterpriseRequest extends AuthDefaultRequest {
HttpResponse userDetailResponse = getUserDetail(authToken.getAccessToken(), userId);
JSONObject userDetail = this.checkResponse(userDetailResponse);
String gender = getRealGender(userDetail);
return AuthUser.builder()
.username(userDetail.getString("name"))
.nickname(userDetail.getString("alias"))
......@@ -72,7 +71,7 @@ public class AuthWeChatEnterpriseRequest extends AuthDefaultRequest {
.location(userDetail.getString("address"))
.email(userDetail.getString("email"))
.uuid(userId)
.gender(AuthUserGender.getRealGender(gender))
.gender(AuthUserGender.getWechatRealGender(userDetail.getString("gender")))
.token(authToken)
.source(source.toString())
.build();
......@@ -94,20 +93,6 @@ public class AuthWeChatEnterpriseRequest extends AuthDefaultRequest {
return object;
}
/**
* 获取用户的实际性别,0表示未定义,1表示男性,2表示女性
*
* @param userDetail 用户详情
* @return 用户性别
*/
private String getRealGender(JSONObject userDetail) {
int gender = userDetail.getIntValue("gender");
if (AuthUserGender.MALE.getCode() == gender) {
return "1";
}
return 2 == gender ? "0" : null;
}
/**
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
*
......
......@@ -63,7 +63,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
.avatar(object.getString("headimgurl"))
.location(location)
.uuid(openId)
.gender(AuthUserGender.getRealGender(object.getString("sex")))
.gender(AuthUserGender.getWechatRealGender(object.getString("sex")))
.token(authToken)
.source(source.toString())
.build();
......
......@@ -62,7 +62,7 @@ public class AuthWeChatOpenRequest extends AuthDefaultRequest {
.avatar(object.getString("headimgurl"))
.location(location)
.uuid(openId)
.gender(AuthUserGender.getRealGender(object.getString("sex")))
.gender(AuthUserGender.getWechatRealGender(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.
先完成此消息的编辑!
想要评论请 注册