IdCardUtil.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.kmall.api.util;
  2. import com.kmall.manager.manager.common.CommonPropertiesBuilder;
  3. import org.apache.http.HttpResponse;
  4. import org.apache.http.util.EntityUtils;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. /**
  8. * @author huangyaqin
  9. * @version 1.0
  10. * 2018-10-16 11:27
  11. */
  12. public class IdCardUtil {
  13. //编码格式。发送编码格式统一用UTF-8
  14. private static String ENCODING = "UTF-8";
  15. /**
  16. * 实名校验
  17. * 方法说明
  18. * @Discription:扩展说明
  19. * @return
  20. * @return String
  21. */
  22. @SuppressWarnings("deprecation")
  23. public static String checkIdCard(String idNo,String name) {
  24. String appcode = CommonPropertiesBuilder.instance().getIdCardApiKey();
  25. String host = CommonPropertiesBuilder.instance().getIdCardUrl();
  26. // String appcode = "6a4e3f16f85843cb9575b14cf93aeded";
  27. // String host = "https://idenauthen.market.alicloudapi.com";
  28. String path = "/idenAuthentication";
  29. String method = "POST";
  30. Map<String, String> headers = new HashMap<String, String>();
  31. //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
  32. headers.put("Authorization", "APPCODE " + appcode);
  33. //根据API的要求,定义相对应的Content-Type
  34. headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  35. Map<String, String> querys = new HashMap<String, String>();
  36. Map<String, String> bodys = new HashMap<String, String>();
  37. bodys.put("idNo", idNo);
  38. bodys.put("name", name);
  39. HttpResponse response = null;
  40. try {
  41. response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
  42. //获取response的body
  43. return EntityUtils.toString(response.getEntity());
  44. } catch (Exception e) {
  45. e.printStackTrace();
  46. }
  47. return "";
  48. }
  49. /**
  50. * 测试
  51. * 方法说明
  52. * @Discription:扩展说明
  53. * @param args
  54. * @return void
  55. */
  56. public static void main(String[] args) {
  57. // System.out.println(SendMsgUtil.createRandomVcode());
  58. // System.out.println("&ecb=12".substring(1));
  59. System.out.println(checkIdCard("", ""));
  60. }
  61. }