|
@@ -9,11 +9,13 @@ import cn.com.ctop.toutiao.common.BytedanceInterfaceConstant;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import constant.KuaishouInterfaceConstant;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.modules.ctop.entity.ByteDanceAdvertiser;
|
|
|
import org.jeecg.modules.ctop.entity.CTopOauthToken;
|
|
|
import org.jeecg.modules.ctop.entity.UserAllocation;
|
|
|
import org.jeecg.modules.ctop.mapper.CTopOauthTokenMapper;
|
|
|
import org.jeecg.modules.ctop.mapper.UserAllocationMapper;
|
|
|
import org.jeecg.modules.ctop.service.IBindAccountAuthService;
|
|
|
+import org.jeecg.modules.ctop.service.IByteDanceAdvertiserDataService;
|
|
|
import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -31,7 +33,6 @@ import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
-@RequestMapping("/")
|
|
|
public class CallbackController {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
|
|
|
|
|
@@ -138,6 +139,8 @@ public class CallbackController {
|
|
|
return "auth_fail";
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserDataService advertiserDataService;
|
|
|
public Map<String, Object> getByteDanceAccessToken(String authCode, String state) {
|
|
|
Map<String, Object> param = new HashMap<String, Object>();
|
|
|
param.put("app_id", PropertiesUtils.getValue("bytedance_config", "bytedance_appid"));
|
|
@@ -158,47 +161,54 @@ public class CallbackController {
|
|
|
if (null == code || code != 0) {
|
|
|
logger.info("获取token失败,state:{},message:{}", state, message);
|
|
|
throw new Exception("token返回码异常");
|
|
|
-
|
|
|
}
|
|
|
+ String advertiser_id = json.getString("advertiserId");
|
|
|
+ String mediaId = json.getString("mediaId"); // 媒体类型: 1 头条 2 快手
|
|
|
+ String realName = json.getString("realName");
|
|
|
+ String departmentId = json.getString("departmentId"); //部门id
|
|
|
+ String distributionName = json.getString("distributionName");//指定分配人姓名
|
|
|
+ String advertiserName = json.getString("advertiser_name"); // 广告主名称
|
|
|
+ String userId = json.getString("userId"); //创建人
|
|
|
+
|
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
|
CTopOauthToken token = new CTopOauthToken(data.getString("advertiser_id"), data);
|
|
|
- if (Check.isNull(token)) {
|
|
|
- String advertiser_id = json.getString("advertiserId");
|
|
|
- String mediaId = json.getString("mediaId"); // 媒体类型: 1 头条 2 快手
|
|
|
- String realName = json.getString("realName");
|
|
|
- String departmentId = json.getString("departmentId"); //部门id
|
|
|
- String distributionName = json.getString("distributionName");//指定分配人姓名
|
|
|
- String advertiserName = json.getString("advertiser_name"); // 广告主名称
|
|
|
- String userId = json.getString("userId"); //创建人
|
|
|
- UserAllocation userAllocation = new UserAllocation();
|
|
|
- userAllocation.setDistributionName(distributionName);
|
|
|
- userAllocation.setUserId(userId);
|
|
|
- userAllocation.setDepartmentId(departmentId);
|
|
|
- userAllocation.setOperationName(realName);
|
|
|
- userAllocation.setAccountId(token.getAccountId());
|
|
|
- userAllocation.setAdvertiserName(advertiserName);
|
|
|
- userAllocation.setMediaId(mediaId);
|
|
|
- userAllocation.setAdvertiserId(advertiser_id);
|
|
|
- allocationMapper.deleteById(userAllocation.getId());
|
|
|
- Map<String, Object> deleteUserMap = new HashMap<>();
|
|
|
- deleteUserMap.put("advertiser_id", advertiser_id);
|
|
|
- deleteUserMap.put("account_id", token.getAccountId());
|
|
|
- allocationMapper.deleteByMap(deleteUserMap);
|
|
|
- int i = allocationMapper.insert(userAllocation);
|
|
|
- if (i > 0) {
|
|
|
- logger.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("advertiser_id", advertiser_id);
|
|
|
+ deleteMap.put("account_id", token.getAccountId());
|
|
|
+ cTopOauthTokenMapper.deleteByMap(deleteMap); //删除 广告主id下的相关授权信息
|
|
|
+ token.setAdvertiserId(advertiser_id);
|
|
|
+ cTopOauthTokenMapper.insert(token);
|
|
|
+ //获取广告主信息
|
|
|
+ Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(token.getAccountId() + "");
|
|
|
+ Boolean getSuccess = (Boolean) advertiserDataMap.get("success");
|
|
|
+ if (null == getSuccess || !getSuccess) {
|
|
|
+ logger.info("获取广告主信息失败,accountId:{},message:{}", token.getAccountId(), (String) advertiserDataMap.get("message"));
|
|
|
+ throw new Exception("获取广告主信息失败");
|
|
|
+ }
|
|
|
+ ByteDanceAdvertiser advertiserData = (ByteDanceAdvertiser) advertiserDataMap.get("data");
|
|
|
+ UserAllocation userAllocation = new UserAllocation();
|
|
|
+ userAllocation.setDistributionName(distributionName);
|
|
|
+ userAllocation.setUserId(userId);
|
|
|
+ userAllocation.setDepartmentId(departmentId);
|
|
|
+ userAllocation.setOperationName(realName);
|
|
|
+ userAllocation.setAccountId(token.getAccountId());
|
|
|
+ userAllocation.setAdvertiserName(advertiserName);
|
|
|
+ userAllocation.setMediaId(mediaId);
|
|
|
+ userAllocation.setAuthName(advertiserData.getName());
|
|
|
+ userAllocation.setAdvertiserId(advertiser_id);
|
|
|
+ allocationMapper.deleteById(userAllocation.getId());
|
|
|
+ Map<String, Object> deleteUserMap = new HashMap<>();
|
|
|
+ deleteUserMap.put("advertiser_id", advertiser_id);
|
|
|
+ deleteUserMap.put("account_id", token.getAccountId());
|
|
|
+ allocationMapper.deleteByMap(deleteUserMap);
|
|
|
+ int i = allocationMapper.insert(userAllocation);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
|
|
|
|
|
|
- }
|
|
|
- Map<String, Object> deleteMap = new HashMap<>();
|
|
|
- deleteMap.put("advertiser_id", advertiser_id);
|
|
|
- deleteMap.put("account_id", token.getAccountId());
|
|
|
- cTopOauthTokenMapper.deleteByMap(deleteMap); //删除 广告主id下的相关授权信息
|
|
|
- token.setAdvertiserId(advertiser_id);
|
|
|
- cTopOauthTokenMapper.insert(token);
|
|
|
- bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiser_id); //账号绑定
|
|
|
- returnMap.put("code", 0);
|
|
|
- returnMap.put("desc", "success");
|
|
|
}
|
|
|
+ bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiser_id); //账号绑定
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("desc", "success");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
returnMap.put("code", -1);
|