ErpQueryServiceImpl.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.uas.credit.service.impl;
  2. import com.uas.credit.config.PyConfig;
  3. import com.uas.credit.service.EnterpriseDeptService;
  4. import com.uas.credit.service.EnterpriseService;
  5. import com.uas.credit.service.ErpQueryService;
  6. import com.uas.credit.service.PersonalService;
  7. import com.uas.credit.util.HttpUtils;
  8. import org.apache.http.HttpResponse;
  9. import org.apache.http.util.EntityUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import java.io.IOException;
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. /**
  16. * 查询入口
  17. * created by shicr on 2018/6/6
  18. **/
  19. @Service
  20. public class ErpQueryServiceImpl implements ErpQueryService {
  21. @Autowired
  22. private EnterpriseService enterpriseService;
  23. @Autowired
  24. private PersonalService personalService;
  25. @Autowired
  26. private EnterpriseDeptService enterpriseDeptService;
  27. @Autowired
  28. private PyConfig pyConfig;
  29. public String requestApi(String host, String path,String query) {
  30. // https双向认证使用,配合PySSLContextUtil中的DefaultSSLContext
  31. // System.setProperty("javax.net.debug", "all");
  32. // System.setProperty("javax.net.ssl.keyStore", PyConfig.KEYSTORE_FILE);
  33. // System.setProperty("javax.net.ssl.keyStorePassword", PyConfig.KEYSTORE_PASSWORD);
  34. // System.setProperty("javax.net.ssl.trustStore", PyConfig.TRUSTSTORE_FILE);
  35. // System.setProperty("javax.net.ssl.trustStorePassword", PyConfig.TRUSTSTORE_PASSWORD);
  36. Map<String, String> headers = new HashMap<String, String>();
  37. Map<String, String> querys = null;
  38. Map<String, String> bodys = new HashMap<String, String>();
  39. //默认请求条件是JSON格式.如果请求条件是xml,需要指定格式。
  40. //bodys.put("format","xml")
  41. bodys.put("userID", pyConfig.getUserId());
  42. bodys.put("password", pyConfig.getPassword());
  43. bodys.put("queryCondition", query);
  44. HttpResponse response = null;
  45. try {
  46. response = HttpUtils.doPost(host, path, "POST", headers, querys, bodys);
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. String result = null;
  51. try {
  52. result = EntityUtils.toString(response.getEntity());
  53. } catch (IOException e) {
  54. e.printStackTrace();
  55. }
  56. return result;
  57. }
  58. }