|
@@ -5,9 +5,8 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
@@ -23,6 +22,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
|
|
|
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
|
|
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
|
|
|
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
import com.google.common.cache.CacheLoader;
|
|
|
import com.google.common.cache.LoadingCache;
|
|
|
import com.xingyuv.jushauth.config.AuthConfig;
|
|
@@ -44,8 +44,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.Duration;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -224,7 +222,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|
|
return service.getUserService().getPhoneNoInfo(phoneCode);
|
|
|
} catch (WxErrorException e) {
|
|
|
log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e);
|
|
|
- throw exception(SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
|
|
|
+ throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -270,6 +268,9 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|
|
|
|
|
@Override
|
|
|
public Long createSocialClient(SocialClientCreateReqVO createReqVO) {
|
|
|
+ // 校验重复
|
|
|
+ validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType());
|
|
|
+
|
|
|
// 插入
|
|
|
SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO);
|
|
|
socialClientMapper.insert(socialClient);
|
|
@@ -281,6 +282,9 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|
|
public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateSocialClientExists(updateReqVO.getId());
|
|
|
+ // 校验重复
|
|
|
+ validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType());
|
|
|
+
|
|
|
// 更新
|
|
|
SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO);
|
|
|
socialClientMapper.updateById(updateObj);
|
|
@@ -300,17 +304,31 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public SocialClientDO getSocialClient(Long id) {
|
|
|
- return socialClientMapper.selectById(id);
|
|
|
+ /**
|
|
|
+ * 校验社交应用是否重复,需要保证 userType + socialType 唯一
|
|
|
+ *
|
|
|
+ * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求
|
|
|
+ *
|
|
|
+ * @param id 编号
|
|
|
+ * @param userType 用户类型
|
|
|
+ * @param socialType 社交类型
|
|
|
+ */
|
|
|
+ @VisibleForTesting
|
|
|
+ private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) {
|
|
|
+ SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType(
|
|
|
+ socialType, userType);
|
|
|
+ if (client == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == null // 新增时,说明重复
|
|
|
+ || ObjUtil.notEqual(id, client.getId())) { // 更新时,如果 id 不一致,说明重复
|
|
|
+ throw exception(SOCIAL_CLIENT_UNIQUE);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SocialClientDO> getSocialClientList(Collection<Long> ids) {
|
|
|
- if (CollUtil.isEmpty(ids)) {
|
|
|
- return ListUtil.empty();
|
|
|
- }
|
|
|
- return socialClientMapper.selectBatchIds(ids);
|
|
|
+ public SocialClientDO getSocialClient(Long id) {
|
|
|
+ return socialClientMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|