<dependency> <groupId>com.baidubce</groupId> <artifactId>api-explorer-sdk</artifactId> <version>1.0.0</version> </dependency>
import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
// 实时快递查询 Java示例代码
public class RequestDemo {
public static void main(String[] args) {
String path = "http://kuaidi100.api.bdymkt.com/apisearch.do";
ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
request.setCredentials("您的 access key", "您的 secret key");
request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded");
String requestExample = "nu=550012024245545&com=huitongkuaidi&phone=13500000000\r\n";
request.setJsonBody(requestExample);
ApiExplorerClient client = new ApiExplorerClient(new AppSigner());
try {
ApiExplorerResponse response = client.sendRequest(request);
// 返回结果格式为Json字符串
System.out.println(response.getResult());
} catch (Exception e) {
e.printStackTrace();
}
}
}
点击复制代码
正常返回示例 {"name":"百世快递",
"icon":"https://cdn.kuaidi100.com/images/all/56/huitongkuaidi.png",
"tel":"95320",
"url":"http://www.800bestex.com/",
"detailUrl":"https://m.kuaidi100.com/result.jsp?com=huitongkuaidi&nu=550012024245545",
"com":"huitongkuaidi",
"nu":"550012024245545",
"state":"3",
"message":"ok",
"status":"1",
"stateName":"已签收",
"data":null,
"context":"深圳市|已签收,签收人凭取货码签收。",
"time":"2021-03-12 18:39:41"}
失败返回示例 {
"message":"ok",
"state":"0",
"status":"400",
}
错误码定义 0 (0%) 好评 | 0 (0%) 中评 | 0 (0%) 差评 |