From b2382d524cfca76f71c9bcf670e68fdb647a0c5d Mon Sep 17 00:00:00 2001 From: ronger Date: Tue, 14 Jan 2020 17:35:02 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=BC=95=E5=85=A5=E7=99=BE?= =?UTF-8?q?=E5=BA=A6=E7=AB=99=E7=82=B9=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ArticleServiceImpl.java | 2 + .../com/rymcu/vertical/util/BaiDuUtils.java | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/rymcu/vertical/util/BaiDuUtils.java diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index a963a89..9406b1d 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -11,6 +11,7 @@ import com.rymcu.vertical.mapper.ArticleMapper; import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.TagService; import com.rymcu.vertical.service.UserService; +import com.rymcu.vertical.util.BaiDuUtils; import com.rymcu.vertical.util.Html2TextUtil; import com.rymcu.vertical.util.UserUtils; import com.rymcu.vertical.util.Utils; @@ -110,6 +111,7 @@ public class ArticleServiceImpl extends AbstractService
implements Arti article1.setArticlePermalink(DOMAIN + "/article/"+article1.getIdArticle()); article1.setArticleLink("/article/"+article1.getIdArticle()); articleMapper.insertArticleContent(article1.getIdArticle(),articleContent,articleContentHtml); + BaiDuUtils.sendSEOData(article1.getArticlePermalink()); } else { article1 = articleMapper.selectByPrimaryKey(article.getIdArticle()); if(!user.getIdUser().equals(article1.getArticleAuthorId())){ diff --git a/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java b/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java new file mode 100644 index 0000000..f207734 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java @@ -0,0 +1,39 @@ +package com.rymcu.vertical.util; + +import jodd.http.HttpRequest; +import jodd.http.HttpResponse; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Value; + +import java.util.concurrent.*; + +/** + * @author ronger + */ +public class BaiDuUtils { + + @Value("${baidu.data.token}") + private static String token; + @Value("${baidu.data.site}") + private static String site; + + public static void sendSEOData(String articlePermalink) { + if (StringUtils.isBlank(articlePermalink) || StringUtils.isBlank(token)) { + return; + } + ExecutorService executor= new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + CompletableFuture.supplyAsync(()-> { + try { + HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/urls?site=" + site + "&token=" + token). + header("User-Agent", "curl/7.12.1"). + header("Host", "data.zz.baidu.com"). + header("Content-Type", "text/plain"). + header("Connection", "close").body(articlePermalink.getBytes(), "text/plain").timeout(30000).send(); + response.charset("UTF-8"); + } catch (Exception e){ + e.printStackTrace(); + } + return 0; + },executor); + } +}