【2021-02】实时获取百度搜索词接口
作者:互联网
获取百度搜索词目的
随着百度流量的不断扩大近年来很多的产品都围绕着百度流量的特征做了很多产品,比如访客搜索“三体”进入到一个网上书城,书城会根据访客搜索的词直接显示“三体”相关的书籍。资源较多的企业一般选择给所有的书籍或者产品输出一个单页,在搜索相关信息时百度展现的就是对应产品的单页,但是一般情况下要准确命中还是比较困难的,如果在落地时能获取到访客在百度中搜素的关键字这样站长就可以灵活对自己的业务进行处理。
获取访客搜索关键字接口测试
API地址:https://doc.echatsoft.com/api/baiduApi/getKeyword.html
ChatLogger logger = YiChatLogger.getChatLogger("baiduAction.jsp");
String result = "系统繁忙,请稍后再试!";
String refer = request.getParameter("refer");
if (StringUtil.isEmpty(refer)) {
sendBack(response, result);
return;
}
ReferrerSearchInfo searchInfo = ReferrerAnalyzer.getRefererSearchInfo(refer);
if (searchInfo == null || !StringUtil.equalsIgnoreCase(searchInfo.getEngine(), Constants.baidu) || StringUtil.isEmpty(searchInfo.getBceEqid())) {
sendBack(response, result);
return;
}
String url = "http://127.0.0.1/pwd";
String data = "{\"eqid\":\"" + searchInfo.getBceEqid() + "\"}";
String companyId = "125";
String appId = "3DEF184AD8F4755FF26982";
String aesKey = "xUsuJwvD6OQGYg22IS4JBkJMuXGYrfdOZ";
String token = "IwY56e";
long timestamp = System.currentTimeMillis() - 5000;
String nonce = RandomUtil.getRandomNumberByDigit(6);
String signature = EncryptUtil.getSHASignature(timestamp, token, nonce);
WXBizMsgCrypt crypt = new WXBizMsgCrypt(token, aesKey, appId);
url = url + "?companyId=" + companyId + "×tamp=" + timestamp + "&nonce=" + nonce + "&signature=" + signature;
String rs = OkHttpUtil.postTextData(url, crypt.encryptData(data));
if (StringUtil.isEmpty(rs)) {
sendBack(response, result);
return;
}
try {
String keyword = EchatJsonUtil.getAttributFromJson(rs, "keyword");
sendBack(response, "关键字:" + keyword);
return;
} catch (Exception e) {
}
sendBack(response, result);
实测体验
测试地址:https://chat.rainbowred.com/baiduTest.html
百度搜索任意关键词,将落地页面的来源地址document.referrer,提交给接口测试页面即可返回访客的百度搜索词。
以百度搜索“csdn官网”为例,点击进入csdn站点后其搜索来源地址为:
https://www.baidu.com/link?url=iMTBywQiEhPZH4v8CEkgXRx1WpEPwfl_7LsqFkXdtJ3&wd=&eqid=df91d4ba00007d8200000006603610cc
将此地址提交给测试页面即可返回搜索词。
标签:02,String,searchInfo,搜索词,2021,sendBack,response,百度,result 来源: https://blog.csdn.net/a276202460/article/details/114026575