代码:
public static void main(String[] args) { String host = "http://aliyunverifyidcard.haoservice.com"; String path = "/idcard/VerifyIdcardv2"; String method = "GET"; String appcode = "你自己的AppCode"; Map<String, String> headers = new HashMap<String, String>(); //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", "APPCODE " + appcode); Map<String, String> querys = new HashMap<String, String>(); querys.put("cardNo", "330329199001020022"); querys.put("realName", "张三"); try { /** * 重要提示如下: * 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 */ HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys); System.out.println(response.toString()); //获取response的body //System.out.println(EntityUtils.toString(response.getEntity())); } catch (Exception e) { e.printStackTrace(); } }
返回成功数据:
{ "error_code": 0, "reason": "Success", "result": { "realname": "张三", /*真实姓名*/ "idcard": "330329199001020022", /*身份证号码*/ "isok": false /*true:匹配 false:不匹配*/ , "IdCardInfor": { "area": "山西省太原市清徐县", "sex": "男", "birthday": "1985-4-10" } } }
返回失败数据:
{ "error_code": 206501, "reason": "NoExistERROR", "result": { "realname": "张三", "idcard": "110115198004232418", "isok": false } }