1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<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");
- Map<String, String> querys = new HashMap<String, String>();
- Map<String, String> bodys = new HashMap<String, String>();
- 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("", ""));
- }
- }
|