| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package com.uas.credit.service.impl;
- import com.uas.credit.config.PyConfig;
- import com.uas.credit.service.EnterpriseDeptService;
- import com.uas.credit.service.EnterpriseService;
- import com.uas.credit.service.ErpQueryService;
- import com.uas.credit.service.PersonalService;
- import com.uas.credit.util.HttpUtils;
- import org.apache.http.HttpResponse;
- import org.apache.http.util.EntityUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * 查询入口
- * created by shicr on 2018/6/6
- **/
- @Service
- public class ErpQueryServiceImpl implements ErpQueryService {
- @Autowired
- private EnterpriseService enterpriseService;
- @Autowired
- private PersonalService personalService;
- @Autowired
- private EnterpriseDeptService enterpriseDeptService;
- @Autowired
- private PyConfig pyConfig;
- public String requestApi(String host, String path,String query) {
- // https双向认证使用,配合PySSLContextUtil中的DefaultSSLContext
- // System.setProperty("javax.net.debug", "all");
- // System.setProperty("javax.net.ssl.keyStore", PyConfig.KEYSTORE_FILE);
- // System.setProperty("javax.net.ssl.keyStorePassword", PyConfig.KEYSTORE_PASSWORD);
- // System.setProperty("javax.net.ssl.trustStore", PyConfig.TRUSTSTORE_FILE);
- // System.setProperty("javax.net.ssl.trustStorePassword", PyConfig.TRUSTSTORE_PASSWORD);
- Map<String, String> headers = new HashMap<String, String>();
- Map<String, String> querys = null;
- Map<String, String> bodys = new HashMap<String, String>();
- //默认请求条件是JSON格式.如果请求条件是xml,需要指定格式。
- //bodys.put("format","xml")
- bodys.put("userID", pyConfig.getUserId());
- bodys.put("password", pyConfig.getPassword());
- bodys.put("queryCondition", query);
- HttpResponse response = null;
- try {
- response = HttpUtils.doPost(host, path, "POST", headers, querys, bodys);
- } catch (Exception e) {
- e.printStackTrace();
- }
- String result = null;
- try {
- result = EntityUtils.toString(response.getEntity());
- } catch (IOException e) {
- e.printStackTrace();
- }
- return result;
- }
- }
|