syh 5 rokov pred
rodič
commit
23ed9a03f6
17 zmenil súbory, kde vykonal 942 pridanie a 1187 odobranie
  1. 7 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdCoverController.java
  2. 3 9
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AuthController.java
  3. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AuthTaskController.java
  4. 7 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountAuthController.java
  5. 6 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountLoginController.java
  6. 3 82
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceAdvertiserPostController.java
  7. 0 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceTemplateController.java
  8. 10 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java
  9. 0 144
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/crawler/WxAccountCrawler.java
  10. 7 6
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceAdvertiserDataServiceImpl.java
  11. 0 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCampaignTemplateServiceImpl.java
  12. 0 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/kuaishou/controller/KuaiShouGroupCreateLogController.java
  13. 6 0
      module-common/pom.xml
  14. 0 20
      module-common/src/main/java/cn/com/ctop/common/utils/AliyunOCRUtils.java
  15. 429 429
      module-common/src/main/java/cn/com/ctop/common/utils/ImageUtils.java
  16. 62 62
      module-common/src/main/java/cn/com/ctop/common/utils/WebMasterUtils.java
  17. 401 426
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/KuaishouTest.java

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

@@ -150,6 +150,13 @@ public class AdCoverController {
         return result;
     }
 
+    /**
+     * TODO 需要确认是否可以删除
+     *
+     * @param photoId
+     * @param userId
+     * @return
+     */
     @ResponseBody
     @RequestMapping(value="/adlist", method = RequestMethod.GET)
     public Result<List<AppAd>> getAdList(@RequestParam(name="photoId") String photoId, @RequestParam(name="userId") Long userId){

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

@@ -15,6 +15,9 @@ import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 import java.util.UUID;
 
+/**
+ * TODO 可以删除
+ */
 @Controller
 @RequestMapping("/auth")
 public class AuthController {
@@ -49,13 +52,4 @@ public class AuthController {
 
         return "auth_error";
     }
-
-
-    @GetMapping("bytedance/refreshtoken")
-    @ResponseBody
-    public Map<String, Object> refreshToken(String accountId) {
-        return null;
-    }
-
-
 }

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

@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 
  /**
+  * TODO 相关AuthTask 需要删除
  * @Description: 关联用户分配
  * @Author: jeecg-boot
  * @Date:   2019-07-31

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

@@ -49,6 +49,12 @@ public class BindAccountAuthController {
     @Autowired
     private IBindAccountAuthService bindAccountAuthService;
 
+    /**
+     * 参数校验
+     *
+     * @param json
+     * @return
+     */
     @PostMapping(value = "/authorization")
     public Result<IPage<BindAccountAuth>> authorization(@RequestBody JSONObject json) {
         Result<IPage<BindAccountAuth>> result = new Result<IPage<BindAccountAuth>>();
@@ -56,7 +62,7 @@ public class BindAccountAuthController {
         try {
             String advertiserId = json.getString("advertiserId");
             if (Check.isNull(advertiserId)) {
-                System.err.println("advertiserId不能为空");
+//                System.err.println("advertiserId不能为空");
                 result.setSuccess(false);
                 return result;
             }

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

@@ -57,7 +57,12 @@ public class BindAccountLoginController {
     @Autowired
     private UserAllocationMapper userAllocationMapper;
 
-
+    /**
+     * TODO  需要爬虫校验用户名密码正确性
+     *
+     * @param json
+     * @return
+     */
     @PostMapping(value = "/login")
     public Result<IPage<BindAccountLogin>> login(@RequestBody JSONObject json) {
         Result<IPage<BindAccountLogin>> result = new Result<IPage<BindAccountLogin>>();

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

@@ -121,85 +121,6 @@ public class ByteDanceAdvertiserPostController {
         return advertiserDataService.getAdvertiserCreativeMaterial(accountId, creativeIds);
     }
 
-    /**
-     * 11:创建广告组信息
-     * @param accountId 本平台广告主id
-     */
-//    @RequestMapping("/advertiser/campaign/create")
-//    public Map<String, Object> advertiserCampaignCreate(String accountId, String campaignName, String budgetMode, Integer budget, String landingType) {
-//        return advertiserDataService.advertiserCampaignCreate(accountId, campaignName, budgetMode, budget, landingType);
-//    }
-
-    /**
-     * 11:创建广告计划信息
-     */
-    @RequestMapping("/advertiser/plan/create")
-    public Map<String, Object> advertiserPlanCreate() {
-        String accountId = "e9ca23d68d884d4ebb19d07889727dae";
-        Long campaignId = 1640397758132260L;
-        JSONObject data = new JSONObject();
-        data.put("campaign_id", campaignId);
-        data.put("delivery_range", "DEFAULT");
-        data.put("budget_mode", "BUDGET_MODE_DAY");
-        data.put("budget", 2000);//需要大于bid
-        data.put("bid", 100);
-        data.put("start_time", "2019-07-30 01:00");
-        data.put("end_time", "2019-07-31 01:00");
-        data.put("pricing", "PRICING_CPM");
-        data.put("schedule_type", "SCHEDULE_FROM_NOW");
-        data.put("flow_control_mode", "FLOW_CONTROL_MODE_FAST");
-        data.put("name", "测试计划名称");
-        data.put("external_url", "https://lordsmobile.176.com/download.php");
-        data.put("download_url", "https://lordsmobile.176.com/download.php");
-        data.put("download_type", "DOWNLOAD_URL");//坑
-        data.put("package", "com.igg.android.lordsmobile_cn");//坑
-        data.put("app_type", "APP_ANDROID");//坑
-        return advertisePlanService.advertiserPlanCreate(new CTopOauthToken(), campaignId, data.toJSONString());
-    }
-
-    /**
-     * 11:创建广告创意信息
-     *
-     * @param accountId 本平台广告主id
-     */
-    @RequestMapping("/advertiser/creative/create")
-    public Map<String, Object> advertiserCreativeCreate(String accountId, Long campaignId, String dataString) {
-        String getAccountId = "e9ca23d68d884d4ebb19d07889727dae";
-        Long adId = 1640445647618076L;
-        JSONObject data = new JSONObject();
-        JSONArray jsonArray = new JSONArray();
-        jsonArray.add("INVENTORY_FEED");
-        jsonArray.add("INVENTORY_VIDEO_FEED");
-        jsonArray.add("INVENTORY_HOTSOON_FEED");
-        jsonArray.add("INVENTORY_AWEME_FEED");
-        jsonArray.add("INVENTORY_UNION_SLOT");
-        data.put("inventory_type", jsonArray);
-
-        data.put("ad_id", adId);
-
-        data.put("app_name", "asdasd");
-
-        data.put("web_url", "http://www.chengzijianzhan.com/tetris/page/1593177139994627/");
-        JSONArray keywords = new JSONArray();
-        keywords.add("游戏");
-        keywords.add("娱乐");
-        keywords.add("塔防");
-        keywords.add("养成");
-        data.put("ad_keywords", keywords);
-        JSONArray creatives = new JSONArray();
-        JSONObject creative = new JSONObject();
-
-        creative.put("image_mode", "CREATIVE_IMAGE_MODE_VIDEO_VERTICAL");
-        creative.put("image_id", "71d10006f7067d0be514");
-        creative.put("video_id", "v020334a0000bkvbakj6936tng75j6ag");
-        creative.put("title", "测试标题11");
-        creatives.add(creative);
-        data.put("creatives", creatives);
-        data.put("third_industry_id", 19050501);
-        data.put("title", "测试创意标题123");
-        return creativeService.creativeCreate(getAccountId, adId, data.toJSONString());
-    }
-
     @Autowired
     private IByteDanceCreativeService creativeService;
     /**
@@ -264,7 +185,7 @@ public class ByteDanceAdvertiserPostController {
      * @return
      * @功能:查询字典数据
      */
-    @RequestMapping(value = "audience/list", method = RequestMethod.GET)
+    @RequestMapping(value = "/audience/list", method = RequestMethod.GET)
     public Result<IPage<ByteDanceCustomAudience>> audiencePageList(ByteDanceCustomAudience audience, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                    @RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize, HttpServletRequest req) {
         Result<IPage<ByteDanceCustomAudience>> result = new Result<>();
@@ -294,10 +215,10 @@ public class ByteDanceAdvertiserPostController {
     @RequestMapping(value = "dictitem/list", method = RequestMethod.GET)
     public Result<IPage<SysDictItem>> dictitemPageList(SysDictItem sysDictItem, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
-        Result<IPage<SysDictItem>> result = new Result<IPage<SysDictItem>>();
+        Result<IPage<SysDictItem>> result = new Result<>();
         QueryWrapper<SysDictItem> queryWrapper = QueryGenerator.initQueryWrapper(sysDictItem, req.getParameterMap());
         queryWrapper.orderByAsc("sort_order");
-        Page<SysDictItem> page = new Page<SysDictItem>(pageNo, pageSize);
+        Page<SysDictItem> page = new Page<>(pageNo, pageSize);
         IPage<SysDictItem> pageList = sysDictItemService.page(page, queryWrapper);
         result.setSuccess(true);
         result.setResult(pageList);

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceTemplateController.java


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

@@ -48,6 +48,15 @@ public class CallbackController {
     private UserAllocationMapper allocationMapper;
 
 
+    /**
+     * TODO 授权绑定成功/失败 需要跳转特定页面
+     *
+     * @param request
+     * @param response
+     * @param authCode
+     * @param state
+     * @return
+     */
     @GetMapping("/kuaishou")
     @ResponseBody
     public String kuaishou(HttpServletRequest request,
@@ -163,7 +172,7 @@ public class CallbackController {
             Integer code = resultObject.getInteger("code");
             String message = resultObject.getString("message");
             if (null == code || code != 0) {
-                logger.info("获取token失败,state:{},message:{}", state, message);
+                logger.error("获取token失败,state:{},message:{}", state, message);
                 throw new Exception("token返回码异常");
             }
             String advertiser_id = json.getString("advertiserId");//广告主id

+ 0 - 144
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/crawler/WxAccountCrawler.java

@@ -1,144 +0,0 @@
-//package org.jeecg.modules.ctop.crawler;
-//
-//import cn.edu.hfut.dmic.webcollector.model.CrawlDatum;
-//import cn.edu.hfut.dmic.webcollector.model.CrawlDatums;
-//import cn.edu.hfut.dmic.webcollector.model.Page;
-//import cn.edu.hfut.dmic.webcollector.plugin.berkeley.BreadthCrawler;
-//
-//import cn.edu.hfut.dmic.webcollector.plugin.nextfilter.HashSetNextFilter;
-//import com.alibaba.fastjson.JSONArray;
-//import com.alibaba.fastjson.JSONObject;
-//import org.jsoup.nodes.Element;
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
-//
-//import java.io.*;
-//import java.net.URLEncoder;
-//
-//public class WxAccountCrawler extends BreadthCrawler {
-//    public static final Logger LOG = LoggerFactory.getLogger(WxAccountCrawler.class);
-//
-//    protected String historyKeysPath;
-//    protected BufferedWriter historyKeysWriter;
-//
-//    public WxAccountCrawler(String crawlPath, String historyKeysPath) throws Exception {
-//        super(crawlPath, false);
-//        this.historyKeysPath = historyKeysPath;
-//        LOG.info("initializing history-keys-filter ......");
-//        this.setNextFilter(new HistoryKeysFilter(historyKeysPath));
-//        LOG.info("creating history-keys-writer");
-//        historyKeysWriter = new BufferedWriter(new OutputStreamWriter(
-//                new FileOutputStream(historyKeysPath, true), "utf-8"));
-//
-//    }
-//
-//    @Override
-//    public void visit(Page page, CrawlDatums next) {
-//        String account = page.meta("account");
-//
-//        if (page.matchType("account_search")) {
-//            //对于账号搜索页面
-//
-//            //抽取公众号文章列表页URL
-//            Element accountLinkEle = page.select("p.tit>a").first();
-//            //防止搜索结果为空
-//            if (accountLinkEle == null) {
-//                LOG.info("公众号\"" + account + "\"不存在,请给出准确的公众号名");
-//                return;
-//            }
-//            //防止公众号名错误
-//            String detectedAccount = accountLinkEle.text().trim();
-//            if (!account.equals(detectedAccount)) {
-//                LOG.info("公众号\"" + account + "\"与搜索结果\"" + detectedAccount + "\"名称不符,请给出准确的公众号名");
-//                return;
-//            }
-//            String accountUrl = accountLinkEle.attr("abs:href");
-//            next.add(new CrawlDatum(accountUrl, "article_list").meta("account", account));
-//
-//        } else if (page.matchType("article_list")) {
-//            //对于公众号文章列表页
-//
-//            String prefix = "msgList = ";
-//            String suffix = "seajs.use";
-//            int startIndex = page.html().indexOf(prefix) + prefix.length();
-//            int endIndex = page.html().indexOf(suffix);
-//            String jsonStr = page.html().substring(startIndex, endIndex);
-//            JSONObject json = JSONObject.parseObject(jsonStr);
-//            JSONArray articleJSONArray = json.getJSONArray("list");
-//            for (int i = 0; i < articleJSONArray.size(); i++) {
-//                JSONObject articleJSON = articleJSONArray.getJSONObject(i).getJSONObject("app_msg_ext_info");
-//                String title = articleJSON.getString("title").trim();
-//                String key = account + "_" + title;
-//                String articleUrl = "http://mp.weixin.qq.com" + articleJSON.getString("content_url").replace("&", "&");
-//                next.add(new CrawlDatum(articleUrl, "article").key(key).meta("account", account));
-//            }
-//
-//        } else if (page.matchType("article")) {
-//            //对于文章页
-//            //抽取标题、内容等信息,此处仅print少数信息作为参考
-//            String title = page.select("h2.rich_media_title").first().text().trim();
-//            String date = page.select("em#post-date").first().text().trim();
-//            String content = page.select("div.rich_media_content").first().text().trim();
-//
-//            try {
-//                writeHistoryKey(page.key());
-//                JSONObject articleJSON = new JSONObject();
-//                articleJSON.put("account", account);
-//                articleJSON.put("title", title);
-//                articleJSON.put("date", date);
-//                articleJSON.put("content", content);
-//                System.out.println(articleJSON);
-//            } catch (IOException ex) {
-//                LOG.info("writer exception", ex);
-//            }
-//
-//        }
-//    }
-//
-//    public synchronized void writeHistoryKey(String key) throws IOException {
-//        historyKeysWriter.write(key + "\n");
-//    }
-//
-//    @Override
-//    public void start(int depth) throws Exception {
-//        super.start(depth);
-//        //关闭文件,保存history keys
-//        historyKeysWriter.close();
-//        LOG.info("save history keys");
-//    }
-//
-//    public void addAccount(String account) throws UnsupportedEncodingException {
-//        String seedUrl = "http://weixin.sogou.com/weixin?type=1&"
-//                + "s_from=input&ie=utf8&query=" + URLEncoder.encode(account, "utf-8");
-//        CrawlDatum seed = new CrawlDatum(seedUrl, "account_search").meta("account", account);
-//        addSeed(seed);
-//    }
-//
-//    //该示例读取文件中的key进行文章去重
-//    //线上应用请老老实实用数据库
-//    public class HistoryKeysFilter extends HashSetNextFilter {
-//
-//        //读取历史文章标题,用于去重
-//        public HistoryKeysFilter(String historyKeysPath) throws Exception {
-//            File historyFile = new File(historyKeysPath);
-//            if (historyFile.exists()) {
-//                FileInputStream fis = new FileInputStream(historyKeysPath);
-//                BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "utf-8"));
-//                String line;
-//                while ((line = reader.readLine()) != null) {
-//                    this.add(line);
-//                }
-//                reader.close();
-//            }
-//        }
-//    }
-//
-//    public static void main(String[] args) throws Exception {
-//        WxAccountCrawler crawler = new WxAccountCrawler("crawl_weixin", "wx_history.txt");
-//        crawler.addAccount("机器之心");
-//        crawler.addAccount("ZEALER订阅号");
-//        crawler.setThreads(5);
-//        crawler.start(10);
-//    }
-//
-//}

+ 7 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -37,6 +37,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", cTopOauthToken.getAccessToken());
         TreeMap<String, Object> params = new TreeMap<>();
+        //TODO jsonArray
         params.put("advertiser_ids", "[" + cTopOauthToken.getAccountId() + "]");
         String result = HttpUtils.httpGetRequest(url, headers, params);
         JSONObject jsonObject = JSONObject.parseObject(result);
@@ -59,7 +60,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         for (int i = 0; i < data.size(); i++) {
             JSONObject dataObject = data.getJSONObject(i);
             ByteDanceAdvertiser advertiser = new ByteDanceAdvertiser(dataObject, accountId);
-            //清除清数据,插入新数据
+            //清除清数据,插入新数据 TODO
             advertiserMapper.deleteById(advertiser.getId());
             advertiserMapper.insert(advertiser);
             resultMap.put("data", advertiser);
@@ -98,12 +99,12 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         Integer code = jsonObject.getInteger("code");
 
         if (null == code || !code.equals(0)) {
-            logger.info("获取广告主广告计划信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
+            logger.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             return;
         }
         JSONArray data = jsonObject.getJSONObject("data").getJSONArray("list");
         if (null == data || data.size() <= 0) {
-            logger.info("获取广告主广告计划信息不存在==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
+            logger.error("获取广告计划信息不存在==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             return;
         }
         for (int i = 0; i < data.size(); i++) {
@@ -368,7 +369,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         Integer code = jsonObject.getInteger("code");
 
         if (null == code || !code.equals(0)) {
-            logger.info("广告计划更新状态接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
+            logger.error("广告计划更新状态接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             resultMap.put("code", -1);
             resultMap.put("message", "广告计划更新状态接口异常");
             return resultMap;
@@ -684,12 +685,12 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         Integer code = jsonObject.getInteger("code");
 
         if (null == code || !code.equals(0)) {
-            logger.info("获取广告主广告组信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
+            logger.error("获取广告组信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             return;
         }
         JSONArray data = jsonObject.getJSONObject("data").getJSONArray("list");
         if (null == data || data.size() <= 0) {
-            logger.info("获取广告主广告组信息不存在==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
+            logger.error("获取广告组信息不存在==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             return;
         }
         for (int i = 0; i < data.size(); i++) {

+ 0 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCampaignTemplateServiceImpl.java

@@ -232,12 +232,9 @@ public class ByteDanceCampaignTemplateServiceImpl extends ServiceImpl<ByteDanceC
         String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
         // 构造请求
         HttpPost httpEntity = new HttpPost(url);
-
         httpEntity.setHeader("Access-Token", token);
-
         CloseableHttpResponse response = null;
         CloseableHttpClient client = null;
-
         try {
             client = HttpClientBuilder.create().build();
             httpEntity.setEntity(new StringEntity(data.toJSONString(), ContentType.APPLICATION_JSON));

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

@@ -53,7 +53,6 @@ public class KuaiShouGroupCreateLogController {
 
     @PostMapping(value = "/insert")
     public Map<String, Object> insert(@RequestBody KuaiShouGroupCreateLog groupCreateTemplate) {
-        System.err.println(groupCreateTemplate);
         return kuaiShouGroupCreateLogService.insert(groupCreateTemplate);
     }
 

+ 6 - 0
module-common/pom.xml

@@ -39,6 +39,12 @@
             <version>3.5.0</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>us.codecraft</groupId>
+            <artifactId>webmagic-core</artifactId>
+            <version>0.7.3</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 0 - 20
module-common/src/main/java/cn/com/ctop/common/utils/AliyunOCRUtils.java

@@ -1,20 +0,0 @@
-package cn.com.ctop.common.utils;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class AliyunOCRUtils {
-    private static String host = "https://ocrapi-ecommerce.taobao.com";
-    private static String path = "/ocrservice/ecommerce";
-    private static String appcode = "a62d65f9056f491aa04e2093f85df663";
-
-    public static String getOCRResult(String imageBase64) {
-        Map<String, String> header = new HashMap<String, String>();
-        header.put("Authorization", "APPCODE " + appcode);
-        header.put("Content-Type", "application/json; charset=UTF-8");
-        Map<String, Object> body = new HashMap<String, Object>();
-        body.put("img", "data:image/jpeg;base64," + imageBase64);
-        body.put("prob", false);
-        return HttpUtils.httpPostRequest(host + path, body, header);
-    }
-}

+ 429 - 429
module-common/src/main/java/cn/com/ctop/common/utils/ImageUtils.java

@@ -1,429 +1,429 @@
-package cn.com.ctop.common.utils;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Date;
-import java.util.Iterator;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReadParam;
-import javax.imageio.ImageReader;
-import javax.imageio.stream.ImageInputStream;
-
-import com.sun.image.codec.jpeg.ImageFormatException;
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-
-/**
- * 图片压缩工具类 提供的方法中可以设定生成的 缩略图片的大小尺寸、压缩尺寸的比例、图片的质量等
- * <pre>
- * 	调用示例:
- * resiz(srcImg, tarDir + "car_1_maxLength_11-220px-hui.jpg", 220, 0.7F);
- * </pre>
- *
- * @author cevencheng
- * @project haohui-b2b
- * @create 2012-3-22 下午8:29:01
- */
-public class ImageUtils {
-
-    /**
-     * * 图片文件读取
-     *
-     * @param srcImgPath
-     * @return
-     */
-    private static BufferedImage InputImage(String srcImgPath) throws RuntimeException {
-
-        BufferedImage srcImage = null;
-        FileInputStream in = null;
-        try {
-            // 构造BufferedImage对象
-            File file = new File(srcImgPath);
-            in = new FileInputStream(file);
-            byte[] b = new byte[5];
-            in.read(b);
-            srcImage = javax.imageio.ImageIO.read(file);
-        } catch (IOException e) {
-            e.printStackTrace();
-            throw new RuntimeException("读取图片文件出错!", e);
-        } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    throw new RuntimeException("读取图片文件出错!", e);
-                }
-            }
-        }
-        return srcImage;
-    }
-
-    /**
-     * * 将图片按照指定的图片尺寸、源图片质量压缩(默认质量为1)
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param new_w      :压缩后的图片宽
-     * @param new_h      :压缩后的图片高
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              int new_w, int new_h) {
-        resize(srcImgPath, outImgPath, new_w, new_h, 1F);
-    }
-
-    /**
-     * 将图片按照指定的尺寸比例、源图片质量压缩(默认质量为1)
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param ratio      :压缩后的图片尺寸比例
-     *                   :百分比
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              float ratio) {
-        resize(srcImgPath, outImgPath, ratio, 1F);
-    }
-
-    /**
-     * 将图片按照指定长或者宽的最大值来压缩图片(默认质量为1)
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param maxLength  :长或者宽的最大值
-     *                   :图片质量
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              int maxLength) {
-        resize(srcImgPath, outImgPath, maxLength, 1F);
-    }
-
-    /**
-     * * 将图片按照指定的图片尺寸、图片质量压缩
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param new_w      :压缩后的图片宽
-     * @param new_h      :压缩后的图片高
-     * @param per        :百分比
-     * @author cevencheng
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              int new_w, int new_h, float per) {
-        // 得到图片
-        BufferedImage src = InputImage(srcImgPath);
-        int old_w = src.getWidth();
-        // 得到源图宽
-        int old_h = src.getHeight();
-        // 得到源图长
-        // 根据原图的大小生成空白画布
-        BufferedImage tempImg = new BufferedImage(old_w, old_h,
-                BufferedImage.TYPE_INT_RGB);
-        // 在新的画布上生成原图的缩略图
-        Graphics2D g = tempImg.createGraphics();
-        g.setColor(Color.white);
-        g.fillRect(0, 0, old_w, old_h);
-        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
-        g.dispose();
-        BufferedImage newImg = new BufferedImage(new_w, new_h,
-                BufferedImage.TYPE_INT_RGB);
-        newImg.getGraphics().drawImage(
-                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
-                0, null);
-        // 调用方法输出图片文件
-        outImage(outImgPath, newImg, per);
-    }
-
-    public static BufferedImage resize(BufferedImage src,
-                                       int new_w, int new_h) {
-        int old_w = src.getWidth();
-        // 得到源图宽
-        int old_h = src.getHeight();
-        // 得到源图长
-        // 根据原图的大小生成空白画布
-        BufferedImage tempImg = new BufferedImage(old_w, old_h,
-                BufferedImage.TYPE_INT_RGB);
-        // 在新的画布上生成原图的缩略图
-        Graphics2D g = tempImg.createGraphics();
-        g.setColor(Color.white);
-        g.fillRect(0, 0, old_w, old_h);
-        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
-        g.dispose();
-        BufferedImage newImg = new BufferedImage(new_w, new_h,
-                BufferedImage.TYPE_INT_RGB);
-        newImg.getGraphics().drawImage(
-                tempImg, 0,
-                0, null);
-        // 调用方法输出图片文件
-        return newImg;
-    }
-
-    /**
-     * * 将图片按照指定的尺寸比例、图片质量压缩
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param ratio      :压缩后的图片尺寸比例
-     * @param per        :百分比
-     * @author cevencheng
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              float ratio, float per) {
-        // 得到图片
-        BufferedImage src = InputImage(srcImgPath);
-        int old_w = src.getWidth();
-        // 得到源图宽
-        int old_h = src.getHeight();
-        // 得到源图长
-        int new_w = 0;
-        // 新图的宽
-        int new_h = 0;
-        // 新图的长
-        BufferedImage tempImg = new BufferedImage(old_w, old_h,
-                BufferedImage.TYPE_INT_RGB);
-        Graphics2D g = tempImg.createGraphics();
-        g.setColor(Color.white);
-        // 从原图上取颜色绘制新图g.fillRect(0, 0, old_w, old_h);
-        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
-        g.dispose();
-        // 根据图片尺寸压缩比得到新图的尺寸new_w = (int) Math.round(old_w * ratio);
-        new_h = (int) Math.round(old_h * ratio);
-        BufferedImage newImg = new BufferedImage(new_w, new_h,
-                BufferedImage.TYPE_INT_RGB);
-        newImg.getGraphics().drawImage(
-                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
-                0, null);
-        // 调用方法输出图片文件OutImage(outImgPath, newImg, per);
-    }
-
-    /**
-     * <b>
-     * 指定长或者宽的最大值来压缩图片
-     * 推荐使用此方法
-     * </b>
-     *
-     * @param srcImgPath :源图片路径
-     * @param outImgPath :输出的压缩图片的路径
-     * @param maxLength  :长或者宽的最大值
-     * @param per        :图片质量
-     * @author cevencheng
-     */
-    public static void resize(String srcImgPath, String outImgPath,
-                              int maxLength, float per) {
-        // 得到图片
-        BufferedImage src = InputImage(srcImgPath);
-        int old_w = src.getWidth();
-        // 得到源图宽
-        int old_h = src.getHeight();
-        // 得到源图长
-        int new_w = 0;
-        // 新图的宽
-        int new_h = 0;
-        // 新图的长
-        BufferedImage tempImg = new BufferedImage(old_w, old_h,
-                BufferedImage.TYPE_INT_RGB);
-        Graphics2D g = tempImg.createGraphics();
-        g.setColor(Color.white);
-        // 从原图上取颜色绘制新图
-        g.fillRect(0, 0, old_w, old_h);
-        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
-        g.dispose();
-        // 根据图片尺寸压缩比得到新图的尺寸
-        if (old_w > old_h) {
-            // 图片要缩放的比例
-            new_w = maxLength;
-            new_h = (int) Math.round(old_h * ((float) maxLength / old_w));
-        } else {
-            new_w = (int) Math.round(old_w * ((float) maxLength / old_h));
-            new_h = maxLength;
-        }
-        BufferedImage newImg = new BufferedImage(new_w, new_h,
-                BufferedImage.TYPE_INT_RGB);
-        newImg.getGraphics().drawImage(
-                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
-                0, null);
-        // 调用方法输出图片文件
-        outImage(outImgPath, newImg, per);
-    }
-
-    /**
-     * 将图片压缩成指定宽度, 高度等比例缩放
-     *
-     * @param srcImgPath
-     * @param outImgPath
-     * @param width
-     * @param per
-     */
-    public static void resizeFixedWidth(String srcImgPath, String outImgPath,
-                                        int width, float per) {
-        // 得到图片
-        BufferedImage src = InputImage(srcImgPath);
-        int old_w = src.getWidth();
-        // 得到源图宽
-        int old_h = src.getHeight();
-        // 得到源图长
-        int new_w = 0;
-        // 新图的宽
-        int new_h = 0;
-        // 新图的长
-        BufferedImage tempImg = new BufferedImage(old_w, old_h,
-                BufferedImage.TYPE_INT_RGB);
-        Graphics2D g = tempImg.createGraphics();
-        g.setColor(Color.white);
-        // 从原图上取颜色绘制新图
-        g.fillRect(0, 0, old_w, old_h);
-        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
-        g.dispose();
-        // 根据图片尺寸压缩比得到新图的尺寸
-        if (old_w > old_h) {
-            // 图片要缩放的比例
-            new_w = width;
-            new_h = (int) Math.round(old_h * ((float) width / old_w));
-        } else {
-            new_w = (int) Math.round(old_w * ((float) width / old_h));
-            new_h = width;
-        }
-        BufferedImage newImg = new BufferedImage(new_w, new_h,
-                BufferedImage.TYPE_INT_RGB);
-        newImg.getGraphics().drawImage(
-                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
-                0, null);
-        // 调用方法输出图片文件
-        outImage(outImgPath, newImg, per);
-    }
-
-    /**
-     * * 将图片文件输出到指定的路径,并可设定压缩质量
-     *
-     * @param outImgPath
-     * @param newImg
-     * @param per
-     * @author cevencheng
-     */
-    private static void outImage(String outImgPath, BufferedImage newImg, float per) {
-        // 判断输出的文件夹路径是否存在,不存在则创建
-        File file = new File(outImgPath);
-        if (!file.getParentFile().exists()) {
-            file.getParentFile().mkdirs();
-        }
-        // 输出到文件流
-        FileOutputStream fos = null;
-        try {
-            fos = new FileOutputStream(outImgPath);
-            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
-            JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(newImg);
-            // 压缩质量
-            jep.setQuality(per, true);
-            encoder.encode(newImg, jep);
-            fos.close();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            if (fos != null) {
-                try {
-                    fos.close();
-                } catch (IOException e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        }
-    }
-
-    /**
-     * 图片剪切工具方法
-     *
-     * @param srcfile 源图片
-     * @param outfile 剪切之后的图片
-     * @param x       剪切顶点 X 坐标
-     * @param y       剪切顶点 Y 坐标
-     * @param width   剪切区域宽度
-     * @param height  剪切区域高度
-     * @throws IOException
-     * @author cevencheng
-     */
-    public static void cut(File srcfile, File outfile, int x, int y, int width, int height) throws IOException {
-        FileInputStream is = null;
-        ImageInputStream iis = null;
-        try {
-            // 读取图片文件
-            is = new FileInputStream(srcfile);
-
-            /*
-             * 返回包含所有当前已注册 ImageReader 的 Iterator,这些 ImageReader 声称能够解码指定格式。
-             * 参数:formatName - 包含非正式格式名称 .(例如 "jpeg" 或 "tiff")等 。
-             */
-            Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName("jpg");
-            ImageReader reader = it.next();
-            // 获取图片流
-            iis = ImageIO.createImageInputStream(is);
-
-            /*
-             * <p>iis:读取源.true:只向前搜索 </p>.将它标记为 ‘只向前搜索’。
-             * 此设置意味着包含在输入源中的图像将只按顺序读取,可能允许 reader 避免缓存包含与以前已经读取的图像关联的数据的那些输入部分。
-             */
-            reader.setInput(iis, true);
-
-            /*
-             * <p>描述如何对流进行解码的类<p>.用于指定如何在输入时从 Java Image I/O
-             * 框架的上下文中的流转换一幅图像或一组图像。用于特定图像格式的插件 将从其 ImageReader 实现的
-             * getDefaultReadParam 方法中返回 ImageReadParam 的实例。
-             */
-            ImageReadParam param = reader.getDefaultReadParam();
-
-            /*
-             * 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象
-             * 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。
-             */
-            Rectangle rect = new Rectangle(x, y, width, height);
-
-            // 提供一个 BufferedImage,将其用作解码像素数据的目标。
-            param.setSourceRegion(rect);
-
-            /*
-             * 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的
-             * BufferedImage 返回。
-             */
-            BufferedImage bi = reader.read(0, param);
-
-            // 保存新图片
-            ImageIO.write(bi, "jpg", outfile);
-        } finally {
-            if (is != null) {
-                is.close();
-            }
-            if (iis != null) {
-                iis.close();
-            }
-        }
-    }
-
-    public static void main(String args[]) throws Exception {
-        String srcImg = "D:/sm.png";
-        String tarDir = "d:/";
-//        URL url = ImageUtils.class.getResource("src-2012.jpg");
-        File srcfile = new File(srcImg);
-//        System.out.println(url);
-        System.out.println(srcfile.exists() + ", dir=" + srcfile.getParent());
-        tarDir = srcfile.getParent();
-        srcImg = srcfile.getPath();
-        System.out.println("srcImg=" + srcImg);
-        long startTime = new Date().getTime();
-        resize(srcImg, tarDir + "car_1_maxLength_1-200px.jpg", 200);
-//        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_2.jpg", 0.5F);
-        resize(srcImg, tarDir + "car_1_maxLength_3.jpg", 280, 112);
-        resize(srcImg, tarDir + "car_1_maxLength_4-400x400.jpg", 220, 220);
-        resize(srcImg, tarDir + "car_1_maxLength_11-220px-yinhui.jpg", 220, 0.7F);
-//        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_22.jpg", 0.5F, 0.8F);
-        resize(srcImg, tarDir + "car_1_maxLength_33.jpg", 400, 500, 0.8F);
-        System.out.println(new Date().getTime() - startTime);
-    }
-}
+//package cn.com.ctop.common.utils;
+//
+//import java.awt.Color;
+//import java.awt.Graphics2D;
+//import java.awt.Image;
+//import java.awt.Rectangle;
+//import java.awt.image.BufferedImage;
+//import java.io.File;
+//import java.io.FileInputStream;
+//import java.io.FileOutputStream;
+//import java.io.IOException;
+//import java.net.URL;
+//import java.util.Date;
+//import java.util.Iterator;
+//
+//import javax.imageio.ImageIO;
+//import javax.imageio.ImageReadParam;
+//import javax.imageio.ImageReader;
+//import javax.imageio.stream.ImageInputStream;
+//
+//import com.sun.image.codec.jpeg.ImageFormatException;
+//import com.sun.image.codec.jpeg.JPEGCodec;
+//import com.sun.image.codec.jpeg.JPEGEncodeParam;
+//import com.sun.image.codec.jpeg.JPEGImageEncoder;
+//
+///**
+// * 图片压缩工具类 提供的方法中可以设定生成的 缩略图片的大小尺寸、压缩尺寸的比例、图片的质量等
+// * <pre>
+// * 	调用示例:
+// * resiz(srcImg, tarDir + "car_1_maxLength_11-220px-hui.jpg", 220, 0.7F);
+// * </pre>
+// *
+// * @author cevencheng
+// * @project haohui-b2b
+// * @create 2012-3-22 下午8:29:01
+// */
+//public class ImageUtils {
+//
+//    /**
+//     * * 图片文件读取
+//     *
+//     * @param srcImgPath
+//     * @return
+//     */
+//    private static BufferedImage InputImage(String srcImgPath) throws RuntimeException {
+//
+//        BufferedImage srcImage = null;
+//        FileInputStream in = null;
+//        try {
+//            // 构造BufferedImage对象
+//            File file = new File(srcImgPath);
+//            in = new FileInputStream(file);
+//            byte[] b = new byte[5];
+//            in.read(b);
+//            srcImage = javax.imageio.ImageIO.read(file);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//            throw new RuntimeException("读取图片文件出错!", e);
+//        } finally {
+//            if (in != null) {
+//                try {
+//                    in.close();
+//                } catch (IOException e) {
+//                    throw new RuntimeException("读取图片文件出错!", e);
+//                }
+//            }
+//        }
+//        return srcImage;
+//    }
+//
+//    /**
+//     * * 将图片按照指定的图片尺寸、源图片质量压缩(默认质量为1)
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param new_w      :压缩后的图片宽
+//     * @param new_h      :压缩后的图片高
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              int new_w, int new_h) {
+//        resize(srcImgPath, outImgPath, new_w, new_h, 1F);
+//    }
+//
+//    /**
+//     * 将图片按照指定的尺寸比例、源图片质量压缩(默认质量为1)
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param ratio      :压缩后的图片尺寸比例
+//     *                   :百分比
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              float ratio) {
+//        resize(srcImgPath, outImgPath, ratio, 1F);
+//    }
+//
+//    /**
+//     * 将图片按照指定长或者宽的最大值来压缩图片(默认质量为1)
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param maxLength  :长或者宽的最大值
+//     *                   :图片质量
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              int maxLength) {
+//        resize(srcImgPath, outImgPath, maxLength, 1F);
+//    }
+//
+//    /**
+//     * * 将图片按照指定的图片尺寸、图片质量压缩
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param new_w      :压缩后的图片宽
+//     * @param new_h      :压缩后的图片高
+//     * @param per        :百分比
+//     * @author cevencheng
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              int new_w, int new_h, float per) {
+//        // 得到图片
+//        BufferedImage src = InputImage(srcImgPath);
+//        int old_w = src.getWidth();
+//        // 得到源图宽
+//        int old_h = src.getHeight();
+//        // 得到源图长
+//        // 根据原图的大小生成空白画布
+//        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        // 在新的画布上生成原图的缩略图
+//        Graphics2D g = tempImg.createGraphics();
+//        g.setColor(Color.white);
+//        g.fillRect(0, 0, old_w, old_h);
+//        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+//        g.dispose();
+//        BufferedImage newImg = new BufferedImage(new_w, new_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        newImg.getGraphics().drawImage(
+//                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+//                0, null);
+//        // 调用方法输出图片文件
+//        outImage(outImgPath, newImg, per);
+//    }
+//
+//    public static BufferedImage resize(BufferedImage src,
+//                                       int new_w, int new_h) {
+//        int old_w = src.getWidth();
+//        // 得到源图宽
+//        int old_h = src.getHeight();
+//        // 得到源图长
+//        // 根据原图的大小生成空白画布
+//        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        // 在新的画布上生成原图的缩略图
+//        Graphics2D g = tempImg.createGraphics();
+//        g.setColor(Color.white);
+//        g.fillRect(0, 0, old_w, old_h);
+//        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+//        g.dispose();
+//        BufferedImage newImg = new BufferedImage(new_w, new_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        newImg.getGraphics().drawImage(
+//                tempImg, 0,
+//                0, null);
+//        // 调用方法输出图片文件
+//        return newImg;
+//    }
+//
+//    /**
+//     * * 将图片按照指定的尺寸比例、图片质量压缩
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param ratio      :压缩后的图片尺寸比例
+//     * @param per        :百分比
+//     * @author cevencheng
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              float ratio, float per) {
+//        // 得到图片
+//        BufferedImage src = InputImage(srcImgPath);
+//        int old_w = src.getWidth();
+//        // 得到源图宽
+//        int old_h = src.getHeight();
+//        // 得到源图长
+//        int new_w = 0;
+//        // 新图的宽
+//        int new_h = 0;
+//        // 新图的长
+//        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        Graphics2D g = tempImg.createGraphics();
+//        g.setColor(Color.white);
+//        // 从原图上取颜色绘制新图g.fillRect(0, 0, old_w, old_h);
+//        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+//        g.dispose();
+//        // 根据图片尺寸压缩比得到新图的尺寸new_w = (int) Math.round(old_w * ratio);
+//        new_h = (int) Math.round(old_h * ratio);
+//        BufferedImage newImg = new BufferedImage(new_w, new_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        newImg.getGraphics().drawImage(
+//                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+//                0, null);
+//        // 调用方法输出图片文件OutImage(outImgPath, newImg, per);
+//    }
+//
+//    /**
+//     * <b>
+//     * 指定长或者宽的最大值来压缩图片
+//     * 推荐使用此方法
+//     * </b>
+//     *
+//     * @param srcImgPath :源图片路径
+//     * @param outImgPath :输出的压缩图片的路径
+//     * @param maxLength  :长或者宽的最大值
+//     * @param per        :图片质量
+//     * @author cevencheng
+//     */
+//    public static void resize(String srcImgPath, String outImgPath,
+//                              int maxLength, float per) {
+//        // 得到图片
+//        BufferedImage src = InputImage(srcImgPath);
+//        int old_w = src.getWidth();
+//        // 得到源图宽
+//        int old_h = src.getHeight();
+//        // 得到源图长
+//        int new_w = 0;
+//        // 新图的宽
+//        int new_h = 0;
+//        // 新图的长
+//        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        Graphics2D g = tempImg.createGraphics();
+//        g.setColor(Color.white);
+//        // 从原图上取颜色绘制新图
+//        g.fillRect(0, 0, old_w, old_h);
+//        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+//        g.dispose();
+//        // 根据图片尺寸压缩比得到新图的尺寸
+//        if (old_w > old_h) {
+//            // 图片要缩放的比例
+//            new_w = maxLength;
+//            new_h = (int) Math.round(old_h * ((float) maxLength / old_w));
+//        } else {
+//            new_w = (int) Math.round(old_w * ((float) maxLength / old_h));
+//            new_h = maxLength;
+//        }
+//        BufferedImage newImg = new BufferedImage(new_w, new_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        newImg.getGraphics().drawImage(
+//                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+//                0, null);
+//        // 调用方法输出图片文件
+//        outImage(outImgPath, newImg, per);
+//    }
+//
+//    /**
+//     * 将图片压缩成指定宽度, 高度等比例缩放
+//     *
+//     * @param srcImgPath
+//     * @param outImgPath
+//     * @param width
+//     * @param per
+//     */
+//    public static void resizeFixedWidth(String srcImgPath, String outImgPath,
+//                                        int width, float per) {
+//        // 得到图片
+//        BufferedImage src = InputImage(srcImgPath);
+//        int old_w = src.getWidth();
+//        // 得到源图宽
+//        int old_h = src.getHeight();
+//        // 得到源图长
+//        int new_w = 0;
+//        // 新图的宽
+//        int new_h = 0;
+//        // 新图的长
+//        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        Graphics2D g = tempImg.createGraphics();
+//        g.setColor(Color.white);
+//        // 从原图上取颜色绘制新图
+//        g.fillRect(0, 0, old_w, old_h);
+//        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+//        g.dispose();
+//        // 根据图片尺寸压缩比得到新图的尺寸
+//        if (old_w > old_h) {
+//            // 图片要缩放的比例
+//            new_w = width;
+//            new_h = (int) Math.round(old_h * ((float) width / old_w));
+//        } else {
+//            new_w = (int) Math.round(old_w * ((float) width / old_h));
+//            new_h = width;
+//        }
+//        BufferedImage newImg = new BufferedImage(new_w, new_h,
+//                BufferedImage.TYPE_INT_RGB);
+//        newImg.getGraphics().drawImage(
+//                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+//                0, null);
+//        // 调用方法输出图片文件
+//        outImage(outImgPath, newImg, per);
+//    }
+//
+//    /**
+//     * * 将图片文件输出到指定的路径,并可设定压缩质量
+//     *
+//     * @param outImgPath
+//     * @param newImg
+//     * @param per
+//     * @author cevencheng
+//     */
+//    private static void outImage(String outImgPath, BufferedImage newImg, float per) {
+//        // 判断输出的文件夹路径是否存在,不存在则创建
+//        File file = new File(outImgPath);
+//        if (!file.getParentFile().exists()) {
+//            file.getParentFile().mkdirs();
+//        }
+//        // 输出到文件流
+//        FileOutputStream fos = null;
+//        try {
+//            fos = new FileOutputStream(outImgPath);
+//            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
+//            JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(newImg);
+//            // 压缩质量
+//            jep.setQuality(per, true);
+//            encoder.encode(newImg, jep);
+//            fos.close();
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        } finally {
+//            if (fos != null) {
+//                try {
+//                    fos.close();
+//                } catch (IOException e) {
+//                    throw new RuntimeException(e);
+//                }
+//            }
+//        }
+//    }
+//
+//    /**
+//     * 图片剪切工具方法
+//     *
+//     * @param srcfile 源图片
+//     * @param outfile 剪切之后的图片
+//     * @param x       剪切顶点 X 坐标
+//     * @param y       剪切顶点 Y 坐标
+//     * @param width   剪切区域宽度
+//     * @param height  剪切区域高度
+//     * @throws IOException
+//     * @author cevencheng
+//     */
+//    public static void cut(File srcfile, File outfile, int x, int y, int width, int height) throws IOException {
+//        FileInputStream is = null;
+//        ImageInputStream iis = null;
+//        try {
+//            // 读取图片文件
+//            is = new FileInputStream(srcfile);
+//
+//            /*
+//             * 返回包含所有当前已注册 ImageReader 的 Iterator,这些 ImageReader 声称能够解码指定格式。
+//             * 参数:formatName - 包含非正式格式名称 .(例如 "jpeg" 或 "tiff")等 。
+//             */
+//            Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName("jpg");
+//            ImageReader reader = it.next();
+//            // 获取图片流
+//            iis = ImageIO.createImageInputStream(is);
+//
+//            /*
+//             * <p>iis:读取源.true:只向前搜索 </p>.将它标记为 ‘只向前搜索’。
+//             * 此设置意味着包含在输入源中的图像将只按顺序读取,可能允许 reader 避免缓存包含与以前已经读取的图像关联的数据的那些输入部分。
+//             */
+//            reader.setInput(iis, true);
+//
+//            /*
+//             * <p>描述如何对流进行解码的类<p>.用于指定如何在输入时从 Java Image I/O
+//             * 框架的上下文中的流转换一幅图像或一组图像。用于特定图像格式的插件 将从其 ImageReader 实现的
+//             * getDefaultReadParam 方法中返回 ImageReadParam 的实例。
+//             */
+//            ImageReadParam param = reader.getDefaultReadParam();
+//
+//            /*
+//             * 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象
+//             * 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。
+//             */
+//            Rectangle rect = new Rectangle(x, y, width, height);
+//
+//            // 提供一个 BufferedImage,将其用作解码像素数据的目标。
+//            param.setSourceRegion(rect);
+//
+//            /*
+//             * 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的
+//             * BufferedImage 返回。
+//             */
+//            BufferedImage bi = reader.read(0, param);
+//
+//            // 保存新图片
+//            ImageIO.write(bi, "jpg", outfile);
+//        } finally {
+//            if (is != null) {
+//                is.close();
+//            }
+//            if (iis != null) {
+//                iis.close();
+//            }
+//        }
+//    }
+//
+//    public static void main(String args[]) throws Exception {
+//        String srcImg = "D:/sm.png";
+//        String tarDir = "d:/";
+////        URL url = ImageUtils.class.getResource("src-2012.jpg");
+//        File srcfile = new File(srcImg);
+////        System.out.println(url);
+//        System.out.println(srcfile.exists() + ", dir=" + srcfile.getParent());
+//        tarDir = srcfile.getParent();
+//        srcImg = srcfile.getPath();
+//        System.out.println("srcImg=" + srcImg);
+//        long startTime = new Date().getTime();
+//        resize(srcImg, tarDir + "car_1_maxLength_1-200px.jpg", 200);
+////        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_2.jpg", 0.5F);
+//        resize(srcImg, tarDir + "car_1_maxLength_3.jpg", 280, 112);
+//        resize(srcImg, tarDir + "car_1_maxLength_4-400x400.jpg", 220, 220);
+//        resize(srcImg, tarDir + "car_1_maxLength_11-220px-yinhui.jpg", 220, 0.7F);
+////        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_22.jpg", 0.5F, 0.8F);
+//        resize(srcImg, tarDir + "car_1_maxLength_33.jpg", 400, 500, 0.8F);
+//        System.out.println(new Date().getTime() - startTime);
+//    }
+//}

+ 62 - 62
module-common/src/main/java/cn/com/ctop/common/utils/WebMasterUtils.java

@@ -1,62 +1,62 @@
-package cn.com.ctop.common.utils;
-
-import us.codecraft.webmagic.Page;
-import us.codecraft.webmagic.ResultItems;
-import us.codecraft.webmagic.Site;
-import us.codecraft.webmagic.Spider;
-import us.codecraft.webmagic.downloader.PhantomJSDownloader;
-import us.codecraft.webmagic.pipeline.CollectorPipeline;
-import us.codecraft.webmagic.pipeline.ResultItemsCollectorPipeline;
-import us.codecraft.webmagic.processor.PageProcessor;
-
-import java.util.List;
-
-public class WebMasterUtils implements PageProcessor {
-    private Site site = Site.me()
-            .setDomain("live.kuaishou.com")
-            .setCharset("UTF-8")
-            .addHeader("Referer","https://live.kuaishou.com")
-            .setRetryTimes(1).setSleepTime(1000);
-
-    public static void main(String[] args){
-        PhantomJSDownloader phantomDownloader = new PhantomJSDownloader("D:/phantomjs-2.1.1-windows/bin/phantomjs.exe","D:/phantomjs-2.1.1-windows/bin/crawler.js").setRetryNum(3);
-
-        CollectorPipeline<ResultItems> collectorPipeline = new ResultItemsCollectorPipeline();
-
-        Spider.create(new WebMasterUtils())
-                .addUrl("https://live.kuaishou.com/profile/mumu6666668")
-                .setDownloader(phantomDownloader)
-                .addPipeline(collectorPipeline)
-                .thread((Runtime.getRuntime().availableProcessors() - 1) << 1)
-                .run();
-
-        List<ResultItems> resultItemsList = collectorPipeline.getCollected();
-        System.out.println(resultItemsList.get(0).get("html").toString());
-
-        Spider.create(new WebMasterUtils())
-                .addUrl("https://live.kuaishou.com/profile/mumu6666668")
-                .setDownloader(phantomDownloader)
-                .addPipeline(collectorPipeline)
-                .thread((Runtime.getRuntime().availableProcessors() - 1) << 1)
-                .run();
-
-        resultItemsList = collectorPipeline.getCollected();
-        ResultItems item = resultItemsList.get(0);
-
-        System.out.println(resultItemsList.get(0).get("html").toString());
-//        System.out.println(resultItemsList.get(1).get("html").toString());
-
-    }
-
-    @Override
-    public void process(Page page) {
-        if(page.getRawText() != null) {
-            page.putField("html", page.getRawText());
-        }
-    }
-
-    @Override
-    public Site getSite() {
-        return site;
-    }
-}
+//package cn.com.ctop.common.utils;
+//
+//import us.codecraft.webmagic.Page;
+//import us.codecraft.webmagic.ResultItems;
+//import us.codecraft.webmagic.Site;
+//import us.codecraft.webmagic.Spider;
+//import us.codecraft.webmagic.downloader.PhantomJSDownloader;
+//import us.codecraft.webmagic.pipeline.CollectorPipeline;
+//import us.codecraft.webmagic.pipeline.ResultItemsCollectorPipeline;
+//import us.codecraft.webmagic.processor.PageProcessor;
+//
+//import java.util.List;
+//
+//public class WebMasterUtils implements PageProcessor {
+//    private Site site = Site.me()
+//            .setDomain("live.kuaishou.com")
+//            .setCharset("UTF-8")
+//            .addHeader("Referer","https://live.kuaishou.com")
+//            .setRetryTimes(1).setSleepTime(1000);
+//
+//    public static void main(String[] args){
+//        PhantomJSDownloader phantomDownloader = new PhantomJSDownloader("D:/phantomjs-2.1.1-windows/bin/phantomjs.exe","D:/phantomjs-2.1.1-windows/bin/crawler.js").setRetryNum(3);
+//
+//        CollectorPipeline<ResultItems> collectorPipeline = new ResultItemsCollectorPipeline();
+//
+//        Spider.create(new WebMasterUtils())
+//                .addUrl("https://live.kuaishou.com/profile/mumu6666668")
+//                .setDownloader(phantomDownloader)
+//                .addPipeline(collectorPipeline)
+//                .thread((Runtime.getRuntime().availableProcessors() - 1) << 1)
+//                .run();
+//
+//        List<ResultItems> resultItemsList = collectorPipeline.getCollected();
+//        System.out.println(resultItemsList.get(0).get("html").toString());
+//
+//        Spider.create(new WebMasterUtils())
+//                .addUrl("https://live.kuaishou.com/profile/mumu6666668")
+//                .setDownloader(phantomDownloader)
+//                .addPipeline(collectorPipeline)
+//                .thread((Runtime.getRuntime().availableProcessors() - 1) << 1)
+//                .run();
+//
+//        resultItemsList = collectorPipeline.getCollected();
+//        ResultItems item = resultItemsList.get(0);
+//
+//        System.out.println(resultItemsList.get(0).get("html").toString());
+////        System.out.println(resultItemsList.get(1).get("html").toString());
+//
+//    }
+//
+//    @Override
+//    public void process(Page page) {
+//        if(page.getRawText() != null) {
+//            page.putField("html", page.getRawText());
+//        }
+//    }
+//
+//    @Override
+//    public Site getSite() {
+//        return site;
+//    }
+//}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 401 - 426
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/KuaishouTest.java