✨ 引入百度站点工具
This commit is contained in:
parent
3ce804779e
commit
b2382d524c
@ -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<Article> 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())){
|
||||
|
39
src/main/java/com/rymcu/vertical/util/BaiDuUtils.java
Normal file
39
src/main/java/com/rymcu/vertical/util/BaiDuUtils.java
Normal file
@ -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<Runnable>());
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user