Ver código fonte

调整快手

yumeng 5 anos atrás
pai
commit
d274b37a92

+ 2 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/LoadFileUtil.java

@@ -30,6 +30,8 @@ public class LoadFileUtil {
     public static String downLoadFromUrl(String urlStr, String savePath) throws IOException {
         String fileName = AesEncryptUtil.getURLDecoderString(urlStr.substring(urlStr.lastIndexOf("/") + 1));
         URL url = new URL(urlStr);
+
+        System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2,SSLv3");
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         //设置超时间为3秒
         conn.setConnectTimeout(60 * 1000);

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

@@ -69,6 +69,7 @@ public class UserAllocationController {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         QueryWrapper<UserAllocation> queryWrapper = QueryGenerator.initQueryWrapper(userAllocation, req.getParameterMap());
         queryWrapper.eq("user_id", user.getId());
+        queryWrapper.orderByDesc("id");
         Page<UserAllocation> page = new Page<UserAllocation>(pageNo, pageSize);
         IPage<UserAllocation> pageList = userAllocationService.page(page, queryWrapper);
         result.setSuccess(true);

+ 6 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/entity/KuaiShouCreateAppTemplate.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.kuaishou.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -32,7 +33,7 @@ public class KuaiShouCreateAppTemplate {
      */
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
-    private Integer id;
+    private Long id;
     /**
      * app类型 安卓 ios
      */
@@ -91,6 +92,10 @@ public class KuaiShouCreateAppTemplate {
     private Integer uploadType;
 
 
+
+    private Long accountId;
+
+
     /**
      * 登录人id
      */

+ 8 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/entity/KuaiShouImage.java

@@ -33,6 +33,14 @@ public class KuaiShouImage {
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
     private Long id;
+
+    /**
+     * 图片保存本地地址
+     */
+    @Excel(name = "accountId", width = 15)
+    @ApiModelProperty(value = "accountId")
+    private Long accountId;
+
     /**
      * 图片保存本地地址
      */

+ 10 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/entity/KuaiShouVideo.java

@@ -32,7 +32,16 @@ public class KuaiShouVideo {
      */
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
-    private Integer id;
+    private Long id;
+
+
+    /**
+     * accountId
+     */
+    @Excel(name = "accountId", width = 15)
+    @ApiModelProperty(value = "accountId")
+    private Long accountId;
+
     /**
      * 视频保存本地地址
      */

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/service/IKuaiShouImageService.java

@@ -14,7 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaiShouImageService extends IService<KuaiShouImage> {
 
-    void insert(JSONObject requestJson);
+    void insert(JSONObject requestJson) throws Exception;
 
     String localInsert( JSONObject imageJson);
 

+ 43 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/service/impl/KuaiShouCreateAppTemplateServiceImpl.java

@@ -1,12 +1,16 @@
 package org.jeecg.modules.kuaishou.service.impl;
 
 import cn.com.ctop.common.utils.Check;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import constant.KuaishouInterfaceConstant;
+import org.jeecg.modules.ctop.entity.CtopOauthToken;
+import org.jeecg.modules.ctop.service.ICtopOauthTokenService;
 import org.jeecg.modules.kuaishou.entity.KuaiShouCreateAppTemplate;
 import org.jeecg.modules.kuaishou.mapper.KuaiShouCreateAppTemplateMapper;
 import org.jeecg.modules.kuaishou.service.IKuaiShouCreateAppTemplateService;
+import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -23,11 +27,21 @@ import java.util.Map;
 public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCreateAppTemplateMapper, KuaiShouCreateAppTemplate> implements IKuaiShouCreateAppTemplateService {
     @Autowired
     private KuaiShouCreateAppTemplateMapper appTemplateMapper;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IKuaishouInterfaceService interfaceService;
 
     @Override
     public Map<String, Object> insert(KuaiShouCreateAppTemplate appTemplate) {
         Map<String, Object> resultMap = new HashMap<>();
         try {
+            Long accountId = appTemplate.getAccountId();
+            CtopOauthToken cTopOauthToken = oauthTokenService.getOauthTokenByAccountId(String.valueOf(accountId));
+            if (Check.isNull(cTopOauthToken)) {
+                throw new Exception("未获取到token信息");
+            }
+            String accessToken = cTopOauthToken.getAccessToken();
             String loginId = appTemplate.getLoginId();
             String appVersion = appTemplate.getAppVersion();
             QueryWrapper<KuaiShouCreateAppTemplate> queryWrapper = new QueryWrapper<>();
@@ -48,6 +62,35 @@ public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCr
                     appTemplate.setImageUrl(KuaishouInterfaceConstant.HTTPS_PREFIX + appTemplate.getImageUrl());
                 }
                 appTemplateMapper.insert(appTemplate);
+
+              /*  Thread thread = new Thread() {
+                    @Override
+                    public void run() {*/
+                        JSONObject apkJson = new JSONObject();
+                        String platform = appTemplate.getPlatform();
+                        apkJson.put("app_name", appTemplate.getAppName());
+                        apkJson.put("app_version", appTemplate.getAppVersion());
+                        apkJson.put("platform", platform);
+                        if (!Check.isNull(appTemplate.getPackageName())) {
+                            apkJson.put("package_name", appTemplate.getPackageName());
+                        }
+                        if (!Check.isNull(appTemplate.getImageUrl()) && ("1".equals(platform) || "3".equals(platform))) {
+                            Map<String, Object> imageMap = interfaceService.imageUpload(accountId, accessToken, (String) appTemplate.getImageUrl(), 1);
+                            apkJson.put("image_token", imageMap.get("imageToken"));
+                        }
+                        if ("1".equals(platform) && appTemplate.getUploadType() == 1) {
+                            apkJson.put("file", appTemplate.getFile());
+
+                            interfaceService.appCreate(accountId, accessToken, apkJson);
+
+                        } else {
+                            apkJson.put("url", appTemplate.getUrl());
+                            interfaceService.urlAppCreate(accountId, accessToken, apkJson);
+                        }
+                   // }
+
+               /* };
+                thread.start();*/
                 resultMap.put("success", true);
                 resultMap.put("message", "创建应用成功");
                 resultMap.put("code", 0);

+ 30 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/service/impl/KuaiShouImageServiceImpl.java

@@ -6,10 +6,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import constant.KuaishouInterfaceConstant;
 import org.jeecg.common.util.encryption.AesEncryptUtil;
+import org.jeecg.modules.ctop.entity.CtopOauthToken;
+import org.jeecg.modules.ctop.service.ICtopOauthTokenService;
 import org.jeecg.modules.kuaishou.entity.KuaiShouImage;
 import org.jeecg.modules.kuaishou.entity.KuaiShouVideo;
 import org.jeecg.modules.kuaishou.mapper.KuaiShouImageMapper;
 import org.jeecg.modules.kuaishou.service.IKuaiShouImageService;
+import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -29,9 +32,20 @@ public class KuaiShouImageServiceImpl extends ServiceImpl<KuaiShouImageMapper, K
     @Autowired
     private KuaiShouImageMapper imageMapper;
 
+    @Autowired
+    private IKuaishouInterfaceService interfaceService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
     @Override
-    public void insert(JSONObject requestJson) {
+    public void insert(JSONObject requestJson) throws Exception {
         JSONArray imageArr = requestJson.getJSONArray("localImageUrl");
+        Long accountId = requestJson.getLong("accountId");
+        CtopOauthToken cTopOauthToken = oauthTokenService.getOauthTokenByAccountId(String.valueOf(accountId));
+        if (Check.isNull(cTopOauthToken)) {
+            throw new Exception("未获取到token信息");
+        }
+        String accessToken = cTopOauthToken.getAccessToken();
         if (!Check.isNull(imageArr)) {
             for (int i = 0; i < imageArr.size(); i++) {
                 KuaiShouImage image = new KuaiShouImage();
@@ -46,14 +60,25 @@ public class KuaiShouImageServiceImpl extends ServiceImpl<KuaiShouImageMapper, K
                 image.setLoginId(requestJson.getString("loginId"));
                 image.setMaterialType(requestJson.getString("materialType"));
                 image.setPositionType(requestJson.getString("positionType"));
-                image.setLocalUrl(KuaishouInterfaceConstant.HTTPS_PREFIX + imageUrl);
+                image.setAccountId(accountId);
+                String imageUrlStr;
+                if (!imageUrl.contains(KuaishouInterfaceConstant.HTTPS_PREFIX + imageUrl)) {
+                    imageUrlStr = KuaishouInterfaceConstant.HTTPS_PREFIX + imageUrl;
+                } else {
+                    imageUrlStr = imageUrl;
+                }
+                image.setLocalUrl(imageUrlStr);
                 imageMapper.insert(image);
-
+                Thread thread = new Thread() {
+                    @Override
+                    public void run() {
+                        interfaceService.imageUpload(accountId, accessToken, imageUrlStr, 0);
+                    }
+                };
+                thread.start();
             }
-
         }
 
-
     }
 
     @Override

+ 33 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/service/impl/KuaiShouVideoServiceImpl.java

@@ -7,9 +7,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import constant.KuaishouInterfaceConstant;
 import org.jeecg.common.util.encryption.AesEncryptUtil;
+import org.jeecg.modules.ctop.entity.CtopOauthToken;
+import org.jeecg.modules.ctop.service.ICtopOauthTokenService;
 import org.jeecg.modules.kuaishou.entity.KuaiShouVideo;
 import org.jeecg.modules.kuaishou.mapper.KuaiShouVideoMapper;
 import org.jeecg.modules.kuaishou.service.IKuaiShouVideoService;
+import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -23,15 +26,28 @@ import org.springframework.stereotype.Service;
 public class KuaiShouVideoServiceImpl extends ServiceImpl<KuaiShouVideoMapper, KuaiShouVideo> implements IKuaiShouVideoService {
     @Autowired
     private KuaiShouVideoMapper kuaiShouVideoMapper;
+    @Autowired
+    private IKuaishouInterfaceService interfaceService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
 
     @Override
     public void insert(JSONObject requestJson) throws Exception {
         if (Check.isNull(requestJson)) {
             throw new Exception("传递参数不能为空");
         }
+        Long accountId = requestJson.getLong("accountId");
+        CtopOauthToken cTopOauthToken = oauthTokenService.getOauthTokenByAccountId(String.valueOf(accountId));
+        if (Check.isNull(cTopOauthToken)) {
+            throw new Exception("未获取到token信息");
+        }
+        String accessToken = cTopOauthToken.getAccessToken();
+
+
         JSONArray localArr = requestJson.getJSONArray("localUrl");
         if (!Check.isNull(localArr)) {
             for (int i = 0; i < localArr.size(); i++) {
+
                 KuaiShouVideo video = new KuaiShouVideo();
                 video.setVideoDesc(requestJson.getString("videoDesc"));
                 String url = localArr.get(i).toString();
@@ -42,11 +58,26 @@ public class KuaiShouVideoServiceImpl extends ServiceImpl<KuaiShouVideoMapper, K
                     fileNameStr = split[0];
                 }
                 video.setLoginId(requestJson.getString("loginId"));
+                video.setAccountId(accountId);
                 video.setVideoName(AesEncryptUtil.getURLDecoderString(fileNameStr));
-                video.setLocalUrl(KuaishouInterfaceConstant.HTTPS_PREFIX + url);
+                String urlStr;
+                if (!url.contains(KuaishouInterfaceConstant.HTTPS_PREFIX)) {
+                    urlStr = KuaishouInterfaceConstant.HTTPS_PREFIX + url;
+                } else {
+                    urlStr = url;
+                }
+                video.setLocalUrl(urlStr);
                 video.setMaterialType(requestJson.getString("materialType"));
                 video.setPositionType(requestJson.getString("positionType"));
                 kuaiShouVideoMapper.insert(video);
+                // 多线程上传文件
+                Thread thread = new Thread() {
+                    @Override
+                    public void run() {
+                        interfaceService.videoUpload(accountId, accessToken, urlStr);
+                    }
+                };
+                thread.start();
             }
         }
 
@@ -73,7 +104,7 @@ public class KuaiShouVideoServiceImpl extends ServiceImpl<KuaiShouVideoMapper, K
                     fileNameStr = split[0];
                 }
 
-                if (!videoUrl.contains("https:")) {
+                if (!videoUrl.contains(KuaishouInterfaceConstant.HTTPS_PREFIX)) {
                     String url = KuaishouInterfaceConstant.HTTPS_PREFIX + videoUrl;
                     video.setLocalUrl(url);
                 } else {

+ 8 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/service/impl/KuaishouInterfaceServiceImpl.java

@@ -744,8 +744,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             logger.info(resultJson.toJSONString());
             if (!Check.isNullMap(resultJson)) {
                 Integer code = resultJson.getInteger("code");
-                Integer is_activate = null;
-                Integer is_form_submit = null;
+                Integer is_activate;
+                Integer is_form_submit;
                 if (code == 0) {
                     Map<String, Object> deleteMap = new HashMap<>();
                     deleteMap.put("account_id", advertiserId);
@@ -774,6 +774,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             }
 
                         }
+                        resultMap.put("isActivate", is_activate);
+                        resultMap.put("isFormSubmit", is_form_submit);
                         resultMap.put("deepConversionTypes", conversionTypeArr);
                         resultMap.put("code", 0);
                         resultMap.put("success", true);
@@ -891,6 +893,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     @Override
     public Map<String, Object> videoUpload(Long advertiserId, String accessToken, String videoUrl) {
+        logger.info("开始上传视频");
         Map<String, Object> returnMap = new HashMap<>();
         try {
             QueryWrapper<KuaiShouVideoUpload> wrapper = new QueryWrapper<>();
@@ -1154,6 +1157,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     @Override
     public Map<String, Object> imageUpload(Long advertiserId, String accessToken, String filePath, Integer type) {
+        logger.info("上传快手图片");
         Map<String, Object> returnMap = new HashMap<>();
         try {
             QueryWrapper<KuaiShouImageUploand> queryWrapper = new QueryWrapper<>();
@@ -1251,6 +1255,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     @Override
     public Map<String, Object> appCreate(Long advertiserId, String accessToken, JSONObject requestJson) {
+        logger.info("快手创建file应用");
         Map<String, Object> returnMap = new HashMap<>();
         try {
             String filePath = requestJson.getString("file");
@@ -1338,6 +1343,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     @Override
     public Map<String, Object> urlAppCreate(Long accountId, String accessToken, JSONObject apkJson) {
+        logger.info("快手创建url应用");
         Map<String, Object> returnMap = new HashMap<>();
         try {
             String appUrl = apkJson.getString("url");

+ 2 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/shiro/authc/ShiroRealm.java

@@ -102,7 +102,8 @@ public class ShiroRealm extends AuthorizingRealm {
         // 解密获得username,用于和数据库进行对比
         String username = JwtUtil.getUsername(token);
         if (username == null) {
-            throw new AuthenticationException("token非法无效!");
+            log.error("token非法无效!");
+            // throw new AuthenticationException("token非法无效!");
         }
 
         // 查询用户信息