|
|
@@ -1,5 +1,20 @@
|
|
|
package com.ytpm.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ytpm.advertise.param.AddPlacementParam;
|
|
|
+import com.ytpm.advertise.param.AppAuthContent;
|
|
|
+import com.ytpm.advertise.param.AuthContent;
|
|
|
+import com.ytpm.advertise.param.Network;
|
|
|
+import com.ytpm.advertise.param.NetworkAppInfo;
|
|
|
+import com.ytpm.advertise.param.PlacementListParam;
|
|
|
+import com.ytpm.advertise.param.PlacementParam;
|
|
|
+import com.ytpm.enums.AdPlatformTypeEnum;
|
|
|
+import com.ytpm.enums.AndroidFirstCategoryEnum;
|
|
|
+import com.ytpm.enums.AndroidSecondCategoryEnum;
|
|
|
+import com.ytpm.advertise.param.AddAppParam;
|
|
|
+import com.ytpm.enums.OpenReportEnum;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
@@ -12,25 +27,17 @@ import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
import java.net.URL;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
+@Slf4j(topic = "Taku请求工具类")
|
|
|
public class TakuRequestUtil {
|
|
|
|
|
|
+ private final static String DOMAIN = "https://openapi.toponad.com";
|
|
|
public final static String CONTENT_TYPE = "application/json";
|
|
|
- public final static String PUBLISHER_KEY = "537981a7286b9b3dd2ba02609fe22ceeaccbf896";
|
|
|
+ public final static String PUBLISHER_KEY = "d4b80bef5f946f618c9e781070aedbf2b1a073d4";
|
|
|
|
|
|
public static void main(String[] args){
|
|
|
- // POST example:
|
|
|
- System.out.println("post response: " + doRequest(HttpPost.METHOD_NAME, "https://openapi.toponad.com/v1/apps", "{\"limit\":1}"));
|
|
|
- // GET example:
|
|
|
-// System.out.println("get response: " + doRequest(HttpGet.METHOD_NAME, "https://openapi.toponad.com/v1/waterfall/units?placement_id=xxx", ""));
|
|
|
- }
|
|
|
-
|
|
|
- public String doPost(String url, String reqBody) {
|
|
|
- return doRequest(HttpPost.METHOD_NAME, url, reqBody);
|
|
|
- }
|
|
|
-
|
|
|
- public String doGet(String url, String reqBody) {
|
|
|
- return this.doRequest(HttpGet.METHOD_NAME, url, "");
|
|
|
+ System.err.println(doRequest(HttpGet.METHOD_NAME, DOMAIN+"/v1/networks", ""));
|
|
|
}
|
|
|
|
|
|
public static String doRequest(String httpMethod, String reqUrl, String reqBody) {
|
|
|
@@ -49,7 +56,7 @@ public class TakuRequestUtil {
|
|
|
// TODO
|
|
|
}
|
|
|
// create the final signature
|
|
|
- String contentMD5 = DigestUtils.md5Hex(reqBody).toUpperCase();
|
|
|
+ String contentMD5 = Objects.nonNull(reqBody)?DigestUtils.md5Hex(reqBody).toUpperCase():"";
|
|
|
String nowMillis = System.currentTimeMillis() + "";
|
|
|
String headerStr = "X-Up-Key:" + PUBLISHER_KEY + "\n" + "X-Up-Timestamp:" + nowMillis;
|
|
|
String relativePath = new URL(reqUrl).getPath();
|
|
|
@@ -59,14 +66,19 @@ public class TakuRequestUtil {
|
|
|
httpRequest.setHeader("X-Up-Timestamp", nowMillis);
|
|
|
httpRequest.setHeader("X-Up-Key", PUBLISHER_KEY);
|
|
|
httpRequest.setHeader("X-Up-Signature", finalSign);
|
|
|
-
|
|
|
+ log.debug("尝试向{}发送请求:请求类型{}, 请求内容:{}", httpMethod, reqUrl, reqBody);
|
|
|
HttpResponse response = httpClient.execute(httpRequest);
|
|
|
- if (response != null) {
|
|
|
- HttpEntity resEntity = response.getEntity();
|
|
|
- result = resEntity != null ? EntityUtils.toString(resEntity, "utf-8") : "";
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ HttpEntity resEntity = response.getEntity();
|
|
|
+ result = resEntity != null ? EntityUtils.toString(resEntity, "utf-8") : "";
|
|
|
+ if(200!=statusCode){
|
|
|
+ JSONObject obj = JSON.parseObject(result);
|
|
|
+ throw new RuntimeException("错误码:" + statusCode + "\n message:"+obj.getString("errors"));
|
|
|
}
|
|
|
+ log.debug("result:{}", result);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -84,4 +96,36 @@ public class TakuRequestUtil {
|
|
|
append(relativePath);
|
|
|
return DigestUtils.md5Hex(buf.toString()).toUpperCase();
|
|
|
|
|
|
- }}
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String sendWxRequest(String httpMethod, String reqUrl, String reqBody){
|
|
|
+ String result = null;
|
|
|
+ try{
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ HttpRequestBase httpRequest = null;
|
|
|
+ if (httpMethod.equals(HttpPost.METHOD_NAME)) {
|
|
|
+ HttpPost httpPost = new HttpPost(reqUrl);
|
|
|
+ httpPost.setEntity(new StringEntity(reqBody,"utf-8")); // 兼容中文
|
|
|
+// httpPost.setEntity(new StringEntity(reqBody));
|
|
|
+ httpRequest = httpPost;
|
|
|
+ } else if (httpMethod.equals(HttpGet.METHOD_NAME)) {
|
|
|
+ httpRequest = new HttpGet(reqUrl);
|
|
|
+ }
|
|
|
+ httpRequest.setHeader("Content-Type", CONTENT_TYPE);
|
|
|
+ log.debug("尝试向{}发送请求:请求类型{}, 请求内容:{}", httpMethod, reqUrl, reqBody);
|
|
|
+ HttpResponse response = httpClient.execute(httpRequest);
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ HttpEntity resEntity = response.getEntity();
|
|
|
+ result = resEntity != null ? EntityUtils.toString(resEntity, "utf-8") : "";
|
|
|
+ if(200!=statusCode){
|
|
|
+ JSONObject obj = JSON.parseObject(result);
|
|
|
+ throw new RuntimeException("错误码:" + statusCode + "\n message:"+obj.getString("errors"));
|
|
|
+ }
|
|
|
+ log.debug("result:{}", result);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|