Commit b365b4027397d2f4b447ae9feffabf3c782ffe64

Authored by YunaiV
1 parent 450ca8f9

code review 用户社交登陆的逻辑

增加测试页面的 README.md
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;
15 15  
16 16 /**
17 17 * 第三方授权拓展 request 工厂类
18   - * (为使得拓展配置和默认配置齐平,自定义本工厂类)
  18 + * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类
19 19 *
20 20 * @author timfruit
21 21 * @date 2021-10-31
22 22 */
  23 +// TODO @timfruit:单测
23 24 public class YudaoAuthRequestFactory extends AuthRequestFactory {
24 25  
25 26 protected JustAuthProperties properties;
26 27 protected AuthStateCache authStateCache;
27 28  
  29 + /**
  30 + * 由于父类 configureHttpConfig 方法是 private 修饰,所以获取后,进行反射调用
  31 + */
  32 + private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class,
  33 + "configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class);
  34 +
28 35 public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
29 36 super(properties, authStateCache);
30 37 this.properties = properties;
... ... @@ -38,20 +45,17 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
38 45 * @return {@link AuthRequest}
39 46 */
40 47 public AuthRequest get(String source) {
41   - //先尝试获取自定义扩展的
  48 + // 先尝试获取自定义扩展的
42 49 AuthRequest authRequest = getExtendRequest(source);
43   -
  50 + // 找不到,使用默认拓展
44 51 if (authRequest == null) {
45 52 authRequest = super.get(source);
46 53 }
47   -
48 54 return authRequest;
49 55 }
50 56  
51   -
52 57 protected AuthRequest getExtendRequest(String source) {
53 58 AuthExtendSource authExtendSource;
54   -
55 59 try {
56 60 authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase());
57 61 } catch (IllegalArgumentException e) {
... ... @@ -59,19 +63,18 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
59 63 return null;
60 64 }
61 65  
62   - // 拓展配置和默认配置齐平,properties放在一起
  66 + // 拓展配置和默认配置齐平,properties 放在一起
63 67 AuthConfig config = properties.getType().get(authExtendSource.name());
64 68 // 找不到对应关系,直接返回空
65 69 if (config == null) {
66 70 return null;
67 71 }
68   -
69 72 // 配置 http config
70   - Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig",
71   - String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class);
72   - ReflectUtil.invoke(this, method,
  73 + ReflectUtil.invoke(this, configureHttpConfigMethod,
73 74 authExtendSource.name(), config, properties.getHttpConfig());
74 75  
  76 + // 获得拓展的 Request
  77 + // noinspection SwitchStatementWithTooFewBranches
75 78 switch (authExtendSource) {
76 79 case WECHAT_MINI_PROGRAM:
77 80 return new AuthWeChatMiniProgramRequest(config, authStateCache);
... ...
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;
3 3 import me.zhyd.oauth.config.AuthSource;
4 4  
5 5 /**
6   - * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理<br>
  6 + * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理
7 7 *
8   - * 默认配置{@link me.zhyd.oauth.config.AuthDefaultSource}
  8 + * 默认配置 {@link me.zhyd.oauth.config.AuthDefaultSource}
  9 + *
  10 + * @author timfruit
9 11 */
10 12 public enum AuthExtendSource implements AuthSource {
11 13  
12 14 /**
13 15 * 微信小程序授权登录
14 16 */
15   - WECHAT_MINI_PROGRAM{
  17 + WECHAT_MINI_PROGRAM {
  18 +
16 19 @Override
17 20 public String authorize() {
18 21 // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html
... ...
yudao-user-server/src/main/resources/static/READMD.md 0 → 100644
  1 +## 微信公众号
  2 +
  3 +参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df
  4 +
  5 +① 访问 social-login.html 选择【微信公众号】
  6 +
  7 +② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定
  8 +
  9 +## 微信小程序
  10 +
  11 +参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa
  12 +
  13 +① 暂时使用 mini-program-test 项目
... ...