Browse Source

Merge branch 'master' of http://git.shengws.com/csx/gdyb

csx 4 years ago
parent
commit
fb66ac6164
3 changed files with 72 additions and 30 deletions
  1. 1 1
      controllers/sg/gdyb_controller.go
  2. 8 21
      controllers/sg/his_api_controller.go
  3. 63 8
      service/gdyb_service.go

+ 1 - 1
controllers/sg/gdyb_controller.go View File

@@ -79,7 +79,7 @@ func (c *GdybController) PostOne() {
79 79
 	id_card_type, _ := c.GetInt64("id_card_type")
80 80
 	card_sn := c.GetString("card_sn")
81 81
 
82
-	result := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type, card_sn, "44022919620927046X")
82
+	result := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type, card_sn)
83 83
 
84 84
 	var dat map[string]interface{}
85 85
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {

+ 8 - 21
controllers/sg/his_api_controller.go View File

@@ -3824,30 +3824,17 @@ func (c *HisApiController) GetPatientInfo() {
3824 3824
 	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
3825 3825
 	config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
3826 3826
 	if config.IsOpen == 1 {
3827
-		api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_no + "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
3828
-		resp, requestErr := http.Get(api)
3829
-		if requestErr != nil {
3830
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3831
-			return
3832
-		}
3833
-		defer resp.Body.Close()
3834
-		body, ioErr := ioutil.ReadAll(resp.Body)
3835
-		if ioErr != nil {
3836
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
3837
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3838
-			return
3839
-		}
3840
-		var respJSON map[string]interface{}
3841 3827
 
3842
-		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
3843
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
3844
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
3845
-			return
3828
+		result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
3829
+		var dat map[string]interface{}
3830
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
3831
+			fmt.Println(dat)
3832
+		} else {
3833
+			fmt.Println(err)
3846 3834
 		}
3847 3835
 
3848
-		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
3849
-		userJSONBytes, _ := json.Marshal(userJSON)
3850
-		var res ResultTwo
3836
+		userJSONBytes, _ := json.Marshal(dat)
3837
+		var res ResultFourteen
3851 3838
 		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
3852 3839
 			utils.ErrorLog("解析失败:%v", err)
3853 3840
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)

+ 63 - 8
service/gdyb_service.go View File

@@ -82,13 +82,12 @@ func Gdyb1201(certNo string, org_name string, doctor string, fixmedins_code stri
82 82
 }
83 83
 
84 84
 // 人员基本信息
85
-func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, id_card_no string) string {
86
-	// 生成签名
85
+func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string) string {
86
+	//生成签名
87 87
 	nonce := GetRandomString(32)
88 88
 	timestamp := time.Now().Unix()
89 89
 	signature := setSignature(timestamp, nonce, secret_key)
90
-
91
-	// 生成输入报文
90
+	//生成输入报文
92 91
 	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
93 92
 	input := make(map[string]interface{})
94 93
 	inputData := make(map[string]interface{})
@@ -97,10 +96,7 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
97 96
 	if id_card_type == 1 {
98 97
 		inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
99 98
 		inputData["card_sn"] = card_sn      // 卡识别码
100
-		inputData["certno"] = id_card_no    // 证件号码
101
-		//inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
102
-		//inputData["card_sn"] = ""           // 卡识别码
103
-		//inputData["certno"] = certNo        // 证件号码
99
+		inputData["certno"] = certNo        // 证件号码
104 100
 	} else {
105 101
 		inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
106 102
 		inputData["card_sn"] = ""           // 卡识别码
@@ -152,6 +148,65 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
152 148
 	return str
153 149
 }
154 150
 
151
+func Gdyb1101A(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
152
+	//生成签名
153
+	nonce := GetRandomString(32)
154
+	timestamp := time.Now().Unix()
155
+	signature := setSignature(timestamp, nonce, secret_key)
156
+	//生成输入报文
157
+	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
158
+	input := make(map[string]interface{})
159
+	inputData := make(map[string]interface{})
160
+	inputMessage["infno"] = "1101"      // 交易编码
161
+	inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
162
+	inputData["card_sn"] = ""           // 卡识别码
163
+	inputData["certno"] = certNo        // 证件号码
164
+	inputData["psn_cert_type"] = "1"    // 人员证件类型
165
+	inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
166
+	inputData["begntime"] = ""          // 开始时间
167
+	inputData["psn_name"] = ""          // 人员姓名
168
+	input["data"] = inputData
169
+	inputMessage["input"] = input //交易输入
170
+
171
+	bytesData, err := json.Marshal(inputMessage)
172
+	fmt.Println(string(bytesData))
173
+	if err != nil {
174
+		fmt.Println(err.Error())
175
+		return err.Error()
176
+	}
177
+	reader := bytes.NewReader(bytesData)
178
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
179
+	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
180
+
181
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
182
+	request, err := http.NewRequest("POST", url, reader)
183
+	if err != nil {
184
+		fmt.Println(err.Error())
185
+		return err.Error()
186
+	}
187
+
188
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
189
+	request.Header.Set("x-tif-paasid", "test_hosp")
190
+	request.Header.Set("x-tif-signature", signature)
191
+	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
192
+	request.Header.Set("x-tif-nonce", nonce)
193
+
194
+	client := http.Client{}
195
+	resp, err := client.Do(request)
196
+	if err != nil {
197
+		fmt.Println(err.Error())
198
+		return err.Error()
199
+	}
200
+	respBytes, err := ioutil.ReadAll(resp.Body)
201
+	if err != nil {
202
+		fmt.Println(err.Error())
203
+		return err.Error()
204
+	}
205
+	fmt.Println(string(respBytes))
206
+	str := string(respBytes)
207
+	return str
208
+}
209
+
155 210
 // 门诊挂号
156 211
 func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64) string {
157 212
 	// 生成签名