Browse Source

测试代码开发

hurugang 5 years ago
parent
commit
456bd8c845

+ 15 - 16
src/main/java/cn/hnthyy/thmz/controller/api/MedicalViewApiController.java

@@ -53,30 +53,29 @@ public class MedicalViewApiController {
     private static final String ZFB="ZFB";
     /**
      * 患者信息查询
-     * @param itemType
-     * @param itemNo
+     * @param haicipat
      * @return
      */
-    @UserLoginToken
-    @RequestMapping(value="/queryPatientInfo/{itemType}/{itemNo}",method = {RequestMethod.GET})
-    public Map<String,Object> queryPatientInfo(@PathVariable String itemType,@PathVariable String itemNo) {
+    //@UserLoginToken
+    @RequestMapping(value="/queryPatientInfo",method = {RequestMethod.POST})
+    public Map<String,Object> queryPatientInfo(Haicipat haicipat) {
         Map<String,Object> results = new HashMap<>();
-        if(StringUtils.isBlank(itemType)){
+        if(StringUtils.isBlank(haicipat.getPatIdType())){
             results.put("resultCode",-1);
             results.put("resultMessage","顾客证件类型不能为空");
             return results;
         }
-        if(StringUtils.isBlank(itemNo)){
+        if(StringUtils.isBlank(haicipat.getPatIdNo())){
             results.put("resultCode",-1);
             results.put("resultMessage","顾客证件号码不能为空");
             return results;
         }
-        if(!ID_CARD_TYPE.equals(itemType)){
+        if(!ID_CARD_TYPE.equals(haicipat.getPatIdType())){
             results.put("resultCode",-1);
             results.put("resultMessage","顾客证件号码非身份证,暂不支持");
             return results;
         }
-        List<MzPatientMi> mzPatientMis = mzPatientMiService.queryBySocialNo(itemNo,null);
+        List<MzPatientMi> mzPatientMis = mzPatientMiService.queryBySocialNo(haicipat.getPatIdNo(),null);
         if(mzPatientMis==null || mzPatientMis.size()==0){
             results.put("resultCode",-1);
             results.put("resultMessage","没有查询到病人信息");
@@ -102,7 +101,7 @@ public class MedicalViewApiController {
      * @param haicipat
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/savePatientInfo",method = {RequestMethod.POST})
     public Map<String,Object> savePatientInfo(Haicipat haicipat) {
         Map<String,Object> results = new HashMap<>();
@@ -223,7 +222,7 @@ public class MedicalViewApiController {
      * @param haicipat
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/boundPatCardNoInfo",method = {RequestMethod.POST})
     public Map<String,Object> boundPatCardNoInfo(Haicipat haicipat) {
         Map<String,Object> results = new HashMap<>();
@@ -322,7 +321,7 @@ public class MedicalViewApiController {
      * @param haicipat
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/cancelBoundPatCardNoInfo",method = {RequestMethod.POST})
     public Map<String,Object> cancelBoundPatCardNoInfo(Haicipat haicipat) {
         Map<String,Object> results = new HashMap<>();
@@ -417,7 +416,7 @@ public class MedicalViewApiController {
      * @param haicipat
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/getMzChargeDetailForUnPaid",method = {RequestMethod.POST})
     public Map<String,Object> getMzChargeDetailForUnPaid(Haicipat haicipat) {
         Map<String,Object> results = new HashMap<>();
@@ -486,7 +485,7 @@ public class MedicalViewApiController {
      * @param haiciCharge
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/getChargeDetailByHisOrdNum",method = {RequestMethod.POST})
     public Map<String,Object> getChargeDetailByHisOrdNum(HaiciCharge haiciCharge) {
         Map<String,Object> results = new HashMap<>();
@@ -557,7 +556,7 @@ public class MedicalViewApiController {
      * @param haiciCharge
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/payChargeDetailFormHaiCi",method = {RequestMethod.POST})
     public Map<String,Object> payChargeDetailFormHaiCi(HaiciCharge haiciCharge) {
         Map<String,Object> results = new HashMap<>();
@@ -654,7 +653,7 @@ public class MedicalViewApiController {
      * @param haiciCharge
      * @return
      */
-    @UserLoginToken
+    //@UserLoginToken
     @RequestMapping(value="/getPayStatus",method = {RequestMethod.POST})
     public Map<String,Object> getPayStatus(HaiciCharge haiciCharge) {
         Map<String,Object> results = new HashMap<>();

+ 51 - 0
src/test/java/cn/hnthyy/thmz/HttpClientUtil.java

@@ -0,0 +1,51 @@
+package cn.hnthyy.thmz;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/*
+     * 利用HttpClient进行post请求的工具类
+     */
+    public class HttpClientUtil {
+        public String doPost(String url, Map<String,String> map, String charset){
+            HttpClient httpClient = null;
+            HttpPost httpPost = null;
+            String result = null;
+            try{
+                httpClient = new SSLClient();
+                httpPost = new HttpPost(url);
+                //设置参数
+                List<NameValuePair> list = new ArrayList<>();
+                Iterator iterator = map.entrySet().iterator();
+                while(iterator.hasNext()){
+                    Map.Entry<String,String> elem = (Map.Entry<String, String>) iterator.next();
+                    list.add(new BasicNameValuePair(elem.getKey(),elem.getValue()));
+                }
+                if(list.size() > 0){
+                    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset);
+                    httpPost.setEntity(entity);
+                }
+                HttpResponse response = httpClient.execute(httpPost);
+                if(response != null){
+                    HttpEntity resEntity = response.getEntity();
+                    if(resEntity != null){
+                        result = EntityUtils.toString(resEntity,charset);
+                    }
+                }
+            }catch(Exception ex){
+                ex.printStackTrace();
+            }
+            return result;
+        }
+    }

+ 38 - 0
src/test/java/cn/hnthyy/thmz/SSLClient.java

@@ -0,0 +1,38 @@
+package cn.hnthyy.thmz;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+//用于进行Https请求的HttpClient
+public class SSLClient extends DefaultHttpClient{
+	public SSLClient() throws Exception{
+        super();
+        SSLContext ctx = SSLContext.getInstance("TLS");
+        X509TrustManager tm = new X509TrustManager() {
+                @Override
+                public void checkClientTrusted(X509Certificate[] chain,
+                        String authType) throws CertificateException {
+                }
+                @Override
+                public void checkServerTrusted(X509Certificate[] chain,
+                        String authType) throws CertificateException {
+                }
+                @Override
+                public X509Certificate[] getAcceptedIssuers() {
+                    return null;
+                }
+        };
+        ctx.init(null, new TrustManager[]{tm}, null);
+        SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+        ClientConnectionManager ccm = this.getConnectionManager();
+        SchemeRegistry sr = ccm.getSchemeRegistry();
+        sr.register(new Scheme("https", 443, ssf));
+    }
+}

+ 35 - 0
src/test/java/cn/hnthyy/thmz/ThmzApiTests.java

@@ -0,0 +1,35 @@
+package cn.hnthyy.thmz;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ThmzApiTests {
+    private String url = "https://172.16.30.33/thmz/api/v1";
+    private String charset = "utf-8";
+    private HttpClientUtil httpClientUtil = null;
+
+    @Test
+    public String testQueryUserInfo(){
+        String httpOrgCreateTest = url + "httpOrg/create";
+        Map<String,String> createMap = new HashMap<>();
+        createMap.put("authuser","*****");
+        createMap.put("authpass","*****");
+        createMap.put("orgkey","****");
+        createMap.put("orgname","****");
+        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap,charset);
+        System.out.println("result:"+httpOrgCreateTestRtn);
+    }
+
+
+
+}
+