From b365b4027397d2f4b447ae9feffabf3c782ffe64 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 15 Dec 2021 09:18:15 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=20=E7=94=A8=E6=88=B7=E7=A4=BE?= =?UTF-8?q?=E4=BA=A4=E7=99=BB=E9=99=86=E7=9A=84=E9=80=BB=E8=BE=91=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../social/core/YudaoAuthRequestFactory.java | 25 +++++++++++-------- .../social/core/enums/AuthExtendSource.java | 9 ++++--- .../src/main/resources/static/READMD.md | 13 ++++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 yudao-user-server/src/main/resources/static/READMD.md diff --git a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java index 26e23b9d7..8f3cf5d51 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java @@ -15,16 +15,23 @@ import java.lang.reflect.Method; /** * 第三方授权拓展 request 工厂类 - * (为使得拓展配置和默认配置齐平,自定义本工厂类) + * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类 * * @author timfruit * @date 2021-10-31 */ +// TODO @timfruit:单测 public class YudaoAuthRequestFactory extends AuthRequestFactory { protected JustAuthProperties properties; protected AuthStateCache authStateCache; + /** + * 由于父类 configureHttpConfig 方法是 private 修饰,所以获取后,进行反射调用 + */ + private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class, + "configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); + public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { super(properties, authStateCache); this.properties = properties; @@ -38,20 +45,17 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { * @return {@link AuthRequest} */ public AuthRequest get(String source) { - //先尝试获取自定义扩展的 + // 先尝试获取自定义扩展的 AuthRequest authRequest = getExtendRequest(source); - + // 找不到,使用默认拓展 if (authRequest == null) { authRequest = super.get(source); } - return authRequest; } - protected AuthRequest getExtendRequest(String source) { AuthExtendSource authExtendSource; - try { authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); } catch (IllegalArgumentException e) { @@ -59,19 +63,18 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { return null; } - // 拓展配置和默认配置齐平,properties放在一起 + // 拓展配置和默认配置齐平,properties 放在一起 AuthConfig config = properties.getType().get(authExtendSource.name()); // 找不到对应关系,直接返回空 if (config == null) { return null; } - // 配置 http config - Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig", - String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); - ReflectUtil.invoke(this, method, + ReflectUtil.invoke(this, configureHttpConfigMethod, authExtendSource.name(), config, properties.getHttpConfig()); + // 获得拓展的 Request + // noinspection SwitchStatementWithTooFewBranches switch (authExtendSource) { case WECHAT_MINI_PROGRAM: return new AuthWeChatMiniProgramRequest(config, authStateCache); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java index 16049419f..ce61bca40 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java @@ -3,16 +3,19 @@ package cn.iocoder.yudao.framework.social.core.enums; import me.zhyd.oauth.config.AuthSource; /** - * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理
+ * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理 * - * 默认配置{@link me.zhyd.oauth.config.AuthDefaultSource} + * 默认配置 {@link me.zhyd.oauth.config.AuthDefaultSource} + * + * @author timfruit */ public enum AuthExtendSource implements AuthSource { /** * 微信小程序授权登录 */ - WECHAT_MINI_PROGRAM{ + WECHAT_MINI_PROGRAM { + @Override public String authorize() { // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html diff --git a/yudao-user-server/src/main/resources/static/READMD.md b/yudao-user-server/src/main/resources/static/READMD.md new file mode 100644 index 000000000..2cf46688d --- /dev/null +++ b/yudao-user-server/src/main/resources/static/READMD.md @@ -0,0 +1,13 @@ +## 微信公众号 + +参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df + +① 访问 social-login.html 选择【微信公众号】 + +② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定 + +## 微信小程序 + +参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa + +① 暂时使用 mini-program-test 项目