提交 b5d1f668 authored 作者: renjianyu's avatar renjianyu

--no commit message

上级 4e7482b6
......@@ -39,6 +39,13 @@ public class DataLogController {
public CallBack<JSONObject> getTrend(QueryTrendForm form) {
return CallBack.success(service.loadTrend(form));
}
//---------------行为分析------------------
@ApiOperation("行为-趋势分析")
@PostMapping("/behaviorApp")
public CallBack<JSONObject> getTrendApp(QueryTrendForm form) {
return CallBack.success(service.loadTrendApp(form));
}
@ApiOperation("来源分析")
@PostMapping("/source")
public CallBack<JSONObject> getSource(QuerySourceForm form) {
......
......@@ -78,6 +78,13 @@ public interface DataLogService extends BaseService<DataLog, String> {
*/
JSONObject loadTrend(QueryTrendForm form);
/**
* 获取行为分析趋势分析
* @return
* @author rjy
* @date: 2021年02月07日 下午4:05:03
*/
JSONObject loadTrendApp(QueryTrendForm form);
/**
* 获取来源分析
* @param form
* @return
......
......@@ -744,4 +744,20 @@ public class DataLogServiceImpl extends BaseServiceImpl<DataLog, String> impleme
return objBody;
}
@Override
public JSONObject loadTrendApp(QueryTrendForm form) {
JSONObject obj = null;
try {
String param = "access_token="+BaiduConfig.TOKEN+"&key="+BaiduConfig.SITEID+"&method=visit/page/a&start-date="+form.getStart_date()+"&end-date="+form.getEnd_date()+"&metrics=pv_count,pv_ratio" ;
String s = HttpUtils.sendGet(BaiduConfig.API_URL, param);
obj = JSON.parseObject(s);
//log.info(objBody.toJSONString());
} catch (Exception e) {
log.error("获取来源分析结果失败", e);
}
return obj;
}
}
package com.zrqx.statistics.utils.baidu;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
......@@ -111,5 +116,59 @@ public class HttpUtils {
}
}
/**
* java模拟get请求
* @param out_trade_no
* @return
* @throws Exception
* @author ray
* @date: 2018年8月24日 下午3:25:34
*/
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//设置连接主机超时
connection.setConnectTimeout(30000);
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
}
......@@ -5,7 +5,7 @@ public class BaiduConfig {
public static final String ACCOUNT = "shiyoushe";
public static final String PASSWORD = "cnpc6452CNPC";
//移动端 token
public static final String TOKEN = "121.6780a420b308a69d3b2b709771f05f39.Y3TQ7_B-ul_K9A6LNsadJz7j68g7K-IJo2dhY_-.g7hXsw";
public static final String SITEID = "9c6665dfc6";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论