Ver código fonte

V1.1.3 授权整合

yumeng 4 anos atrás
pai
commit
e071b2871b
19 arquivos alterados com 300 adições e 83 exclusões
  1. 1 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountAuthController.java
  2. 9 10
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java
  3. 126 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  4. 31 2
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  5. 7 9
      module-common/src/main/java/cn/com/ctop/common/module/controller/OauthConfigController.java
  6. 1 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/CtopOauthToken.java
  7. 11 6
      module-common/src/main/java/cn/com/ctop/common/module/entity/OauthConfig.java
  8. 8 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/OauthConfigMapper.java
  9. 2 1
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml
  10. 14 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/OauthConfigMapper.xml
  11. 4 1
      module-common/src/main/java/cn/com/ctop/common/module/service/IBindAccountAuthService.java
  12. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/ICtopOauthTokenService.java
  13. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IOauthConfigService.java
  14. 21 15
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java
  15. 4 10
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java
  16. 33 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/OauthConfigServiceImpl.java
  17. 9 1
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/RefreshTokenServiceImpl.java
  18. 3 12
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  19. 10 10
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 1 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountAuthController.java

@@ -54,10 +54,8 @@ public class BindAccountAuthController {
             }
 
             String authorizationType = json.getString("authorizationType");
-            // 0 三方代理商 1 本代理商
-            Integer agentType = json.getInteger("agentType");
             if ("kuaishou".equals(authorizationType)) {
-                codeUrl = bindAccountAuthService.getKuaishouCodeUrl(json.toJSONString(), agentType);
+                codeUrl = bindAccountAuthService.getKuaishouCodeUrl(json);
             }
             if ("bytedance".equals(authorizationType)) {
                 codeUrl = bindAccountAuthService.getByteDanceCodeUrl(json.toJSONString());

+ 9 - 10
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -119,8 +119,9 @@ public class CallbackController {
             log.info("快手授权返回信息:{}", json);
             log.info("快手授权返回oauthCode:{}", authCode);
             Integer agentType = json.getInteger("agentType");
+            Long appId = json.getLong("appId");
             if (StringUtils.isNotBlank(authCode)) {
-                KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode, agentType);
+                KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode, appId);
                 if (accessToken.getCode() != 0) {
                     throw new Exception("快手回调token返回错误");
                 }
@@ -131,11 +132,14 @@ public class CallbackController {
                         return "授权绑定失败!";
                     }
 
+                    Map<String, Object> advertiseBaseInfoMap = kuaishouInterfaceService.advertiserInfo(accountId, token.getAccessToken());
+                    if ((Integer) advertiseBaseInfoMap.get("code") != 0) {
+                        return "授权绑定失败,失败原因:" + advertiseBaseInfoMap.get("message");
+                    }
                     String advertiserId = json.getString("advertiserId");
                     //指定分配人姓名
                     String userName = json.getString("userName");
-                    // 广告主名称
-                    String advertiserName = json.getString("advertiser_name");
+
                     // 媒体类型: 1 头条 2 快手
                     String mediaId = json.getString("mediaId");
                     //创建人
@@ -147,6 +151,7 @@ public class CallbackController {
 
                     CtopOauthToken topOauthToken = new CtopOauthToken();
                     topOauthToken.setId(String.valueOf(accountId));
+                    topOauthToken.setAppId(json.getLong("appId"));
                     topOauthToken.setAccountId(accountId);
                     topOauthToken.setMediaId("2");
                     topOauthToken.setAdvertiserId(advertiserId);
@@ -162,8 +167,6 @@ public class CallbackController {
                     topOauthToken.setRefreshTokenExpiresIn(refreshTokenExpireInDate);
                     topOauthToken.setUpdateTime(new Date());
                     ctopOauthTokenService.saveOrUpdate(topOauthToken);
-
-
                     QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
                     userAllocationQueryWrapper.eq("account_id", accountId);
                     userAllocationQueryWrapper.eq("media_id", 2);
@@ -179,10 +182,7 @@ public class CallbackController {
                     userAllocation.setAdvertiserId(advertiserId);
                     userAllocation.setSystemType(systemType);
                     // 获取快手昵称
-                    Map<String, Object> advertiseBaseInfoMap = kuaishouInterfaceService.advertiserInfo(accountId, token.getAccessToken());
-                    if ((Integer) advertiseBaseInfoMap.get("code") == 0) {
-                        userAllocation.setAuthName((String) advertiseBaseInfoMap.get("userName"));
-                    }
+                    userAllocation.setAuthName((String) advertiseBaseInfoMap.get("userName"));
                     userAllocation.setMediaId(mediaId);
                     userAllocation.setAccountId(accountId);
                     userAllocation.setProjectId(projectId);
@@ -199,7 +199,6 @@ public class CallbackController {
                     if (i > 0) {
                         log.info("同步分配用户表完成,task_id:{},accountId:{}", state, accountId);
                     }
-
                     //账号绑定
                     bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
                     Thread t = new Thread() {

+ 126 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.*;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.common.module.vo.ResFileDTO;
@@ -11,6 +12,8 @@ import cn.com.ctop.crawler.modules.douyin.service.DouyinMusicService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
+import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
+import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.material.service.IBytedanceEffectVideoInfoService;
@@ -29,11 +32,15 @@ import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -102,6 +109,123 @@ public class TestController {
     private IBytedanceAccountReportTaskRecordService reportTaskRecordService;
     @Resource
     private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
+    @Autowired
+    private ICtopOauthTokenService ctopOauthTokenService;
+
+    @Autowired
+    private IBindAccountAuthService bindAccountAuthService;
+    @Autowired
+    private UserAllocationMapper allocationMapper;
+
+    @GetMapping("/testKuaishou")
+    public String kuaishouCallback( @RequestParam("auth_code") String authCode, @RequestParam("state") String state) {
+        try {
+            JSONObject json = JSONObject.parseObject(state);
+            if (Check.isNull(json)) {
+                throw new Exception("回调信息为空");
+            }
+            log.info("快手授权返回信息:{}", json);
+            log.info("快手授权返回oauthCode:{}", authCode);
+            Integer agentType = json.getInteger("agentType");
+            Long appId = json.getLong("appId");
+            if (org.apache.commons.lang.StringUtils.isNotBlank(authCode)) {
+                KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode, appId);
+                if (accessToken.getCode() != 0) {
+                    throw new Exception("快手回调token返回错误");
+                }
+                KuaishouAccessToken token = accessToken.getData();
+                if (token != null) {
+                    Long accountId = token.getAccountId();
+                    if (Check.isNull(accountId)) {
+                        return "授权绑定失败!";
+                    }
+                    Map<String, Object> advertiseBaseInfoMap = kuaishouInterfaceService.advertiserInfo(accountId, token.getAccessToken());
+                    if ((Integer) advertiseBaseInfoMap.get("code") != 0) {
+                        return "授权绑定失败,失败原因:" + advertiseBaseInfoMap.get("message");
+                    }
+                    String advertiserId = json.getString("advertiserId");
+                    //指定分配人姓名
+                    String userName = json.getString("userName");
+                    // 媒体类型: 1 头条 2 快手
+                    String mediaId = json.getString("mediaId");
+                    //创建人
+                    String userId = json.getString("userId");
+                    Long projectId = json.getLong("projectId");
+                    BigDecimal warningProportion = json.getBigDecimal("WarningProportion");
+                    BigDecimal warningAmount = json.getBigDecimal("WarningAmount");
+                    String systemType = json.getString("systemType");
+                    CtopOauthToken topOauthToken = new CtopOauthToken();
+                    topOauthToken.setId(String.valueOf(accountId));
+                    topOauthToken.setAppId(json.getLong("appId"));
+                    topOauthToken.setAccountId(accountId);
+                    topOauthToken.setMediaId("2");
+                    topOauthToken.setAdvertiserId(advertiserId);
+                    topOauthToken.setAgentType(agentType);
+                    topOauthToken.setAccessToken(token.getAccessToken());
+                    long accessTokenExpireIn = token.getAccessTokenExpiresIn() * 1000L;
+                    long now = System.currentTimeMillis();
+                    Date accessTokenExpireInDate = new Date(now + accessTokenExpireIn);
+                    topOauthToken.setAccessTokenExpiresIn(accessTokenExpireInDate);
+                    topOauthToken.setRefreshToken(token.getRefreshToken());
+                    long refreshTokenExpireIn = token.getRefreshTokenExpiresIn() * 1000L;
+                    Date refreshTokenExpireInDate = new Date(now + refreshTokenExpireIn);
+                    topOauthToken.setRefreshTokenExpiresIn(refreshTokenExpireInDate);
+                    topOauthToken.setUpdateTime(new Date());
+                    ctopOauthTokenService.saveOrUpdate(topOauthToken);
+                    QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+                    userAllocationQueryWrapper.eq("account_id", accountId);
+                    userAllocationQueryWrapper.eq("media_id", 2);
+                    userAllocationQueryWrapper.orderByDesc("create_time");
+                    userAllocationQueryWrapper.last("limit 1");
+                    UserAllocation checkUserAllocation = allocationMapper.selectOne(userAllocationQueryWrapper);
+                    if (!Check.isNull(checkUserAllocation)) {
+                        return "授权失败,该账号已被:" + checkUserAllocation.getUserName() + " 绑定!";
+                    }
+                    UserAllocation userAllocation = new UserAllocation();
+                    userAllocation.setUserName(userName);
+                    userAllocation.setUserId(userId);
+                    userAllocation.setAdvertiserId(advertiserId);
+                    userAllocation.setSystemType(systemType);
+                    // 获取快手昵称
+                    userAllocation.setAuthName((String) advertiseBaseInfoMap.get("userName"));
+                    userAllocation.setMediaId(mediaId);
+                    userAllocation.setAccountId(accountId);
+                    userAllocation.setProjectId(projectId);
+                    userAllocation.setWarningProportion(warningProportion);
+                    userAllocation.setWarningAmount(warningAmount);
+                    userAllocation.setCreateTime(new Date());
+                    userAllocation.setUpdateTime(new Date());
+                    allocationMapper.deleteById(userAllocation.getId());
+                    Map<String, Object> deleteUserMap = new HashMap<>();
+                    deleteUserMap.put("advertiser_id", advertiserId);
+                    deleteUserMap.put("account_id", accountId);
+                    allocationMapper.deleteByMap(deleteUserMap);
+                    int i = allocationMapper.insert(userAllocation);
+                    if (i > 0) {
+                        log.info("同步分配用户表完成,task_id:{},accountId:{}", state, accountId);
+                    }
+                    //账号绑定
+                    bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
+                    Thread t = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                kuaishouInterfaceService.loadKuaishouDataSingle(topOauthToken);
+                            } catch (ParseException e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    };
+                    t.start();
+                }
+                return "授权绑定成功";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "授权绑定失败!";
+    }
+
 
     @GetMapping("/getBytedanceMatReport")
     public Map<String,Object>getData(){
@@ -710,11 +834,11 @@ public class TestController {
     }
 
 
-    @GetMapping(value = "/getToken")
+   /* @GetMapping(value = "/getToken")
     public String getToken(Long accountId, String token, String refreshToken, Integer agentType) {
         oauthTokenService.getKuaiShouRefreshToken(accountId, token, refreshToken, agentType);
         return "Success";
-    }
+    }*/
 
 
     @GetMapping(value = "/getAccountReport")

+ 31 - 2
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -3,8 +3,10 @@ package org.jeecg;
 import cn.com.ctop.common.module.entity.BindAccountLogin;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
@@ -25,6 +27,7 @@ import cn.com.ctop.toutiao.modules.report.entity.BytedanceAccountReportTaskRecor
 import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMaterialDailyMapper;
 import cn.com.ctop.toutiao.modules.report.service.*;
 import com.alibaba.fastjson.JSONArray;
+import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.catalina.User;
 import org.jeecg.common.util.DateUtils;
@@ -70,12 +73,38 @@ public class SampleTest {
     private IBindAccountLoginService bindAccountLoginService;
     @Autowired
     private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
+    @Autowired
+    private IOauthConfigService configService;
+    @Autowired
+    private CtopOauthTokenMapper oauthTokenMapper;
 
 
     @Test
     public void loadBytedanceCreativeData() throws ParseException {
 
-        List<KuaiShouVideoGet> KuaiShouVideoGets = videoGetService.selectPhotoIdsByAccountId(9743746L);
+
+        List<CtopOauthToken> oauthTokens = oauthTokenMapper.selectKuaiShouTokens(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+        if (!Check.isNull(oauthTokens)) {
+            Map<Long, String> configMap = configService.getConfigMapByMediaId(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT);
+            for (CtopOauthToken oauthToken : oauthTokens) {
+                XxlJobHelper.log("刷新token,accountId:{}", oauthToken.getAccountId());
+                //快手
+                if (CtopAdConstant.PLATFORM_TYPE_KUAISHOU.equals(oauthToken.getMediaId().trim())) {
+                    String secret = configMap.get(oauthToken.getAppId());
+                    System.err.println(secret);
+                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getAccessToken(), oauthToken.getRefreshToken(), oauthToken.getAppId(), secret);
+                }
+            }
+        } else {
+            XxlJobHelper.log("----------------------刷新token获取数据返回结果为空----------------------------------");
+        }
+
+
+      /*  Map<Long, String> configMap = configService.getConfigMapByMediaId(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT);
+        System.err.println(configMap);*/
+
+
+      /*  List<KuaiShouVideoGet> KuaiShouVideoGets = videoGetService.selectPhotoIdsByAccountId(9743746L);
         if (!Check.isNull(KuaiShouVideoGets)) {
             JSONArray dateList = new JSONArray();
             JSONArray photoIds = new JSONArray();
@@ -96,7 +125,7 @@ public class SampleTest {
             }
             dateList.add(photoIds);
             kuaishouVideoRelateCreativesService.videoRelateCreatives(9743746L, dateList, statdateMap);
-        }
+        }*/
     }
 
     @Test

+ 7 - 9
module-common/src/main/java/cn/com/ctop/common/module/controller/OauthConfigController.java

@@ -5,8 +5,6 @@ import cn.com.ctop.common.module.entity.OauthConfig;
 import cn.com.ctop.common.module.service.IOauthConfigService;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -60,14 +58,14 @@ public class OauthConfigController {
     @AutoLog(value = "授权配置信息-分页列表查询")
     @ApiOperation(value = "授权配置信息-分页列表查询", notes = "授权配置信息-分页列表查询")
     @GetMapping(value = "/list")
-    public Result<IPage<OauthConfig>> queryPageList(OauthConfig oauthConfig,
-                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-                                                    HttpServletRequest req) {
-        Result<IPage<OauthConfig>> result = new Result<>();
+    public Result<List<OauthConfig>> queryPageList(OauthConfig oauthConfig,
+                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                   HttpServletRequest req) {
+        Result<List<OauthConfig>> result = new Result<>();
         QueryWrapper<OauthConfig> queryWrapper = QueryGenerator.initQueryWrapper(oauthConfig, req.getParameterMap());
-        Page<OauthConfig> page = new Page<OauthConfig>(pageNo, pageSize);
-        IPage<OauthConfig> pageList = oauthConfigService.page(page, queryWrapper);
+        queryWrapper.orderByAsc("rank");
+        List<OauthConfig> pageList = oauthConfigService.list(queryWrapper);
         result.setSuccess(true);
         result.setResult(pageList);
         return result;

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/CtopOauthToken.java

@@ -76,6 +76,7 @@ public class CtopOauthToken {
 
 
     private Integer agentType;
+    private Long appId;
 
     /**
      * 刷新令牌有效期

+ 11 - 6
module-common/src/main/java/cn/com/ctop/common/module/entity/OauthConfig.java

@@ -34,6 +34,9 @@ public class OauthConfig {
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "主键ID")
     private Long id;
+
+
+    private Integer mediaId;
     /**
      * 代理商名称
      */
@@ -58,18 +61,20 @@ public class OauthConfig {
     @Excel(name = "回调地址", width = 15)
     @ApiModelProperty(value = "回调地址")
     private String redirectUri;
-    /**
-     * 所用公司名称
-     */
-    @Excel(name = "所用公司名称", width = 15)
-    @ApiModelProperty(value = "所用公司名称")
-    private String companyName;
+
+
+    private Integer status;
+
+    private Integer oauthType;
+
     /**
      * 排序
      */
     @Excel(name = "排序", width = 15)
     @ApiModelProperty(value = "排序")
     private Integer rank;
+
+    String callbackUrl;
     /**
      * 创建时间
      */

+ 8 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/OauthConfigMapper.java

@@ -1,7 +1,12 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.OauthConfig;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 授权配置信息
@@ -12,4 +17,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface OauthConfigMapper extends BaseMapper<OauthConfig> {
 
+    Map<Long, String> getConfigMapByMediaId(@Param("mediaId") int mediaId);
+
+    List<JSONObject> getListByMediaId(@Param("mediaId") int mediaId);
 }

+ 2 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml

@@ -12,12 +12,13 @@
         <result column="access_token_expires_in" property="accessTokenExpiresIn" jdbcType="TIMESTAMP"/>
         <result column="refresh_token_expires_in" property="refreshTokenExpiresIn" jdbcType="TIMESTAMP"/>
         <result column="agent_type" property="agentType" jdbcType="INTEGER"/>
+        <result column="app_id" property="appId" jdbcType="INTEGER"/>
         <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
         <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
     </resultMap>
 
     <sql id="Base_Column_List">
-        id,media_id,advertiser_id,account_id,access_token,refresh_token,access_token_expires_in,refresh_token_expires_in,agent_type,create_time,update_time
+        id,media_id,advertiser_id,account_id,access_token,refresh_token,access_token_expires_in,refresh_token_expires_in,agent_type,app_id,create_time,update_time
    </sql>
 
     <select id="selectByteDanceTokens" resultMap="BaseResultMap">

+ 14 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/OauthConfigMapper.xml

@@ -2,4 +2,18 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.common.module.mapper.OauthConfigMapper">
 
+    <select id="getConfigMapByMediaId" resultType="map">
+       select
+       app_id,
+       secret
+       from ctop_oauth_config
+       where media_id = #{mediaId}
+    </select>
+    <select id="getListByMediaId" resultType="com.alibaba.fastjson.JSONObject">
+       select
+       app_id,
+       secret
+       from ctop_oauth_config
+       where media_id = #{mediaId}
+    </select>
 </mapper>

+ 4 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/IBindAccountAuthService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.BindAccountAuth;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.io.UnsupportedEncodingException;
@@ -20,10 +21,11 @@ public interface IBindAccountAuthService extends IService<BindAccountAuth> {
      * @return
      * @throws UnsupportedEncodingException
      */
-    String getKuaishouCodeUrl(String state,Integer  agentType ) throws UnsupportedEncodingException;
+    String getKuaishouCodeUrl(JSONObject state) throws UnsupportedEncodingException;
 
     /**
      * 获取头条url
+     *
      * @param state
      * @return
      * @throws UnsupportedEncodingException
@@ -32,6 +34,7 @@ public interface IBindAccountAuthService extends IService<BindAccountAuth> {
 
     /**
      * 绑定账号
+     *
      * @param accountId
      * @param type
      * @param state

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/ICtopOauthTokenService.java

@@ -20,7 +20,7 @@ public interface ICtopOauthTokenService extends IService<CtopOauthToken> {
 
     Map<String, Object> getByteDanceAccessToken(CtopOauthToken token);
 
-    void getKuaiShouRefreshToken(Long accountId, String token, String refreshToken, Integer agentType);
+    void getKuaiShouRefreshToken(Long accountId, String token, String refreshToken, Long appId, String secret);
 
     List<CtopOauthToken> getTokenListByType(String platformTypeBytedance);
 

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IOauthConfigService.java

@@ -3,6 +3,8 @@ package cn.com.ctop.common.module.service;
 import cn.com.ctop.common.module.entity.OauthConfig;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Map;
+
 /**
  * @Description: 授权配置信息
  * @Author: jeecg-boot
@@ -11,4 +13,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IOauthConfigService extends IService<OauthConfig> {
 
+    OauthConfig getConfigByAppId(Long appId);
+
+    Map<Long, String> getConfigMapByMediaId(int mediaId);
 }

+ 21 - 15
module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java

@@ -1,11 +1,14 @@
 package cn.com.ctop.common.module.service.impl;
 
 import cn.com.ctop.common.module.entity.BindAccountAuth;
+import cn.com.ctop.common.module.entity.OauthConfig;
 import cn.com.ctop.common.module.mapper.BindAccountAuthMapper;
 import cn.com.ctop.common.module.service.IBindAccountAuthService;
+import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,23 +67,26 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
     }
 
 
+    @Autowired
+    private IOauthConfigService oauthConfigService;
+
     @Override
-    public String getKuaishouCodeUrl(String state, Integer agentType) throws UnsupportedEncodingException {
+    public String getKuaishouCodeUrl(JSONObject state) throws UnsupportedEncodingException {
         StringBuffer sb = new StringBuffer();
-        if (agentType == 1) {
-            sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
-                    .append(KuaishouInterfaceConstant.AUTH_PATH)
-                    .append("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_appid"))
-                    .append("&state=" + URLEncoder.encode(URLEncoder.encode(state)))
-                    .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
-                    .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_callback_url"), "UTF-8"));
-        } else if (agentType == 0) {
-            sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
-                    .append(KuaishouInterfaceConstant.AUTH_PATH)
-                    .append ("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_third_appid"))
-                    .append("&state=" + URLEncoder.encode(URLEncoder.encode(state)))
-                    .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
-                    .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_third_callback_url"), "UTF-8"));
+        Long id = state.getLong("id");
+
+        OauthConfig config = oauthConfigService.getById(id);
+        state.put("appId", config.getAppId());
+        state.put("callbackUrl", config.getCallbackUrl());
+        sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
+                .append(KuaishouInterfaceConstant.AUTH_PATH)
+                .append("?app_id=" + config.getAppId())
+                .append("&state=" + URLEncoder.encode(URLEncoder.encode(state.toJSONString())))
+                .append("&redirect_uri=" + URLEncoder.encode(config.getRedirectUri(), "UTF-8"));
+        if (config.getOauthType() != 1) {
+            sb.append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D");
+        } else {
+            sb.append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22ad_manage%22%5D");
         }
         return sb.toString();
     }

+ 4 - 10
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java

@@ -121,20 +121,14 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
      * @return
      */
     @Override
-    public void getKuaiShouRefreshToken(Long accountId, String token, String refreshToken, Integer agentType) {
+    public void getKuaiShouRefreshToken(Long accountId, String token, String refreshToken, Long appId, String secret) {
         log.info("快手刷新token入参,accountId:{},token:{},refreshToken:{}", accountId, token, refreshToken);
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + "/rest/openapi/oauth2/authorize/refresh_token";
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", " application/json");
         Map<String, Object> param = new HashMap<>();
-        if (agentType == 1) {
-            param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
-            param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
-        } else if (agentType == 0) {
-            param.put("app_id", PropertiesUtils.getConfig("kuaishou_third_appid"));
-            param.put("secret", PropertiesUtils.getConfig("kuaishou_third_secret"));
-        }
-
+        param.put("app_id", appId);
+        param.put("secret", secret);
         param.put("refresh_token", refreshToken);
         try {
             CtopOauthToken oauthToken = ctopOauthTokenMapper.selectByAccountId(accountId);
@@ -142,7 +136,7 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
                 log.error("查询token信息返回结果为空,accountId:{}", accountId);
                 return;
             }
-            XxlJobHelper.log("刷新token,入參:{},token:{}", param,headers);
+            XxlJobHelper.log("刷新token,入參:{},token:{}", param, headers);
             String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             log.info("快手刷新token返回结果:{}", refreshToken);

+ 33 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/OauthConfigServiceImpl.java

@@ -3,9 +3,17 @@ package cn.com.ctop.common.module.service.impl;
 import cn.com.ctop.common.module.entity.OauthConfig;
 import cn.com.ctop.common.module.mapper.OauthConfigMapper;
 import cn.com.ctop.common.module.service.IOauthConfigService;
+import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 授权配置信息
  *
@@ -15,5 +23,30 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class OauthConfigServiceImpl extends ServiceImpl<OauthConfigMapper, OauthConfig> implements IOauthConfigService {
+    @Autowired
+    private OauthConfigMapper configMapper;
+
+    @Override
+    public OauthConfig getConfigByAppId(Long appId) {
+        QueryWrapper<OauthConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("app_id", appId);
+        OauthConfig config = this.getOne(queryWrapper);
+        return config;
+    }
+
+    @Override
+    public Map<Long, String> getConfigMapByMediaId(int mediaId) {
+
+        Map<Long, String> map = new HashMap<>();
+        List<JSONObject> list = configMapper.getListByMediaId(mediaId);
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject jsonObject = list.get(i);
+                map.put(jsonObject.getLong("app_id"), jsonObject.getString("secret"));
+            }
+
+        }
 
+        return map;
+    }
 }

+ 9 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/RefreshTokenServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.entity.OauthAgentToken;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IOauthAgentTokenService;
+import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.service.IRefreshTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Service
@@ -25,6 +27,8 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
     private ICtopOauthTokenService oauthTokenService;
     @Autowired
     private IOauthAgentTokenService agentTokenService;
+    @Autowired
+    private IOauthConfigService configService;
 
     /**
      * 获取所有token
@@ -33,13 +37,17 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
      */
     @Override
     public void getKuaiShouRefresh() {
+
+
         List<CtopOauthToken> oauthTokens = oauthTokenMapper.selectKuaiShouTokens(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
         if (!Check.isNull(oauthTokens)) {
+            Map<Long, String> configMap = configService.getConfigMapByMediaId(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT);
             for (CtopOauthToken oauthToken : oauthTokens) {
                 XxlJobHelper.log("刷新token,accountId:{}", oauthToken.getAccountId());
                 //快手
                 if (CtopAdConstant.PLATFORM_TYPE_KUAISHOU.equals(oauthToken.getMediaId().trim())) {
-                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getAccessToken(), oauthToken.getRefreshToken(), oauthToken.getAgentType());
+                    String secret = configMap.get(oauthToken.getAppId());
+                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getAccessToken(), oauthToken.getRefreshToken(), oauthToken.getAppId(), secret);
                 }
             }
         } else {

+ 3 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java

@@ -8,7 +8,6 @@ import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
 import cn.com.ctop.kuaishou.modules.report.entity.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.google.gson.JsonArray;
 
 import java.text.ParseException;
 import java.util.Date;
@@ -21,7 +20,7 @@ import java.util.Map;
  */
 public interface IKuaishouInterfaceService {
 
-    KuaishouResultToken getAccessToken(String authCode, Integer agentType);
+    KuaishouResultToken getAccessToken(String authCode, Long appId);
 
 
     /**
@@ -152,7 +151,6 @@ public interface IKuaishouInterfaceService {
     void getCreativeList(CtopOauthToken token, Date startDate, Date endDate);
 
 
-
     /**
      * 根据组id,获取创意列表
      *
@@ -162,7 +160,7 @@ public interface IKuaishouInterfaceService {
      * @param endDate
      * @param timeFilterType
      */
-    JSONArray getCreativeList(CtopOauthToken token, Long unitId, Date startDate, Date endDate,int timeFilterType);
+    JSONArray getCreativeList(CtopOauthToken token, Long unitId, Date startDate, Date endDate, int timeFilterType);
 
 
     /**
@@ -359,7 +357,6 @@ public interface IKuaishouInterfaceService {
     void getCampaignList(CtopOauthToken token, Date startDate, Date endDate);
 
 
-
     /**
      * 获取计划列表,新增一个参数 按创建时间,还是更新时间进行筛选
      *
@@ -381,7 +378,6 @@ public interface IKuaishouInterfaceService {
     void getGroupList(CtopOauthToken token, Date startDate, Date endDate);
 
 
-
     /**
      * 获取指定广告计划下的广告组列表
      *
@@ -391,12 +387,7 @@ public interface IKuaishouInterfaceService {
      * @param endDate
      * @param time_filter_type
      */
-    JSONArray getGroupList(CtopOauthToken token, Long campaignId, Date startDate, Date endDate,int time_filter_type);
-
-
-
-
-
+    JSONArray getGroupList(CtopOauthToken token, Long campaignId, Date startDate, Date endDate, int time_filter_type);
 
 
     /**

+ 10 - 10
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -2,9 +2,11 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.MaterialCutFrame;
+import cn.com.ctop.common.module.entity.OauthConfig;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
+import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
@@ -1870,20 +1872,18 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param authCode
      * @return
      */
+    @Autowired
+    private IOauthConfigService configService;
+
     @Override
-    public KuaishouResultToken getAccessToken(String authCode, Integer agentType) {
+    public KuaishouResultToken getAccessToken(String authCode, Long appId) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AUTH_TOKEN;
         JSONObject requestJson = new JSONObject();
         requestJson.put("auth_code", authCode);
 
-        if (agentType == 1) { // 本代理商开户
-            requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
-            requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
-        } else if (agentType == 0) {
-            requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_third_appid"));
-            requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_third_secret"));
-        }
-
+        OauthConfig config = configService.getConfigByAppId(appId);
+        requestJson.put("app_id", config.getAppId());
+        requestJson.put("secret", config.getSecret());
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", " application/json");
         KuaishouResultToken kuaiShouResult = null;
@@ -2975,7 +2975,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     @Override
                     public void run() {
                         List<MaterialCutFrame> cutFrames = cutFrameService.getListByVideoSignature(md5);
-                        if(null==cutFrames||cutFrames.isEmpty()){
+                        if (null == cutFrames || cutFrames.isEmpty()) {
                             videoGetService.getKeyFrame(token, accountId, md5, String.valueOf(photo_id));
                         }
                     }