package com.poi.poiDemo.NutTest;
import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
public class Nuttest2 {
private String clientId = "071b9b1a6de50bbee77736c46704b3ab";
private String clientSecret = "59d33ca94ad0dd6c097b6b1dedc05bc8";
private String url = "https://sqdapi.u51.com";
private final HttpClient client = new HttpClient();
@Test
public void token() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("client_id", clientId);
params.put("client_secret", clientSecret);
HttpRequest request = HttpRequest.post(url + "/openapi/api/v3/oauth2/token").body(JSON.toJSONString(params))
.header("Content-Type", "application/json");
HttpResponse response = request.send();
System.out.println(response.body());
}
// 获取账户id
@Test
public void accountId() throws HttpException, IOException {
GetMethod method = new GetMethod(url + "/openapi/api/v2/crawler/CARRIER/serviceAccounts");
method.addRequestHeader("Content-Type", "application/json;charset=UTF-8");
method.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
method.addRequestHeader("userId", "0_1000031897_10000020");
client.executeMethod(method);
// 返回报告的json信息
String res = new String(method.getResponseBodyAsString());
System.out.println("\n\n返回报告的json信息:" + res + "\n\n");
}
// 获取号码信息
@Test
public void phoneMessage() throws HttpException, IOException {
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
String uri = "/openapi/api/v2/carrier/0_1000031897_10000020/" + phoneId + "/personal-info";
GetMethod method = new GetMethod(url + uri);
method.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(method);
// 返回报告的json信息
String res = new String(method.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 星级信用分信息
@Test
public void creditScore() throws HttpException, IOException {
PostMethod postmethod = new PostMethod(url + "/openapi/api/v2/carrier/phones/creditstar");
Map<String, Object> params = new HashMap<String, Object>();
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
params.put("phoneId", phoneId);
params.put("startDate", "2015-08-24");
params.put("endDate", "2018-10-10");
RequestEntity entity = new StringRequestEntity(JSON.toJSONString(params), "application/json", "UTF-8");
postmethod.setRequestEntity(entity);
postmethod.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(postmethod);
// 返回报告的json信息
String res = new String(postmethod.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 获取账单信息
@Test
public void bill() throws HttpException, IOException {
PostMethod postmethod = new PostMethod(url + "/openapi/api/v2/carrier/phones/billList");
Map<String, Object> params = new HashMap<String, Object>();
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
params.put("phoneId", phoneId);
params.put("startDate", "2018-09-30");
params.put("endDate", "2018-10-10");
RequestEntity entity = new StringRequestEntity(JSON.toJSONString(params), "application/json", "UTF-8");
postmethod.setRequestEntity(entity);
postmethod.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(postmethod);
// 返回报告的json信息
String res = new String(postmethod.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 通话详单
@Test
public void dialtype() throws HttpException, IOException {
PostMethod postmethod = new PostMethod(url + "/openapi/api/v2/carrier/phones/callrecords");
Map<String, Object> params = new HashMap<String, Object>();
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
params.put("phoneId", phoneId);
params.put("startDate", "2018-09-01");
params.put("endDate", "2018-09-10");
RequestEntity entity = new StringRequestEntity(JSON.toJSONString(params), "application/json", "UTF-8");
postmethod.setRequestEntity(entity);
postmethod.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(postmethod);
// 返回报告的json信息
String res = new String(postmethod.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 短信详单
@Test
public void sms() throws HttpException, IOException {
PostMethod postmethod = new PostMethod(url + "/openapi/api/v2/carrier/phones/smsrecords");
Map<String, Object> params = new HashMap<String, Object>();
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
params.put("phoneId", phoneId);
params.put("startDate", "2018-09-01");
params.put("endDate", "2018-09-10");
RequestEntity entity = new StringRequestEntity(JSON.toJSONString(params), "application/json", "UTF-8");
postmethod.setRequestEntity(entity);
postmethod.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(postmethod);
// 返回报告的json信息
String res = new String(postmethod.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 充值记录
@Test
public void money() throws HttpException, IOException {
PostMethod postmethod = new PostMethod(url + "/openapi/api/v2/carrier/phones/recharges");
Map<String, Object> params = new HashMap<String, Object>();
String phoneId = "45f3b230-cc32-11e8-9943-0200506b00e6";
params.put("phoneId", phoneId);
params.put("startDate", "2018-09-30");
params.put("endDate", "2018-10-10");
RequestEntity entity = new StringRequestEntity(JSON.toJSONString(params), "application/json", "UTF-8");
postmethod.setRequestEntity(entity);
postmethod.addRequestHeader("Authorization",
"Bearer v3-access2a2b80c2cab448d3a042c5ac8ebd5a7f8e5aa1880dc4fc46a8e57e0c69c6c492");
client.executeMethod(postmethod);
// 返回报告的json信息
String res = new String(postmethod.getResponseBodyAsString());
System.out.println("返回报告的json信息:" + res);
}
// 获取任务状态
@Test
public void task() throws HttpException, IOException {
String taskId = "";
String uri = "/openapi/api/v3/crawler/tasks/" + taskId + "/status";
GetMethod method = new GetMethod(url + uri);
method.addR