mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	增加注释,优化代码
This commit is contained in:
		| @@ -1,24 +1,21 @@ | ||||
| package cn.iocoder.yudao.framework.social.core; | ||||
|  | ||||
| import cn.hutool.core.util.EnumUtil; | ||||
| import cn.hutool.core.util.ReflectUtil; | ||||
| import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; | ||||
| import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest; | ||||
| import com.xkcoding.http.config.HttpConfig; | ||||
| import com.xkcoding.justauth.AuthRequestFactory; | ||||
| import com.xkcoding.justauth.autoconfigure.JustAuthProperties; | ||||
| import me.zhyd.oauth.cache.AuthStateCache; | ||||
| import me.zhyd.oauth.config.AuthConfig; | ||||
| import me.zhyd.oauth.config.AuthSource; | ||||
| import me.zhyd.oauth.request.AuthRequest; | ||||
| import org.springframework.util.CollectionUtils; | ||||
|  | ||||
| import java.net.InetSocketAddress; | ||||
| import java.net.Proxy; | ||||
| import java.util.Map; | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| /** | ||||
|  * 第三方授权拓展 request 工厂类 | ||||
|  * TODO @timfruit 可以说明下,为啥有了 AuthRequestFactory 类,咱还需要自定义 | ||||
|  * (为使得拓展配置和默认配置齐平,自定义本工厂类) | ||||
|  * | ||||
|  * @author timfruit | ||||
|  * @date 2021-10-31 | ||||
| @@ -70,7 +67,10 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||||
|         } | ||||
|  | ||||
|         // 配置 http config | ||||
|         configureHttpConfig(authExtendSource.name(), config, properties.getHttpConfig()); | ||||
|         Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig", | ||||
|                 String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); | ||||
|         ReflectUtil.invoke(this, method, | ||||
|                 authExtendSource.name(), config, properties.getHttpConfig()); | ||||
|  | ||||
|         switch (authExtendSource) { | ||||
|             case WECHAT_MINI_PROGRAM: | ||||
| @@ -80,31 +80,4 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 配置 http 相关的配置 | ||||
|      * | ||||
|      * @param authSource {@link AuthSource} | ||||
|      * @param authConfig {@link AuthConfig} | ||||
|      */ | ||||
|     protected void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) { | ||||
|         // TODO @timfruit:可以改成反射调用父类的方法。可能有一定的损耗,但是可以忽略不计的 | ||||
|         if (null == httpConfig) { | ||||
|             return; | ||||
|         } | ||||
|         Map<String, JustAuthProperties.JustAuthProxyConfig> proxyConfigMap = httpConfig.getProxy(); | ||||
|         if (CollectionUtils.isEmpty(proxyConfigMap)) { | ||||
|             return; | ||||
|         } | ||||
|         JustAuthProperties.JustAuthProxyConfig proxyConfig = proxyConfigMap.get(authSource); | ||||
|  | ||||
|         if (null == proxyConfig) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         authConfig.setHttpConfig(HttpConfig.builder() | ||||
|                 .timeout(httpConfig.getTimeout()) | ||||
|                 .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort()))) | ||||
|                 .build()); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -2,7 +2,11 @@ package cn.iocoder.yudao.framework.social.core.enums; | ||||
|  | ||||
| import me.zhyd.oauth.config.AuthSource; | ||||
|  | ||||
| // TODO @timfruit:类注释 | ||||
| /** | ||||
|  * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理<br> | ||||
|  * | ||||
|  * 默认配置{@link me.zhyd.oauth.config.AuthDefaultSource} | ||||
|  */ | ||||
| public enum AuthExtendSource implements AuthSource { | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.social.core.request; | ||||
| import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||
| import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; | ||||
| import cn.iocoder.yudao.framework.social.core.model.AuthExtendToken; | ||||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||||
| import lombok.Data; | ||||
| import me.zhyd.oauth.cache.AuthStateCache; | ||||
| import me.zhyd.oauth.config.AuthConfig; | ||||
| @@ -39,7 +40,7 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { | ||||
|         this.checkResponse(accessTokenObject); | ||||
|  | ||||
|         AuthExtendToken token = new AuthExtendToken(); | ||||
|         token.setMiniSessionKey(accessTokenObject.session_key); | ||||
|         token.setMiniSessionKey(accessTokenObject.sessionKey); | ||||
|         token.setOpenId(accessTokenObject.openid); | ||||
|         token.setUnionId(accessTokenObject.unionid); | ||||
|         return token; | ||||
| @@ -86,12 +87,12 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { | ||||
|                 .build(); | ||||
|     } | ||||
|  | ||||
|     // TODO @timfruit:我们要采用驼峰的命名方式。不匹配的,可以通过 jackson 的自定义注解映射 | ||||
|     @Data | ||||
|     private static class CodeSessionResponse { | ||||
|         private int errcode; | ||||
|         private String errmsg; | ||||
|         private String session_key; | ||||
|         @JsonProperty("session_key") | ||||
|         private String sessionKey; | ||||
|         private String openid; | ||||
|         private String unionid; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 timfruit
					timfruit