您的位置:首页 > 其它

实名认证二要素查询调用阿里接口

2017-11-08 16:54 344 查看
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**author xxx
* @version 1.0
* Created by Administrator on 2017/11/2.
*/
public class IdCardCheck {
public static JSONObject IdCardCheck(String certificationName, String cardId) {
String host = "http://1.api.apistore.cn";
String path = "/idcard";
String method = "GET";
String appcode = "申请你自己的appcode";//在阿里云上面购买实名认证2要素接口以后就可以获得
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<String, String>();
querys.put("cardNo", cardId);
querys.put("realName", certificationName);
HttpResponse response = null;
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/[/code] 
src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml */
response =  HttpUtils.doGet(host, path, method, headers, querys);
JSONObject jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
JSONObject json = JSONObject.parseObject(String.valueOf(jsonObject));
JSONObject result= (JSONObject) json.get("result");
return result;
} catch (Exception e) {
e.printStackTrace();
}
return new JSONObject();
}

public static void main(String[] args) {
IdCardCheck.IdCardCheck("张三", "输入你查的身份证号");

System.out.println(IdCardCheck.IdCardCheck("张三", "输入你查的身份证号"));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: