Search in sources :

Example 1 with WechatArticleCrawlerTask

use of com.bc.pmpheep.general.runnable.WechatArticleCrawlerTask in project pmph by BCSquad.

the class WechatArticleService method runCrawler.

public String runCrawler(String url) throws CheckedServiceException {
    if (StringUtil.isEmpty(url)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.NULL_PARAM, "给定链接不能为空");
    }
    if (url.length() < 25) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
    } else {
        String httpStr = url.substring(0, 23);
        String httpsStr = url.substring(0, 24);
        if (!"http://mp.weixin.qq.com".equals(httpStr) && !"https://mp.weixin.qq.com".equals(httpsStr)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
        }
    }
    String guid = String.valueOf(System.currentTimeMillis()).concat(String.valueOf(RandomUtil.getRandomNum()));
    taskExecutor.execute(new WechatArticleCrawlerTask(new WechatArticle(guid, url)));
    return guid;
}
Also used : CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WechatArticle(com.bc.pmpheep.general.runnable.WechatArticle) WechatArticleCrawlerTask(com.bc.pmpheep.general.runnable.WechatArticleCrawlerTask)

Aggregations

WechatArticle (com.bc.pmpheep.general.runnable.WechatArticle)1 WechatArticleCrawlerTask (com.bc.pmpheep.general.runnable.WechatArticleCrawlerTask)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1