1.3-业务接口调用示例
业务接口示例代码 (查看接单人)
调用代码
@Test
public void getPersonList() throws Exception {
CloseableHttpClient client =
HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
Map responseMap = JSONObject.parseObject(context, Map.class);
String tokenStr = MapUtils.getString(responseMap, "access_token");
HttpPost personListPost =
new HttpPost("https://{domain}/task/openapi/v1/person/list");
personListPost.setHeader("Content-Type","application/json");
//head里放入getToken所获取的token
personListPost.setHeader("Authorization", "Bearer " + TOKEN);
CloseableHttpResponse personListResponse = client.execute(personListPost);
HttpEntity personListEntity = personListResponse.getEntity();
int personListStatusCode = personListResponse.getStatusLine().getStatusCode();
System.out.println("响应状态码:" + personListStatusCode);
String personListContext = EntityUtils.toString(personListEntity, "utf-8");
System.out.println("响应内容:" + personListContext);
client.close();
personListResponse.close();
}
输出结果
响应状态码: 200
响应内容:{"msg":"请求成功","code":"200","success":true,"data":[
{
"personName": "张三",
"cardNo": "432112190012345678",
"phone": "13111111111",
"bankName": "交通银行",
"bankAccount": "6222888888888888888",
"certified": null,
"createTime": "2019-10-30T19:40:53.000+0000"
},
{
"personName": "李四",
"cardNo": "330781198509078935",
"phone": "13211111111",
"bankName": "交通银行",
"bankAccount": "6222111111111111111",
"certified": null,
"createTime": "2019-10-30T19:47:48.000+0000"
}]
}