|
@@ -6,15 +6,20 @@ import cn.kdan.pdf.backend.core.model.Members;
|
|
|
import cn.kdan.pdf.backend.core.model.SocialAccounts;
|
|
|
import cn.kdan.pdf.backend.core.model.SocialAccountsExample;
|
|
|
import cn.kdan.pdf.backend.core.params.BindAccountParam;
|
|
|
+import cn.kdan.pdf.backend.core.pojo.app.SocialAccountVo;
|
|
|
import cn.kdan.pdf.backend.core.pojo.third.Tencent;
|
|
|
import cn.kdan.pdf.backend.core.pojo.third.Wechat;
|
|
|
import cn.kdan.pdf.backend.core.service.SocialAccountService;
|
|
|
import cn.kdan.pdf.backend.core.utils.TencentUtils;
|
|
|
import cn.kdan.pdf.backend.core.utils.WechatUtils;
|
|
|
+import exception.BackendRuntimeException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import utils.CommonUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
@@ -70,18 +75,25 @@ public class SocialAccountServiceImpl implements SocialAccountService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String bindSocialAccount(Members member, BindAccountParam param) {
|
|
|
+ public String bindSocialAccount(Members member, BindAccountParam param, SocialAccountVo socialAccountVo) {
|
|
|
String accountId = "";
|
|
|
String accessToken = param.getAccessToken();
|
|
|
String openid = param.getOpenid();
|
|
|
String provider = param.getProvider();
|
|
|
+ socialAccountVo.setProvider(provider);
|
|
|
if(ProviderEnum.TENCENT.getName().equals(provider)){
|
|
|
Tencent userInfo = TencentUtils.getUserInfo(accessToken);
|
|
|
String unionId = userInfo.getUnionId();
|
|
|
+ if(StringUtils.isEmpty(unionId)){
|
|
|
+ log.info("未找到第三方账号,accessToken:{},openid:{}",accessToken,openid);
|
|
|
+ throw new BackendRuntimeException("未找到第三方账号");
|
|
|
+ }
|
|
|
accountId = unionId;
|
|
|
SocialAccounts socialAccount = selectByAccountId(unionId);
|
|
|
//看看有没有该账号,没有就新增一条,有就更新用户id
|
|
|
if(ObjectUtils.isEmpty(socialAccount)){
|
|
|
+ socialAccount = new SocialAccounts();
|
|
|
+ socialAccount.setId(CommonUtils.generateId());
|
|
|
socialAccount.setAccountId(unionId);
|
|
|
socialAccount.setMemberId(member.getId());
|
|
|
socialAccount.setName(userInfo.getNickname());
|
|
@@ -92,12 +104,19 @@ public class SocialAccountServiceImpl implements SocialAccountService {
|
|
|
socialAccount.setMemberId(member.getId());
|
|
|
updateSocialAccount(socialAccount);
|
|
|
}
|
|
|
+ BeanUtils.copyProperties(socialAccount,socialAccountVo);
|
|
|
}else{
|
|
|
Wechat userInfo = WechatUtils.getUserInfo(openid, accessToken);
|
|
|
String unionId = userInfo.getUnionId();
|
|
|
+ if(StringUtils.isEmpty(unionId)){
|
|
|
+ log.info("未找到第三方账号,accessToken:{},openid:{}",accessToken,openid);
|
|
|
+ throw new BackendRuntimeException("未找到第三方账号");
|
|
|
+ }
|
|
|
accountId = unionId;
|
|
|
SocialAccounts socialAccount = selectByAccountId(unionId);
|
|
|
if(ObjectUtils.isEmpty(socialAccount)){
|
|
|
+ socialAccount = new SocialAccounts();
|
|
|
+ socialAccount.setId(CommonUtils.generateId());
|
|
|
socialAccount.setAvatar(userInfo.getHeadImgUrl());
|
|
|
socialAccount.setAccountId(unionId);
|
|
|
socialAccount.setProvider(ProviderEnum.getCodeByName(provider));
|
|
@@ -108,6 +127,7 @@ public class SocialAccountServiceImpl implements SocialAccountService {
|
|
|
socialAccount.setMemberId(member.getId());
|
|
|
updateSocialAccount(socialAccount);
|
|
|
}
|
|
|
+ BeanUtils.copyProperties(socialAccount,socialAccountVo);
|
|
|
}
|
|
|
return accountId;
|
|
|
}
|