diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendToken.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendToken.java index b336511cb..2ecb0d461 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendToken.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendToken.java @@ -4,6 +4,7 @@ import lombok.*; import me.zhyd.oauth.model.AuthToken; /** + * TODO @timfruit:类注释 * @author timfruit * @date 2021-10-29 */ @@ -12,10 +13,10 @@ import me.zhyd.oauth.model.AuthToken; @NoArgsConstructor @AllArgsConstructor public class AuthExtendToken extends AuthToken { + /** * 微信小程序 会话密钥 */ private String miniSessionKey; - } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthWeChatMiniProgramRequest.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthWeChatMiniProgramRequest.java index 84c920b3d..664f9157f 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthWeChatMiniProgramRequest.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthWeChatMiniProgramRequest.java @@ -11,13 +11,17 @@ import me.zhyd.oauth.request.AuthDefaultRequest; import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.UrlBuilder; +// TODO @timfruit:新建一个 yudao-spring-boot-starter-biz-social 包,把这个拓展拿进去哈。另外,可以思考下。 +// 1. application-local.yaml 的配置里,justauth.extend.enum-class 能否不配置,而是自动配置好 +// 2. application-local.yaml 的配置里,justauth.extend.extend.config.WECHAT_MINI_PROGRAM 有办法和 justauth.type.WECHAT_MP 持平 /** - * 微信小程序 + * 微信小程序登陆 * * @author timfruit * @date 2021-10-29 */ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { + public AuthWeChatMiniProgramRequest(AuthConfig config) { super(config, AuthExtendSource.WECHAT_MINI_PROGRAM); } @@ -30,11 +34,11 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { protected AuthToken getAccessToken(AuthCallback authCallback) { // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode())); - JSONObject accessTokenObject = JSONObject.parseObject(response); + JSONObject accessTokenObject = JSONObject.parseObject(response); // TODO @timfruit:使用 JsonUtils,项目尽量避免直接使用某个 json 库 this.checkResponse(accessTokenObject); - AuthExtendToken token=new AuthExtendToken(); + AuthExtendToken token = new AuthExtendToken(); token.setMiniSessionKey(accessTokenObject.getString("session_key")); token.setOpenId(accessTokenObject.getString("openid")); token.setUnionId(accessTokenObject.getString("unionid")); @@ -62,16 +66,16 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { */ private void checkResponse(JSONObject object) { int code = object.getIntValue("errcode"); - if(code != 0){ + if(code != 0){ // TODO @timfruit:if (code != 0) { ,注意空格 throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg")); } } /** - * 返回获取accessToken的url + * 返回获取 accessToken 的 url * * @param code 授权码 - * @return 返回获取accessToken的url + * @return 返回获取 accessToken 的 url */ @Override protected String accessTokenUrl(String code) { @@ -82,4 +86,5 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { .queryParam("grant_type", "authorization_code") .build(); } + } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/social/SysSocialTypeEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/social/SysSocialTypeEnum.java index d36d8a727..3dba5bda0 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/social/SysSocialTypeEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/social/SysSocialTypeEnum.java @@ -18,24 +18,37 @@ import java.util.List; @AllArgsConstructor public enum SysSocialTypeEnum implements IntArrayValuable { - GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ - DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials + /** + * Gitee + * 文档链接:https://gitee.com/api/v5/oauth_doc#/ + */ + GITEE(10, "GITEE"), + /** + * 钉钉 + * 文档链接:https://developers.dingtalk.com/document/app/obtain-identity-credentials + */ + DINGTALK(20, "DINGTALK"), + /** * 企业微信 + * 文档链接:https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html */ - WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html + WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), /** - * 微信公众平台 - 移动端H5 + * 微信公众平台 - 移动端 H5 + * 文档链接:https://www.cnblogs.com/juewuzhe/p/11905461.html */ - WECHAT_MP(31, "WECHAT_MP"), // https://www.cnblogs.com/juewuzhe/p/11905461.html + WECHAT_MP(31, "WECHAT_MP"), /** - * 微信开放平台 - 网站应用 pc端扫码授权登录 + * 微信开放平台 - 网站应用 PC 端扫码授权登录 + * 文档链接:https://justauth.wiki/guide/oauth/wechat_open/#_2-申请开发者资质认证 */ - WECHAT_OPEN(32, "WECHAT_OPEN"), // https://justauth.wiki/guide/oauth/wechat_open/#_2-%E7%94%B3%E8%AF%B7%E5%BC%80%E5%8F%91%E8%80%85%E8%B5%84%E8%B4%A8%E8%AE%A4%E8%AF%81 + WECHAT_OPEN(32, "WECHAT_OPEN"), /** * 微信小程序 + * 文档链接:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html */ - WECHAT_MINI_PROGRAM(33, "WECHAT_MINI_PROGRAM"), // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html + WECHAT_MINI_PROGRAM(33, "WECHAT_MINI_PROGRAM"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSocialTypeEnum::getType).toArray(); diff --git a/yudao-user-server/src/main/resources/application-local.yaml b/yudao-user-server/src/main/resources/application-local.yaml index e5756b9c9..c57d17808 100644 --- a/yudao-user-server/src/main/resources/application-local.yaml +++ b/yudao-user-server/src/main/resources/application-local.yaml @@ -145,19 +145,6 @@ yudao: justauth: enabled: true type: - GITEE: # Gitee - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 - ignore-check-redirect-uri: true - DINGTALK: # 钉钉 - client-id: dingvrnreaje3yqvzhxg - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI - ignore-check-redirect-uri: true - WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 - ignore-check-redirect-uri: true WECHAT_MP: # 微信公众平台 - 移动端H5 https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index client-id: wxa5a05b85ac361f96 client-secret: 247073c7cebb67f27f0e769195c2a57e @@ -174,4 +161,4 @@ justauth: cache: type: REDIS prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: - timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 \ No newline at end of file + timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟