Commit 4cebe4af1424b11ec6c959c5562673ca4a60c4a8
1 parent
d591e9a0
reactor:使用 justauth 官方 1.16.7
Showing
17 changed files
with
419 additions
and
52 deletions
yudao-dependencies/pom.xml
| @@ -72,7 +72,8 @@ | @@ -72,7 +72,8 @@ | ||
| 72 | <commons-io.version>2.17.0</commons-io.version> | 72 | <commons-io.version>2.17.0</commons-io.version> |
| 73 | <commons-compress.version>1.27.1</commons-compress.version> | 73 | <commons-compress.version>1.27.1</commons-compress.version> |
| 74 | <awssdk.version>2.30.14</awssdk.version> | 74 | <awssdk.version>2.30.14</awssdk.version> |
| 75 | - <justauth.version>2.0.5</justauth.version> | 75 | + <justauth.version>1.16.7</justauth.version> |
| 76 | + <justauth-starter.version>1.4.0</justauth-starter.version> | ||
| 76 | <jimureport.version>1.8.1</jimureport.version> | 77 | <jimureport.version>1.8.1</jimureport.version> |
| 77 | <weixin-java.version>4.7.2.B</weixin-java.version> | 78 | <weixin-java.version>4.7.2.B</weixin-java.version> |
| 78 | </properties> | 79 | </properties> |
| @@ -559,15 +560,14 @@ | @@ -559,15 +560,14 @@ | ||
| 559 | </dependency> | 560 | </dependency> |
| 560 | 561 | ||
| 561 | <dependency> | 562 | <dependency> |
| 562 | - <groupId>com.xingyuv</groupId> | ||
| 563 | - <artifactId>spring-boot-starter-justauth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> | 563 | + <groupId>me.zhyd.oauth</groupId> |
| 564 | + <artifactId>JustAuth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> | ||
| 564 | <version>${justauth.version}</version> | 565 | <version>${justauth.version}</version> |
| 565 | - <exclusions> | ||
| 566 | - <exclusion> | ||
| 567 | - <groupId>cn.hutool</groupId> | ||
| 568 | - <artifactId>hutool-core</artifactId> | ||
| 569 | - </exclusion> | ||
| 570 | - </exclusions> | 566 | + </dependency> |
| 567 | + <dependency> | ||
| 568 | + <groupId>com.xkcoding.justauth</groupId> | ||
| 569 | + <artifactId>justauth-spring-boot-starter</artifactId> | ||
| 570 | + <version>${justauth-starter.version}</version> | ||
| 571 | </dependency> | 571 | </dependency> |
| 572 | 572 | ||
| 573 | <dependency> | 573 | <dependency> |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
| @@ -135,7 +135,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { | @@ -135,7 +135,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { | ||
| 135 | private Long createPayTransfer(BrokerageWithdrawDO withdraw) { | 135 | private Long createPayTransfer(BrokerageWithdrawDO withdraw) { |
| 136 | // 1.1 获取微信 openid | 136 | // 1.1 获取微信 openid |
| 137 | SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId( | 137 | SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId( |
| 138 | - UserTypeEnum.MEMBER.getValue(), withdraw.getUserId(), SocialTypeEnum.WECHAT_MINI_APP.getType()); | 138 | + UserTypeEnum.MEMBER.getValue(), withdraw.getUserId(), SocialTypeEnum.WECHAT_MINI_PROGRAM.getType()); |
| 139 | // TODO @luchi:这里,需要校验非空。如果空的话,要有业务异常哈; | 139 | // TODO @luchi:这里,需要校验非空。如果空的话,要有业务异常哈; |
| 140 | // 1.2 构建请求 | 140 | // 1.2 构建请求 |
| 141 | PayTransferCreateReqDTO payTransferCreateReqDTO = new PayTransferCreateReqDTO() | 141 | PayTransferCreateReqDTO payTransferCreateReqDTO = new PayTransferCreateReqDTO() |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java
| 1 | package cn.iocoder.yudao.module.member.service.auth; | 1 | package cn.iocoder.yudao.module.member.service.auth; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | -import cn.hutool.core.util.ObjectUtil; | ||
| 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | import cn.iocoder.yudao.framework.common.enums.TerminalEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.TerminalEnum; |
| 7 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| @@ -27,11 +26,11 @@ import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; | @@ -27,11 +26,11 @@ import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; | ||
| 27 | import cn.iocoder.yudao.module.system.enums.oauth2.OAuth2ClientConstants; | 26 | import cn.iocoder.yudao.module.system.enums.oauth2.OAuth2ClientConstants; |
| 28 | import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; | 27 | import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; |
| 29 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 28 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 29 | +import jakarta.annotation.Resource; | ||
| 30 | import lombok.extern.slf4j.Slf4j; | 30 | import lombok.extern.slf4j.Slf4j; |
| 31 | import org.springframework.stereotype.Service; | 31 | import org.springframework.stereotype.Service; |
| 32 | import org.springframework.transaction.annotation.Transactional; | 32 | import org.springframework.transaction.annotation.Transactional; |
| 33 | 33 | ||
| 34 | -import jakarta.annotation.Resource; | ||
| 35 | import java.util.Objects; | 34 | import java.util.Objects; |
| 36 | 35 | ||
| 37 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 36 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -147,7 +146,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { | @@ -147,7 +146,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { | ||
| 147 | 146 | ||
| 148 | // 绑定社交用户 | 147 | // 绑定社交用户 |
| 149 | String openid = socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), | 148 | String openid = socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), |
| 150 | - SocialTypeEnum.WECHAT_MINI_APP.getType(), reqVO.getLoginCode(), reqVO.getState())); | 149 | + SocialTypeEnum.WECHAT_MINI_PROGRAM.getType(), reqVO.getLoginCode(), reqVO.getState())); |
| 151 | 150 | ||
| 152 | // 创建 Token 令牌,记录登录日志 | 151 | // 创建 Token 令牌,记录登录日志 |
| 153 | return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, openid); | 152 | return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, openid); |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/social/SocialTypeEnum.java
| @@ -52,7 +52,7 @@ public enum SocialTypeEnum implements ArrayValuable<Integer> { | @@ -52,7 +52,7 @@ public enum SocialTypeEnum implements ArrayValuable<Integer> { | ||
| 52 | * | 52 | * |
| 53 | * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html">接入文档</a> | 53 | * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html">接入文档</a> |
| 54 | */ | 54 | */ |
| 55 | - WECHAT_MINI_APP(34, "WECHAT_MINI_APP"), | 55 | + WECHAT_MINI_PROGRAM(34, "WECHAT_MINI_PROGRAM"), |
| 56 | ; | 56 | ; |
| 57 | 57 | ||
| 58 | public static final Integer[] ARRAYS = Arrays.stream(values()).map(SocialTypeEnum::getType).toArray(Integer[]::new); | 58 | public static final Integer[] ARRAYS = Arrays.stream(values()).map(SocialTypeEnum::getType).toArray(Integer[]::new); |
yudao-module-system/yudao-module-system-biz/pom.xml
| @@ -97,8 +97,12 @@ | @@ -97,8 +97,12 @@ | ||
| 97 | 97 | ||
| 98 | <!-- 三方云服务相关 --> | 98 | <!-- 三方云服务相关 --> |
| 99 | <dependency> | 99 | <dependency> |
| 100 | - <groupId>com.xingyuv</groupId> | ||
| 101 | - <artifactId>spring-boot-starter-justauth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> | 100 | + <groupId>me.zhyd.oauth</groupId> |
| 101 | + <artifactId>JustAuth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> | ||
| 102 | + </dependency> | ||
| 103 | + <dependency> | ||
| 104 | + <groupId>com.xkcoding.justauth</groupId> | ||
| 105 | + <artifactId>justauth-spring-boot-starter</artifactId> | ||
| 102 | </dependency> | 106 | </dependency> |
| 103 | 107 | ||
| 104 | <dependency> | 108 | <dependency> |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| @@ -84,7 +84,7 @@ public class SocialClientApiImpl implements SocialClientApi { | @@ -84,7 +84,7 @@ public class SocialClientApiImpl implements SocialClientApi { | ||
| 84 | 84 | ||
| 85 | // 2. 获得社交用户 | 85 | // 2. 获得社交用户 |
| 86 | SocialUserRespDTO socialUser = socialUserService.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(), | 86 | SocialUserRespDTO socialUser = socialUserService.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(), |
| 87 | - SocialTypeEnum.WECHAT_MINI_APP.getType()); | 87 | + SocialTypeEnum.WECHAT_MINI_PROGRAM.getType()); |
| 88 | if (StrUtil.isBlankIfStr(socialUser.getOpenid())) { | 88 | if (StrUtil.isBlankIfStr(socialUser.getOpenid())) { |
| 89 | log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO); | 89 | log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO); |
| 90 | return; | 90 | return; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialClientDO.java
| @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | ||
| 7 | import com.baomidou.mybatisplus.annotation.KeySequence; | 7 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 8 | import com.baomidou.mybatisplus.annotation.TableId; | 8 | import com.baomidou.mybatisplus.annotation.TableId; |
| 9 | import com.baomidou.mybatisplus.annotation.TableName; | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| 10 | -import com.xingyuv.jushauth.config.AuthConfig; | ||
| 11 | import lombok.*; | 10 | import lombok.*; |
| 11 | +import me.zhyd.oauth.config.AuthConfig; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 社交客户端 DO | 14 | * 社交客户端 DO |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/justauth/config/YudaoJustAuthConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.framework.justauth.config; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.system.framework.justauth.core.AuthRequestFactory; | ||
| 4 | +import com.xkcoding.justauth.autoconfigure.JustAuthProperties; | ||
| 5 | +import com.xkcoding.justauth.support.cache.RedisStateCache; | ||
| 6 | +import me.zhyd.oauth.cache.AuthStateCache; | ||
| 7 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| 8 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| 9 | +import org.springframework.context.annotation.Bean; | ||
| 10 | +import org.springframework.context.annotation.Configuration; | ||
| 11 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * JustAuth 配置类 TODO 芋艿:等 justauth 1.4.1 版本发布!!! | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@Configuration(proxyBeanMethods = false) | ||
| 19 | +@EnableConfigurationProperties({JustAuthProperties.class}) | ||
| 20 | +public class YudaoJustAuthConfiguration { | ||
| 21 | + | ||
| 22 | + @Bean | ||
| 23 | + @ConditionalOnProperty( | ||
| 24 | + prefix = "justauth", | ||
| 25 | + value = {"enabled"}, | ||
| 26 | + havingValue = "true", | ||
| 27 | + matchIfMissing = true | ||
| 28 | + ) | ||
| 29 | + public AuthRequestFactory authRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { | ||
| 30 | + return new AuthRequestFactory(properties, authStateCache); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Bean | ||
| 34 | + public AuthStateCache authStateCache(RedisTemplate<String, String> justAuthRedisCacheTemplate, | ||
| 35 | + JustAuthProperties justAuthProperties) { | ||
| 36 | + return new RedisStateCache(justAuthRedisCacheTemplate, justAuthProperties.getCache()); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/justauth/core/AuthRequestFactory.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2019-2029, xkcoding & Yangkai.Shen & 沈扬凯 (237497819@qq.com & xkcoding.com). | ||
| 3 | + * <p> | ||
| 4 | + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * <p> | ||
| 8 | + * http://www.gnu.org/licenses/lgpl.html | ||
| 9 | + * <p> | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package cn.iocoder.yudao.module.system.framework.justauth.core; | ||
| 19 | + | ||
| 20 | +import cn.hutool.core.collection.CollUtil; | ||
| 21 | +import cn.hutool.core.util.EnumUtil; | ||
| 22 | +import cn.hutool.core.util.ReflectUtil; | ||
| 23 | +import cn.hutool.core.util.StrUtil; | ||
| 24 | +import com.xkcoding.http.config.HttpConfig; | ||
| 25 | +import com.xkcoding.justauth.autoconfigure.ExtendProperties; | ||
| 26 | +import com.xkcoding.justauth.autoconfigure.JustAuthProperties; | ||
| 27 | +import lombok.RequiredArgsConstructor; | ||
| 28 | +import lombok.extern.slf4j.Slf4j; | ||
| 29 | +import me.zhyd.oauth.cache.AuthStateCache; | ||
| 30 | +import me.zhyd.oauth.config.AuthConfig; | ||
| 31 | +import me.zhyd.oauth.config.AuthDefaultSource; | ||
| 32 | +import me.zhyd.oauth.config.AuthSource; | ||
| 33 | +import me.zhyd.oauth.enums.AuthResponseStatus; | ||
| 34 | +import me.zhyd.oauth.exception.AuthException; | ||
| 35 | +import me.zhyd.oauth.request.*; | ||
| 36 | +import org.springframework.util.CollectionUtils; | ||
| 37 | + | ||
| 38 | +import java.net.InetSocketAddress; | ||
| 39 | +import java.net.Proxy; | ||
| 40 | +import java.util.ArrayList; | ||
| 41 | +import java.util.HashMap; | ||
| 42 | +import java.util.List; | ||
| 43 | +import java.util.Map; | ||
| 44 | +import java.util.stream.Collectors; | ||
| 45 | + | ||
| 46 | +// TODO @芋艿:等官方发布 1.4.1!!! | ||
| 47 | +/** | ||
| 48 | + * <p> | ||
| 49 | + * AuthRequest工厂类 | ||
| 50 | + * </p> | ||
| 51 | + * | ||
| 52 | + * @author yangkai.shen | ||
| 53 | + * @date Created in 2019-07-22 14:21 | ||
| 54 | + */ | ||
| 55 | +@Slf4j | ||
| 56 | +@RequiredArgsConstructor | ||
| 57 | +public class AuthRequestFactory { | ||
| 58 | + private final JustAuthProperties properties; | ||
| 59 | + private final AuthStateCache authStateCache; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 返回当前Oauth列表 | ||
| 63 | + * | ||
| 64 | + * @return Oauth列表 | ||
| 65 | + */ | ||
| 66 | + @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| 67 | + public List<String> oauthList() { | ||
| 68 | + // 默认列表 | ||
| 69 | + List<String> defaultList = new ArrayList<>(properties.getType().keySet()); | ||
| 70 | + // 扩展列表 | ||
| 71 | + List<String> extendList = new ArrayList<>(); | ||
| 72 | + ExtendProperties extend = properties.getExtend(); | ||
| 73 | + if (null != extend) { | ||
| 74 | + Class enumClass = extend.getEnumClass(); | ||
| 75 | + List<String> names = EnumUtil.getNames(enumClass); | ||
| 76 | + // 扩展列表 | ||
| 77 | + extendList = extend.getConfig() | ||
| 78 | + .keySet() | ||
| 79 | + .stream() | ||
| 80 | + .filter(x -> names.contains(x.toUpperCase())) | ||
| 81 | + .map(String::toUpperCase) | ||
| 82 | + .collect(Collectors.toList()); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + // 合并 | ||
| 86 | + return (List<String>) CollUtil.addAll(defaultList, extendList); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 返回AuthRequest对象 | ||
| 91 | + * | ||
| 92 | + * @param source {@link AuthSource} | ||
| 93 | + * @return {@link AuthRequest} | ||
| 94 | + */ | ||
| 95 | + public AuthRequest get(String source) { | ||
| 96 | + if (StrUtil.isBlank(source)) { | ||
| 97 | + throw new AuthException(AuthResponseStatus.NO_AUTH_SOURCE); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + // 获取 JustAuth 中已存在的 | ||
| 101 | + AuthRequest authRequest = getDefaultRequest(source); | ||
| 102 | + | ||
| 103 | + // 如果获取不到则尝试取自定义的 | ||
| 104 | + if (authRequest == null) { | ||
| 105 | + authRequest = getExtendRequest(properties.getExtend().getEnumClass(), source); | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + if (authRequest == null) { | ||
| 109 | + throw new AuthException(AuthResponseStatus.UNSUPPORTED); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + return authRequest; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 获取自定义的 request | ||
| 117 | + * | ||
| 118 | + * @param clazz 枚举类 {@link AuthSource} | ||
| 119 | + * @param source {@link AuthSource} | ||
| 120 | + * @return {@link AuthRequest} | ||
| 121 | + */ | ||
| 122 | + @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| 123 | + private AuthRequest getExtendRequest(Class clazz, String source) { | ||
| 124 | + String upperSource = source.toUpperCase(); | ||
| 125 | + try { | ||
| 126 | + EnumUtil.fromString(clazz, upperSource); | ||
| 127 | + } catch (IllegalArgumentException e) { | ||
| 128 | + // 无自定义匹配 | ||
| 129 | + return null; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + Map<String, ExtendProperties.ExtendRequestConfig> extendConfig = properties.getExtend().getConfig(); | ||
| 133 | + | ||
| 134 | + // key 转大写 | ||
| 135 | + Map<String, ExtendProperties.ExtendRequestConfig> upperConfig = new HashMap<>(6); | ||
| 136 | + extendConfig.forEach((k, v) -> upperConfig.put(k.toUpperCase(), v)); | ||
| 137 | + | ||
| 138 | + ExtendProperties.ExtendRequestConfig extendRequestConfig = upperConfig.get(upperSource); | ||
| 139 | + if (extendRequestConfig != null) { | ||
| 140 | + | ||
| 141 | + // 配置 http config | ||
| 142 | + configureHttpConfig(upperSource, extendRequestConfig, properties.getHttpConfig()); | ||
| 143 | + | ||
| 144 | + Class<? extends AuthRequest> requestClass = extendRequestConfig.getRequestClass(); | ||
| 145 | + | ||
| 146 | + if (requestClass != null) { | ||
| 147 | + // 反射获取 Request 对象,所以必须实现 2 个参数的构造方法 | ||
| 148 | + return ReflectUtil.newInstance(requestClass, (AuthConfig) extendRequestConfig, authStateCache); | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + return null; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 获取默认的 Request | ||
| 158 | + * | ||
| 159 | + * @param source {@link AuthSource} | ||
| 160 | + * @return {@link AuthRequest} | ||
| 161 | + */ | ||
| 162 | + private AuthRequest getDefaultRequest(String source) { | ||
| 163 | + AuthDefaultSource authDefaultSource; | ||
| 164 | + | ||
| 165 | + try { | ||
| 166 | + authDefaultSource = EnumUtil.fromString(AuthDefaultSource.class, source.toUpperCase()); | ||
| 167 | + } catch (IllegalArgumentException e) { | ||
| 168 | + // 无自定义匹配 | ||
| 169 | + return null; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + AuthConfig config = properties.getType().get(authDefaultSource.name()); | ||
| 173 | + // 找不到对应关系,直接返回空 | ||
| 174 | + if (config == null) { | ||
| 175 | + return null; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + // 配置 http config | ||
| 179 | + configureHttpConfig(authDefaultSource.name(), config, properties.getHttpConfig()); | ||
| 180 | + | ||
| 181 | + switch (authDefaultSource) { | ||
| 182 | + case GITHUB: | ||
| 183 | + return new AuthGithubRequest(config, authStateCache); | ||
| 184 | + case WEIBO: | ||
| 185 | + return new AuthWeiboRequest(config, authStateCache); | ||
| 186 | + case GITEE: | ||
| 187 | + return new AuthGiteeRequest(config, authStateCache); | ||
| 188 | + case DINGTALK: | ||
| 189 | + return new AuthDingTalkRequest(config, authStateCache); | ||
| 190 | + case DINGTALK_V2: | ||
| 191 | + return new AuthDingTalkV2Request(config, authStateCache); | ||
| 192 | + case DINGTALK_ACCOUNT: | ||
| 193 | + return new AuthDingTalkAccountRequest(config, authStateCache); | ||
| 194 | + case BAIDU: | ||
| 195 | + return new AuthBaiduRequest(config, authStateCache); | ||
| 196 | + case CSDN: | ||
| 197 | + return new AuthCsdnRequest(config, authStateCache); | ||
| 198 | + case CODING: | ||
| 199 | + return new AuthCodingRequest(config, authStateCache); | ||
| 200 | + case OSCHINA: | ||
| 201 | + return new AuthOschinaRequest(config, authStateCache); | ||
| 202 | + case ALIPAY: | ||
| 203 | + return new AuthAlipayRequest(config, authStateCache); | ||
| 204 | + case QQ: | ||
| 205 | + return new AuthQqRequest(config, authStateCache); | ||
| 206 | + case WECHAT_OPEN: | ||
| 207 | + return new AuthWeChatOpenRequest(config, authStateCache); | ||
| 208 | + case WECHAT_MP: | ||
| 209 | + return new AuthWeChatMpRequest(config, authStateCache); | ||
| 210 | + case TAOBAO: | ||
| 211 | + return new AuthTaobaoRequest(config, authStateCache); | ||
| 212 | + case GOOGLE: | ||
| 213 | + return new AuthGoogleRequest(config, authStateCache); | ||
| 214 | + case FACEBOOK: | ||
| 215 | + return new AuthFacebookRequest(config, authStateCache); | ||
| 216 | + case DOUYIN: | ||
| 217 | + return new AuthDouyinRequest(config, authStateCache); | ||
| 218 | + case LINKEDIN: | ||
| 219 | + return new AuthLinkedinRequest(config, authStateCache); | ||
| 220 | + case MICROSOFT: | ||
| 221 | + return new AuthMicrosoftRequest(config, authStateCache); | ||
| 222 | + case MICROSOFT_CN: | ||
| 223 | + return new AuthMicrosoftCnRequest(config, authStateCache); | ||
| 224 | + | ||
| 225 | + case MI: | ||
| 226 | + return new AuthMiRequest(config, authStateCache); | ||
| 227 | + case TOUTIAO: | ||
| 228 | + return new AuthToutiaoRequest(config, authStateCache); | ||
| 229 | + case TEAMBITION: | ||
| 230 | + return new AuthTeambitionRequest(config, authStateCache); | ||
| 231 | + case RENREN: | ||
| 232 | + return new AuthRenrenRequest(config, authStateCache); | ||
| 233 | + case PINTEREST: | ||
| 234 | + return new AuthPinterestRequest(config, authStateCache); | ||
| 235 | + case STACK_OVERFLOW: | ||
| 236 | + return new AuthStackOverflowRequest(config, authStateCache); | ||
| 237 | + case HUAWEI: | ||
| 238 | + return new AuthHuaweiRequest(config, authStateCache); | ||
| 239 | + case HUAWEI_V3: | ||
| 240 | + return new AuthHuaweiV3Request(config, authStateCache); | ||
| 241 | + case WECHAT_ENTERPRISE: | ||
| 242 | + return new AuthWeChatEnterpriseQrcodeRequest(config, authStateCache); | ||
| 243 | + case WECHAT_ENTERPRISE_V2: | ||
| 244 | + return new AuthWeChatEnterpriseQrcodeV2Request(config, authStateCache); | ||
| 245 | + case WECHAT_ENTERPRISE_QRCODE_THIRD: | ||
| 246 | + return new AuthWeChatEnterpriseThirdQrcodeRequest(config, authStateCache); | ||
| 247 | + case WECHAT_ENTERPRISE_WEB: | ||
| 248 | + return new AuthWeChatEnterpriseWebRequest(config, authStateCache); | ||
| 249 | + case KUJIALE: | ||
| 250 | + return new AuthKujialeRequest(config, authStateCache); | ||
| 251 | + case GITLAB: | ||
| 252 | + return new AuthGitlabRequest(config, authStateCache); | ||
| 253 | + case MEITUAN: | ||
| 254 | + return new AuthMeituanRequest(config, authStateCache); | ||
| 255 | + case ELEME: | ||
| 256 | + return new AuthElemeRequest(config, authStateCache); | ||
| 257 | + case TWITTER: | ||
| 258 | + return new AuthTwitterRequest(config, authStateCache); | ||
| 259 | + case FEISHU: | ||
| 260 | + return new AuthFeishuRequest(config, authStateCache); | ||
| 261 | + case JD: | ||
| 262 | + return new AuthJdRequest(config, authStateCache); | ||
| 263 | + case ALIYUN: | ||
| 264 | + return new AuthAliyunRequest(config, authStateCache); | ||
| 265 | + case XMLY: | ||
| 266 | + return new AuthXmlyRequest(config, authStateCache); | ||
| 267 | + case AMAZON: | ||
| 268 | + return new AuthAmazonRequest(config, authStateCache); | ||
| 269 | + case SLACK: | ||
| 270 | + return new AuthSlackRequest(config, authStateCache); | ||
| 271 | + case LINE: | ||
| 272 | + return new AuthLineRequest(config, authStateCache); | ||
| 273 | + case OKTA: | ||
| 274 | + return new AuthOktaRequest(config, authStateCache); | ||
| 275 | + case PROGINN: | ||
| 276 | + return new AuthProginnRequest(config,authStateCache); | ||
| 277 | + case AFDIAN: | ||
| 278 | + return new AuthAfDianRequest(config,authStateCache); | ||
| 279 | + case APPLE: | ||
| 280 | + return new AuthAppleRequest(config,authStateCache); | ||
| 281 | + case FIGMA: | ||
| 282 | + return new AuthFigmaRequest(config,authStateCache); | ||
| 283 | + case WECHAT_MINI_PROGRAM: | ||
| 284 | + config.setIgnoreCheckRedirectUri(true); | ||
| 285 | + config.setIgnoreCheckState(true); | ||
| 286 | + return new AuthWechatMiniProgramRequest(config, authStateCache); | ||
| 287 | + case QQ_MINI_PROGRAM: | ||
| 288 | + config.setIgnoreCheckRedirectUri(true); | ||
| 289 | + config.setIgnoreCheckState(true); | ||
| 290 | + return new AuthQQMiniProgramRequest(config, authStateCache); | ||
| 291 | + default: | ||
| 292 | + return null; | ||
| 293 | + } | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + /** | ||
| 297 | + * 配置 http 相关的配置 | ||
| 298 | + * | ||
| 299 | + * @param authSource {@link AuthSource} | ||
| 300 | + * @param authConfig {@link AuthConfig} | ||
| 301 | + */ | ||
| 302 | + private void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) { | ||
| 303 | + if (null == httpConfig) { | ||
| 304 | + return; | ||
| 305 | + } | ||
| 306 | + Map<String, JustAuthProperties.JustAuthProxyConfig> proxyConfigMap = httpConfig.getProxy(); | ||
| 307 | + if (CollectionUtils.isEmpty(proxyConfigMap)) { | ||
| 308 | + return; | ||
| 309 | + } | ||
| 310 | + JustAuthProperties.JustAuthProxyConfig proxyConfig = proxyConfigMap.get(authSource); | ||
| 311 | + | ||
| 312 | + if (null == proxyConfig) { | ||
| 313 | + return; | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + authConfig.setHttpConfig(HttpConfig.builder() | ||
| 317 | + .timeout(httpConfig.getTimeout()) | ||
| 318 | + .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort()))) | ||
| 319 | + .build()); | ||
| 320 | + } | ||
| 321 | +} | ||
| 0 | \ No newline at end of file | 322 | \ No newline at end of file |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/justauth/package-info.java
0 → 100644
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
| @@ -8,10 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl | @@ -8,10 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl | ||
| 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| 10 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 10 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 11 | -import com.xingyuv.jushauth.model.AuthUser; | ||
| 12 | import jakarta.validation.Valid; | 11 | import jakarta.validation.Valid; |
| 13 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 12 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 14 | import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | 13 | import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; |
| 14 | +import me.zhyd.oauth.model.AuthUser; | ||
| 15 | 15 | ||
| 16 | import java.util.List; | 16 | import java.util.List; |
| 17 | 17 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| @@ -26,18 +26,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; | @@ -26,18 +26,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; | ||
| 26 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; | 26 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; |
| 27 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; | 27 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| 28 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 28 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 29 | +import cn.iocoder.yudao.module.system.framework.justauth.core.AuthRequestFactory; | ||
| 29 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; | 30 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; |
| 30 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; | 31 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; |
| 31 | import com.google.common.annotations.VisibleForTesting; | 32 | import com.google.common.annotations.VisibleForTesting; |
| 32 | import com.google.common.cache.CacheLoader; | 33 | import com.google.common.cache.CacheLoader; |
| 33 | import com.google.common.cache.LoadingCache; | 34 | import com.google.common.cache.LoadingCache; |
| 34 | -import com.xingyuv.jushauth.config.AuthConfig; | ||
| 35 | -import com.xingyuv.jushauth.model.AuthCallback; | ||
| 36 | -import com.xingyuv.jushauth.model.AuthResponse; | ||
| 37 | -import com.xingyuv.jushauth.model.AuthUser; | ||
| 38 | -import com.xingyuv.jushauth.request.AuthRequest; | ||
| 39 | -import com.xingyuv.jushauth.utils.AuthStateUtils; | ||
| 40 | -import com.xingyuv.justauth.AuthRequestFactory; | ||
| 41 | import jakarta.annotation.Resource; | 35 | import jakarta.annotation.Resource; |
| 42 | import lombok.SneakyThrows; | 36 | import lombok.SneakyThrows; |
| 43 | import lombok.extern.slf4j.Slf4j; | 37 | import lombok.extern.slf4j.Slf4j; |
| @@ -48,6 +42,12 @@ import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; | @@ -48,6 +42,12 @@ import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; | ||
| 48 | import me.chanjar.weixin.mp.api.WxMpService; | 42 | import me.chanjar.weixin.mp.api.WxMpService; |
| 49 | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | 43 | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
| 50 | import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; | 44 | import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; |
| 45 | +import me.zhyd.oauth.config.AuthConfig; | ||
| 46 | +import me.zhyd.oauth.model.AuthCallback; | ||
| 47 | +import me.zhyd.oauth.model.AuthResponse; | ||
| 48 | +import me.zhyd.oauth.model.AuthUser; | ||
| 49 | +import me.zhyd.oauth.request.AuthRequest; | ||
| 50 | +import me.zhyd.oauth.utils.AuthStateUtils; | ||
| 51 | import org.springframework.beans.factory.annotation.Value; | 51 | import org.springframework.beans.factory.annotation.Value; |
| 52 | import org.springframework.cache.annotation.Cacheable; | 52 | import org.springframework.cache.annotation.Cacheable; |
| 53 | import org.springframework.data.redis.core.StringRedisTemplate; | 53 | import org.springframework.data.redis.core.StringRedisTemplate; |
| @@ -337,7 +337,7 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -337,7 +337,7 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 337 | WxMaService getWxMaService(Integer userType) { | 337 | WxMaService getWxMaService(Integer userType) { |
| 338 | // 第一步,查询 DB 的配置项,获得对应的 WxMaService 对象 | 338 | // 第一步,查询 DB 的配置项,获得对应的 WxMaService 对象 |
| 339 | SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType( | 339 | SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType( |
| 340 | - SocialTypeEnum.WECHAT_MINI_APP.getType(), userType); | 340 | + SocialTypeEnum.WECHAT_MINI_PROGRAM.getType(), userType); |
| 341 | if (client != null && Objects.equals(client.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | 341 | if (client != null && Objects.equals(client.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { |
| 342 | return wxMaServiceCache.getUnchecked(client.getClientId() + ":" + client.getClientSecret()); | 342 | return wxMaServiceCache.getUnchecked(client.getClientId() + ":" + client.getClientSecret()); |
| 343 | } | 343 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
| @@ -6,21 +6,20 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; | @@ -6,21 +6,20 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 8 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | 8 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; |
| 9 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | ||
| 10 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; |
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; |
| 12 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; |
| 13 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; |
| 14 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper; | 13 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper; |
| 15 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 14 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 16 | -import com.xingyuv.jushauth.model.AuthUser; | 15 | +import jakarta.annotation.Resource; |
| 16 | +import jakarta.validation.constraints.NotNull; | ||
| 17 | import lombok.extern.slf4j.Slf4j; | 17 | import lombok.extern.slf4j.Slf4j; |
| 18 | +import me.zhyd.oauth.model.AuthUser; | ||
| 18 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 20 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 21 | 22 | ||
| 22 | -import jakarta.annotation.Resource; | ||
| 23 | -import jakarta.validation.constraints.NotNull; | ||
| 24 | import java.util.Collections; | 23 | import java.util.Collections; |
| 25 | import java.util.List; | 24 | import java.util.List; |
| 26 | 25 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java
| @@ -13,26 +13,25 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl | @@ -13,26 +13,25 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl | ||
| 13 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| 14 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; | 14 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; |
| 15 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 15 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 16 | +import cn.iocoder.yudao.module.system.framework.justauth.core.AuthRequestFactory; | ||
| 16 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; | 17 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; |
| 17 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; | 18 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; |
| 18 | -import com.xingyuv.jushauth.config.AuthConfig; | ||
| 19 | -import com.xingyuv.jushauth.model.AuthResponse; | ||
| 20 | -import com.xingyuv.jushauth.model.AuthUser; | ||
| 21 | -import com.xingyuv.jushauth.request.AuthDefaultRequest; | ||
| 22 | -import com.xingyuv.jushauth.request.AuthRequest; | ||
| 23 | -import com.xingyuv.jushauth.utils.AuthStateUtils; | ||
| 24 | -import com.xingyuv.justauth.AuthRequestFactory; | 19 | +import jakarta.annotation.Resource; |
| 25 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 20 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 26 | import me.chanjar.weixin.common.error.WxErrorException; | 21 | import me.chanjar.weixin.common.error.WxErrorException; |
| 27 | import me.chanjar.weixin.mp.api.WxMpService; | 22 | import me.chanjar.weixin.mp.api.WxMpService; |
| 23 | +import me.zhyd.oauth.config.AuthConfig; | ||
| 24 | +import me.zhyd.oauth.model.AuthResponse; | ||
| 25 | +import me.zhyd.oauth.model.AuthUser; | ||
| 26 | +import me.zhyd.oauth.request.AuthDefaultRequest; | ||
| 27 | +import me.zhyd.oauth.request.AuthRequest; | ||
| 28 | +import me.zhyd.oauth.utils.AuthStateUtils; | ||
| 28 | import org.junit.jupiter.api.Test; | 29 | import org.junit.jupiter.api.Test; |
| 29 | import org.mockito.MockedStatic; | 30 | import org.mockito.MockedStatic; |
| 30 | import org.springframework.boot.test.mock.mockito.MockBean; | 31 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 31 | import org.springframework.context.annotation.Import; | 32 | import org.springframework.context.annotation.Import; |
| 32 | import org.springframework.data.redis.core.StringRedisTemplate; | 33 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 33 | 34 | ||
| 34 | -import jakarta.annotation.Resource; | ||
| 35 | - | ||
| 36 | import static cn.hutool.core.util.RandomUtil.randomEle; | 35 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 37 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 36 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 38 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 37 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| @@ -103,7 +102,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | @@ -103,7 +102,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | ||
| 103 | when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest); | 102 | when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest); |
| 104 | // mock 方法(AuthResponse) | 103 | // mock 方法(AuthResponse) |
| 105 | AuthUser authUser = randomPojo(AuthUser.class); | 104 | AuthUser authUser = randomPojo(AuthUser.class); |
| 106 | - AuthResponse<?> authResponse = new AuthResponse<>(2000, null, authUser); | 105 | + AuthResponse<AuthUser> authResponse = new AuthResponse<>(2000, null, authUser); |
| 107 | when(authRequest.login(argThat(authCallback -> { | 106 | when(authRequest.login(argThat(authCallback -> { |
| 108 | assertEquals(code, authCallback.getCode()); | 107 | assertEquals(code, authCallback.getCode()); |
| 109 | assertEquals(state, authCallback.getState()); | 108 | assertEquals(state, authCallback.getState()); |
| @@ -127,7 +126,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | @@ -127,7 +126,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | ||
| 127 | AuthRequest authRequest = mock(AuthRequest.class); | 126 | AuthRequest authRequest = mock(AuthRequest.class); |
| 128 | when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest); | 127 | when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest); |
| 129 | // mock 方法(AuthResponse) | 128 | // mock 方法(AuthResponse) |
| 130 | - AuthResponse<?> authResponse = new AuthResponse<>(0, "模拟失败", null); | 129 | + AuthResponse<AuthUser> authResponse = new AuthResponse<>(0, "模拟失败", null); |
| 131 | when(authRequest.login(argThat(authCallback -> { | 130 | when(authRequest.login(argThat(authCallback -> { |
| 132 | assertEquals(code, authCallback.getCode()); | 131 | assertEquals(code, authCallback.getCode()); |
| 133 | assertEquals(state, authCallback.getState()); | 132 | assertEquals(state, authCallback.getState()); |
| @@ -317,7 +316,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | @@ -317,7 +316,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | ||
| 317 | Integer userType = randomPojo(UserTypeEnum.class).getValue(); | 316 | Integer userType = randomPojo(UserTypeEnum.class).getValue(); |
| 318 | // mock 数据 | 317 | // mock 数据 |
| 319 | SocialClientDO client = randomPojo(SocialClientDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()) | 318 | SocialClientDO client = randomPojo(SocialClientDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()) |
| 320 | - .setUserType(userType).setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType())); | 319 | + .setUserType(userType).setSocialType(SocialTypeEnum.WECHAT_MINI_PROGRAM.getType())); |
| 321 | socialClientMapper.insert(client); | 320 | socialClientMapper.insert(client); |
| 322 | 321 | ||
| 323 | // 调用 | 322 | // 调用 |
| @@ -332,7 +331,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | @@ -332,7 +331,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | ||
| 332 | Integer userType = randomPojo(UserTypeEnum.class).getValue(); | 331 | Integer userType = randomPojo(UserTypeEnum.class).getValue(); |
| 333 | // mock 数据 | 332 | // mock 数据 |
| 334 | SocialClientDO client = randomPojo(SocialClientDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()) | 333 | SocialClientDO client = randomPojo(SocialClientDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()) |
| 335 | - .setUserType(userType).setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType())); | 334 | + .setUserType(userType).setSocialType(SocialTypeEnum.WECHAT_MINI_PROGRAM.getType())); |
| 336 | socialClientMapper.insert(client); | 335 | socialClientMapper.insert(client); |
| 337 | // mock 方法 | 336 | // mock 方法 |
| 338 | WxMaProperties.ConfigStorage configStorage = mock(WxMaProperties.ConfigStorage.class); | 337 | WxMaProperties.ConfigStorage configStorage = mock(WxMaProperties.ConfigStorage.class); |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java
| @@ -11,12 +11,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | @@ -11,12 +11,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | ||
| 11 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; | 11 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; |
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper; |
| 13 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 13 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 14 | -import com.xingyuv.jushauth.model.AuthUser; | 14 | +import jakarta.annotation.Resource; |
| 15 | +import me.zhyd.oauth.model.AuthUser; | ||
| 15 | import org.junit.jupiter.api.Test; | 16 | import org.junit.jupiter.api.Test; |
| 16 | import org.springframework.boot.test.mock.mockito.MockBean; | 17 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 17 | import org.springframework.context.annotation.Import; | 18 | import org.springframework.context.annotation.Import; |
| 18 | 19 | ||
| 19 | -import jakarta.annotation.Resource; | ||
| 20 | import java.util.List; | 20 | import java.util.List; |
| 21 | 21 | ||
| 22 | import static cn.hutool.core.util.RandomUtil.randomEle; | 22 | import static cn.hutool.core.util.RandomUtil.randomEle; |
yudao-server/src/main/resources/application-dev.yaml
| @@ -186,7 +186,7 @@ justauth: | @@ -186,7 +186,7 @@ justauth: | ||
| 186 | agent-id: 1000004 | 186 | agent-id: 1000004 |
| 187 | ignore-check-redirect-uri: true | 187 | ignore-check-redirect-uri: true |
| 188 | # noinspection SpringBootApplicationYaml | 188 | # noinspection SpringBootApplicationYaml |
| 189 | - WECHAT_MINI_APP: # 微信小程序 | 189 | + WECHAT_MINI_PROGRAM: # 微信小程序 |
| 190 | client-id: ${wx.miniapp.appid} | 190 | client-id: ${wx.miniapp.appid} |
| 191 | client-secret: ${wx.miniapp.secret} | 191 | client-secret: ${wx.miniapp.secret} |
| 192 | ignore-check-redirect-uri: true | 192 | ignore-check-redirect-uri: true |
yudao-server/src/main/resources/application-local.yaml
| @@ -209,10 +209,10 @@ wx: | @@ -209,10 +209,10 @@ wx: | ||
| 209 | # secret: 333ae72f41552af1e998fe1f54e1584a | 209 | # secret: 333ae72f41552af1e998fe1f54e1584a |
| 210 | # appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 | 210 | # appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 |
| 211 | # secret: 6f270509224a7ae1296bbf1c8cb97aed | 211 | # secret: 6f270509224a7ae1296bbf1c8cb97aed |
| 212 | -# appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的) | ||
| 213 | -# secret: 4a1a04e07f6a4a0751b39c3064a92c8b | ||
| 214 | - appid: wx66186af0759f47c9 # 测试号(puhui 提供的) | ||
| 215 | - secret: 3218bcbd112cbc614c7264ceb20144ac | 212 | + appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的) |
| 213 | + secret: 4a1a04e07f6a4a0751b39c3064a92c8b | ||
| 214 | +# appid: wx66186af0759f47c9 # 测试号(puhui 提供的) | ||
| 215 | +# secret: 3218bcbd112cbc614c7264ceb20144ac | ||
| 216 | config-storage: | 216 | config-storage: |
| 217 | type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 | 217 | type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 |
| 218 | key-prefix: wa # Redis Key 的前缀 | 218 | key-prefix: wa # Redis Key 的前缀 |
| @@ -252,7 +252,7 @@ justauth: | @@ -252,7 +252,7 @@ justauth: | ||
| 252 | agent-id: 1000004 | 252 | agent-id: 1000004 |
| 253 | ignore-check-redirect-uri: true | 253 | ignore-check-redirect-uri: true |
| 254 | # noinspection SpringBootApplicationYaml | 254 | # noinspection SpringBootApplicationYaml |
| 255 | - WECHAT_MINI_APP: # 微信小程序 | 255 | + WECHAT_MINI_PROGRAM: # 微信小程序 |
| 256 | client-id: ${wx.miniapp.appid} | 256 | client-id: ${wx.miniapp.appid} |
| 257 | client-secret: ${wx.miniapp.secret} | 257 | client-secret: ${wx.miniapp.secret} |
| 258 | ignore-check-redirect-uri: true | 258 | ignore-check-redirect-uri: true |