|
|
@@ -1,7 +1,11 @@
|
|
|
package cn.tr.module.smart.wx.utils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import cn.tr.core.utils.JsonUtils;
|
|
|
import cn.tr.module.smart.wx.controller.vo.IdCardInfoVO;
|
|
|
@@ -13,33 +17,54 @@ import okhttp3.RequestBody;
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
public class Id2Utils {
|
|
|
- private static String url = "https://idenauthen.market.alicloudapi.com/idenAuthentication";
|
|
|
- private static String appCode = "0b50e932833a476b96d6aafae04d95b0";
|
|
|
+ private static String url = "https://kzidcardv1.market.alicloudapi.com/api-mall/api/id_card/check";
|
|
|
+ private static String appCode = "83359fd73fe94948385f570e3c139105";
|
|
|
|
|
|
public static IdCardInfoVO getInfo(String name, String idNo) throws IOException {
|
|
|
return postData(appCode, url, name, idNo);
|
|
|
}
|
|
|
|
|
|
private static IdCardInfoVO postData(String appCode, String url, String name, String idNo) throws IOException {
|
|
|
- String result = "";
|
|
|
- RequestBody formBody = new FormBody.Builder().add("name", name).add("idNo", idNo).build();
|
|
|
- Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(formBody).build();
|
|
|
-
|
|
|
+ String method = "POST";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appCode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ RequestBody formBody = new FormBody.Builder().add("name", name).add("idcard", idNo).build();
|
|
|
+ Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode)
|
|
|
+ .addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")
|
|
|
+ .post(formBody).build();
|
|
|
+
|
|
|
+
|
|
|
Call call = new OkHttpClient().newCall(request);
|
|
|
Response response = null;
|
|
|
try {
|
|
|
- response = call.execute();
|
|
|
+ response = call.execute();
|
|
|
} catch (IOException e) {
|
|
|
- System.out.println("execute failed, message:" + e.getMessage());
|
|
|
+ System.out.println("execute failed, message:" + e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
assert response != null;
|
|
|
if (!response.isSuccessful()) { // 当返回结果发生错误时
|
|
|
- // 状态码为403时一般是套餐包用尽,需续购;注意:续购不会改变秘钥(appCode),仅增加次数
|
|
|
- // 续购链接:https://market.aliyun.com/products/57000002/cmapi025518.html
|
|
|
- System.out.println("request failed----" + "返回状态码" + response.code() + ",message:" + response.message());
|
|
|
+ // 状态码为403时一般是套餐包用尽,需续购;注意:续购不会改变秘钥(appCode),仅增加次数
|
|
|
+ // 续购链接:https://market.aliyun.com/products/57000002/cmapi025518.html
|
|
|
+ System.out.println("request failed----" + "返回状态码" + response.code() + ",message:" + response.message());
|
|
|
}
|
|
|
- result = response.body().string(); //此处不可以使用toString()方法,该方法已过期
|
|
|
+ String result = response.body().string(); //此处不可以使用toString()方法,该方法已过期
|
|
|
return JsonUtils.parseObject(result, IdCardInfoVO.class);
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+ System.out.println(getInfo("李放", "410728199802040031"));
|
|
|
+ }
|
|
|
}
|