package com.kmall.api.util; import com.kmall.manager.manager.common.CommonPropertiesBuilder; import org.apache.http.HttpResponse; import org.apache.http.util.EntityUtils; import java.util.HashMap; import java.util.Map; /** * @author huangyaqin * @version 1.0 * 2018-10-16 11:27 */ public class IdCardUtil { //编码格式。发送编码格式统一用UTF-8 private static String ENCODING = "UTF-8"; /** * 实名校验 * 方法说明 * @Discription:扩展说明 * @return * @return String */ @SuppressWarnings("deprecation") public static String checkIdCard(String idNo,String name) { String appcode = CommonPropertiesBuilder.instance().getIdCardApiKey(); String host = CommonPropertiesBuilder.instance().getIdCardUrl(); // String appcode = "6a4e3f16f85843cb9575b14cf93aeded"; // String host = "https://idenauthen.market.alicloudapi.com"; String path = "/idenAuthentication"; String method = "POST"; Map headers = new HashMap(); //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", "APPCODE " + appcode); //根据API的要求,定义相对应的Content-Type headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Map querys = new HashMap(); Map bodys = new HashMap(); bodys.put("idNo", idNo); bodys.put("name", name); HttpResponse response = null; try { response = HttpUtils.doPost(host, path, method, headers, querys, bodys); //获取response的body return EntityUtils.toString(response.getEntity()); } catch (Exception e) { e.printStackTrace(); } return ""; } /** * 测试 * 方法说明 * @Discription:扩展说明 * @param args * @return void */ public static void main(String[] args) { // System.out.println(SendMsgUtil.createRandomVcode()); // System.out.println("&ecb=12".substring(1)); System.out.println(checkIdCard("", "")); } }