百度推广平台数据API接口数据回传
数据推广分析
在线Api https://dev2.baidu.com/content?sceneType=0&pageId=101211&nodeId=658&subhead=
public class BaiduConvert {
public static final String URL = "https://ocpc.baidu.com/ocpcapi/api/uploadConvertData";
/**
* 上传数据
*/
public AjaxResult upload(BaiduConvertEntity entity) throws Exception {
String method = "[百度推广-数据回传] ";
log.info(method + "--------------------start");
String req = getParams(entity);
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json; charset=utf-8");
header.put("Content-Length", req.length() + "");
return BaseBaidu.getConvertResult(OkHttpUtils.getInstance().postJson(URL, req, header));
}
/**
* 获取账号报告的参数
* @param entity
* @return
*/
private static String getParams(BaiduConvertEntity entity)
{
String time = DateUtils.getTime();
Map<String, Object> convertType = new HashMap<>();
convertType.put("logidUrl", entity.getLogidUrl());
convertType.put("uid", entity.getUid());
convertType.put("deviceType", entity.getDeviceType()); // 设备: 0 android, 1 ios, 2 其它
convertType.put("clickTime", time);
convertType.put("convertTime", time);
convertType.put("isConvert", 1); // 0 未发生转化,1 为发生转化,2 缺失转化。目前为1
// 转化类型: 1 咨询按钮点击, 2 电话按钮点击,3 表单提交成功, 4 购买成功, 17 api 三句话, 18 api 留线索
convertType.put("convertType", entity.getConvertType());
Map<String, Object> body = new HashMap<>();
body.put("conversionTypes", convertType);
body.put("token", entity.getToken());
String req = JsonUtils.toJson(body);
log.info("[百度推广-数据回传]请求参数:" + req);
return req;
}
}