Bladeren bron

医保对接

csx 4 jaren geleden
bovenliggende
commit
6f783fcd69
4 gewijzigde bestanden met toevoegingen van 192 en 75 verwijderingen
  1. 29 29
      controllers/gdyb_controller.go
  2. 54 32
      controllers/his_api_controller.go
  3. 4 0
      enums/error_code.go
  4. 105 14
      service/gdyb_service.go

+ 29 - 29
controllers/gdyb_controller.go Bestand weergeven

@@ -391,40 +391,40 @@ func (c *GdybController) PostTen() {
391 391
 }
392 392
 
393 393
 func (c *GdybController) PostEleven() {
394
-	fmt.Println("777777666666-----")
395
-
396
-	file_byte := c.GetString("file_byte")
397
-	file_name := c.GetString("file_name")
398
-	fixmedins_code := c.GetString("fixmedins_code")
399
-	insuplc_admdvs := c.GetString("insuplc_admdvs")
400
-	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
401
-	secret_key := c.GetString("secret_key")
402
-	org_name := c.GetString("org_name")
403
-	doctor := c.GetString("doctor")
404
-
405
-	baseParams := models.BaseParams{
406
-		SecretKey:      secret_key,
407
-		FixmedinsCode:  fixmedins_code,
408
-		InsuplcAdmdvs:  insuplc_admdvs,
409
-		MdtrtareaAdmvs: mdtrtarea_admvs,
410
-		OrgName:        org_name,
411
-		Doctor:         doctor,
412
-	}
394
+	//fmt.Println("777777666666-----")
395
+	//
396
+	//file_byte := c.GetString("file_byte")
397
+	//file_name := c.GetString("file_name")
398
+	//fixmedins_code := c.GetString("fixmedins_code")
399
+	//insuplc_admdvs := c.GetString("insuplc_admdvs")
400
+	//mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
401
+	//secret_key := c.GetString("secret_key")
402
+	//org_name := c.GetString("org_name")
403
+	//doctor := c.GetString("doctor")
404
+	//
405
+	//baseParams := models.BaseParams{
406
+	//	SecretKey:      secret_key,
407
+	//	FixmedinsCode:  fixmedins_code,
408
+	//	InsuplcAdmdvs:  insuplc_admdvs,
409
+	//	MdtrtareaAdmvs: mdtrtarea_admvs,
410
+	//	OrgName:        org_name,
411
+	//	Doctor:         doctor,
412
+	//}
413 413
 
414 414
 	//x := (*[2]uintptr)(unsafe.Pointer(&file_byte))
415 415
 	//h := [3]uintptr{x[0], x[1], x[1]}
416 416
 	//bytes := *(*[]byte)(unsafe.Pointer(&h))
417 417
 
418
-	result := service.Gdyb9101(baseParams, file_name, []byte(file_byte))
419
-	var dat map[string]interface{}
420
-	if err := json.Unmarshal([]byte(result), &dat); err == nil {
421
-		fmt.Println(dat)
422
-	} else {
423
-		fmt.Println(err)
424
-	}
425
-	c.ServeSuccessJSON(map[string]interface{}{
426
-		"pre": dat,
427
-	})
418
+	//result := service.Gdyb9101(baseParams, file_name, []byte(file_byte))
419
+	//var dat map[string]interface{}
420
+	//if err := json.Unmarshal([]byte(result), &dat); err == nil {
421
+	//	fmt.Println(dat)
422
+	//} else {
423
+	//	fmt.Println(err)
424
+	//}
425
+	//c.ServeSuccessJSON(map[string]interface{}{
426
+	//	"pre": dat,
427
+	//})
428 428
 }
429 429
 
430 430
 func (c *GdybController) PostTwelve() {

+ 54 - 32
controllers/his_api_controller.go Bestand weergeven

@@ -59,7 +59,7 @@ func HisManagerApiRegistRouters() {
59 59
 	beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
60 60
 	beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
61 61
 
62
-	beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
62
+	beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
63 63
 
64 64
 	beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
65 65
 
@@ -1190,6 +1190,7 @@ type ResultSix struct {
1190 1190
 	Signtype    interface{} `json:"signtype"`
1191 1191
 	WarnMsg     interface{} `json:"warn_msg"`
1192 1192
 }
1193
+
1193 1194
 type ResultSeven struct {
1194 1195
 	Cainfo      string `json:"cainfo"`
1195 1196
 	ErrMsg      string `json:"err_msg"`
@@ -1279,6 +1280,22 @@ type ResultNine struct {
1279 1280
 	WarnMsg     interface{} `json:"warn_msg"`
1280 1281
 }
1281 1282
 
1283
+type ResultTen struct {
1284
+	Cainfo      string `json:"cainfo"`
1285
+	ErrMsg      string `json:"err_msg"`
1286
+	InfRefmsgid string `json:"inf_refmsgid"`
1287
+	Infcode     int64  `json:"infcode"`
1288
+	Output      struct {
1289
+		DldEndtime string `json:"dld_endtime"`
1290
+		FileQuryNo string `json:"file_qury_no"`
1291
+		Filename   string `json:"filename"`
1292
+	} `json:"output"`
1293
+	RefmsgTime  string      `json:"refmsg_time"`
1294
+	RespondTime string      `json:"respond_time"`
1295
+	Signtype    interface{} `json:"signtype"`
1296
+	WarnMsg     interface{} `json:"warn_msg"`
1297
+}
1298
+
1282 1299
 type Custom struct {
1283 1300
 	DetItemFeeSumamt string
1284 1301
 	Cut              string
@@ -1893,7 +1910,8 @@ func (c *HisApiController) GetUploadInfo() {
1893 1910
 					}
1894 1911
 				}
1895 1912
 			} else {
1896
-
1913
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
1914
+				return
1897 1915
 			}
1898 1916
 
1899 1917
 		} else {
@@ -2298,36 +2316,30 @@ func (c *HisApiController) GetCheckDetailAccount() {
2298 2316
 
2299 2317
 	}
2300 2318
 	Zip(file_path, zip_path)
2319
+	fmt.Println(ReadFile(zip_path))
2320
+	fmt.Println(string(ReadFile(zip_path)))
2321
+
2301 2322
 	if config.IsOpen == 1 {
2302
-		api := "http://127.0.0.1:9532/" + "gdyb/eleven?" +
2303
-			"file_byte=" + string(ReadFile(zip_path)) +
2304
-			"&file_name=" + zip_name +
2305
-			"&fixmedins_code=" + miConfig.Code +
2306
-			"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
2307
-			"&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
2308
-			"&secret_key=" + miConfig.SecretKey +
2309
-			"&org_name=" + miConfig.OrgName +
2310
-			"&doctor=某人"
2311 2323
 
2312
-		resp, requestErr := http.Get(api)
2313
-		if requestErr != nil {
2314
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2315
-			return
2316
-		}
2317
-		body, ioErr := ioutil.ReadAll(resp.Body)
2318
-		if ioErr != nil {
2319
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2320
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2321
-			return
2324
+		baseParams := models.BaseParams{
2325
+			SecretKey:      miConfig.SecretKey,
2326
+			FixmedinsCode:  miConfig.Code,
2327
+			InsuplcAdmdvs:  miConfig.InsuplcAdmdvs,
2328
+			MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
2329
+			OrgName:        miConfig.OrgName,
2330
+			Doctor:         "某人",
2322 2331
 		}
2323
-		var respJSON map[string]interface{}
2324
-		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2325
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2326
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2327
-			return
2332
+
2333
+		result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
2334
+
2335
+		var dat map[string]interface{}
2336
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
2337
+			fmt.Println(dat)
2338
+		} else {
2339
+			fmt.Println(err)
2328 2340
 		}
2329
-		respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2330
-		userJSONBytes, _ := json.Marshal(respJSON)
2341
+
2342
+		userJSONBytes, _ := json.Marshal(dat)
2331 2343
 
2332 2344
 		var res ResultNine
2333 2345
 		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
@@ -2336,7 +2348,6 @@ func (c *HisApiController) GetCheckDetailAccount() {
2336 2348
 			return
2337 2349
 		}
2338 2350
 		if res.Infcode == 0 {
2339
-
2340 2351
 			api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
2341 2352
 				"file_qury_no=" + res.Output.FileQuryNo +
2342 2353
 				"&setl_optins=" + miConfig.OrgName +
@@ -2352,7 +2363,6 @@ func (c *HisApiController) GetCheckDetailAccount() {
2352 2363
 				"&secret_key=" + miConfig.SecretKey +
2353 2364
 				"&org_name=" + miConfig.OrgName +
2354 2365
 				"&doctor=某人"
2355
-
2356 2366
 			resp, requestErr := http.Get(api)
2357 2367
 			if requestErr != nil {
2358 2368
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -2371,9 +2381,21 @@ func (c *HisApiController) GetCheckDetailAccount() {
2371 2381
 				return
2372 2382
 			}
2373 2383
 			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2384
+
2374 2385
 			userJSONBytes, _ := json.Marshal(respJSON)
2375
-			fmt.Println(respJSON)
2376
-			fmt.Println(userJSONBytes)
2386
+			var res ResultTen
2387
+			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2388
+				utils.ErrorLog("解析失败:%v", err)
2389
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2390
+				return
2391
+			}
2392
+
2393
+			if res.Infcode == 0 {
2394
+				service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
2395
+				c.ServeSuccessJSON(map[string]interface{}{
2396
+					"msg": "明细对账成功",
2397
+				})
2398
+			}
2377 2399
 
2378 2400
 		} else {
2379 2401
 

+ 4 - 0
enums/error_code.go Bestand weergeven

@@ -220,6 +220,8 @@ const ( // ErrorCode
220 220
 	ErrorCodeRegisterTwoException = 20067
221 221
 
222 222
 	ErrorCodeCreateOrderException = 20068
223
+
224
+	ErrorCodeCalOrderException = 20069
223 225
 )
224 226
 
225 227
 var ErrCodeMsgs = map[int]string{
@@ -430,6 +432,8 @@ var ErrCodeMsgs = map[int]string{
430 432
 	ErrorCodeRegisterTwoException: "挂号失败",
431 433
 
432 434
 	ErrorCodeCreateOrderException: "创建预结算订单失败",
435
+
436
+	ErrorCodeCalOrderException: "结算失败",
433 437
 }
434 438
 
435 439
 type SGJError struct {

+ 105 - 14
service/gdyb_service.go Bestand weergeven

@@ -13,7 +13,9 @@ import (
13 13
 	"mime/multipart"
14 14
 	"net/http"
15 15
 	"os"
16
+	"path/filepath"
16 17
 	"strconv"
18
+	"strings"
17 19
 	"time"
18 20
 	_ "unsafe"
19 21
 )
@@ -38,7 +40,7 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
38 40
 	inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
39 41
 	inputData["card_sn"] = ""           // 卡识别码
40 42
 	inputData["begntime"] = ""          // 开始时间
41
-	inputData["psn_cert_type"] = ""     // 人员证件类型
43
+	inputData["psn_cert_type"] = "1"    // 人员证件类型
42 44
 	inputData["certno"] = certNo        // 证件号码
43 45
 	inputData["psn_name"] = ""          // 人员姓名
44 46
 	input["data"] = inputData
@@ -798,23 +800,31 @@ func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams
798 800
 	return str
799 801
 }
800 802
 
803
+type Params struct {
804
+	FileName      string `json:"file_name"`      //产品ID
805
+	In            []byte `json:"in"`             //
806
+	FixmedinsCode string `json:"fixmedins_code"` //调用环境生产为1 沙盒2
807
+}
808
+
809
+//文件上传
801 810
 //文件上传
802 811
 func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string {
803 812
 
804
-	//http.Post(strinUrl,"multipart/form-data",bytes.NewReader(file_byte))
805
-
806 813
 	// 生成签名
807 814
 	nonce := GetRandomString(32)
808 815
 	timestamp := time.Now().Unix()
809 816
 	signature := setSignature(timestamp, nonce, baseParams.SecretKey)
810 817
 
811
-	// 生成输入报文
818
+	buf := new(bytes.Buffer)
819
+	buf.ReadFrom(strings.NewReader(string(file_byte)))
820
+
812 821
 	inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
813 822
 	input := make(map[string]interface{})
814 823
 	inputData := make(map[string]interface{})
824
+
815 825
 	inputMessage["infno"] = "9101"                         // 交易编码
816 826
 	inputData["file_name"] = file_name                     //文件名
817
-	inputData["in"] = file_byte                            //文件数据
827
+	inputData["in"] = bytes.NewBuffer(file_byte).Bytes()   //文件数据
818 828
 	inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
819 829
 
820 830
 	input["fsUploadIn"] = inputData
@@ -857,6 +867,59 @@ func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte)
857 867
 	return str
858 868
 }
859 869
 
870
+func Gdyb9102(baseParams models.BaseParams, file_name string, file_qury_no string) string {
871
+
872
+	// 生成签名
873
+	nonce := GetRandomString(32)
874
+	timestamp := time.Now().Unix()
875
+	signature := setSignature(timestamp, nonce, baseParams.SecretKey)
876
+	inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
877
+	input := make(map[string]interface{})
878
+	inputData := make(map[string]interface{})
879
+	inputMessage["infno"] = "9102"                                 // 交易编码
880
+	inputData["file_name"] = file_name                             //文件名
881
+	inputData["file_qury_no"] = "fsi/H44022900158/" + file_qury_no //文件数据
882
+	inputData["fixmedins_code"] = baseParams.FixmedinsCode         //编码
883
+	input["fsDownloadIn"] = inputData
884
+	inputMessage["input"] = input //交易输入
885
+
886
+	bytesData, err := json.Marshal(inputMessage)
887
+	fmt.Println(string(bytesData))
888
+	if err != nil {
889
+		fmt.Println(err.Error())
890
+		return err.Error()
891
+	}
892
+	reader := bytes.NewReader(bytesData)
893
+
894
+	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9102"
895
+	request, err := http.NewRequest("POST", url, reader)
896
+	if err != nil {
897
+		fmt.Println(err.Error())
898
+		return err.Error()
899
+	}
900
+
901
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
902
+	request.Header.Set("x-tif-paasid", "test_hosp")
903
+	request.Header.Set("x-tif-signature", signature)
904
+	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
905
+	request.Header.Set("x-tif-nonce", nonce)
906
+
907
+	client := http.Client{}
908
+	resp, err := client.Do(request)
909
+	if err != nil {
910
+		fmt.Println(err.Error())
911
+		return err.Error()
912
+	}
913
+	respBytes, err := ioutil.ReadAll(resp.Body)
914
+	if err != nil {
915
+		fmt.Println(err.Error())
916
+		return err.Error()
917
+	}
918
+	str := string(respBytes)
919
+	fmt.Println(str)
920
+	return str
921
+}
922
+
860 923
 func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams) string {
861 924
 	// 生成签名
862 925
 	nonce := GetRandomString(32)
@@ -867,15 +930,15 @@ func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams
867 930
 	inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
868 931
 	input := make(map[string]interface{})
869 932
 	inputData := make(map[string]interface{})
870
-	inputMessage["infno"] = "3202"                                    // 交易编码
871
-	inputData["file_qury_no"] = businessParams.FileQuryNo             // 险种
872
-	inputData["setl_optins"] = baseParams.OrgName                     // 结算经办机构
873
-	inputData["stmt_begndate"] = businessParams.StmtBegndate          // 对帐开始时间
874
-	inputData["stmt_enddate"] = businessParams.StmtEnddate            //对帐结束时间
875
-	inputData["medfee_sumamt"] = businessParams.MedfeeSumamt          //医疗费总额
876
-	inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt       //基金支付总额
877
-	inputData["cash_payamt"] = businessParams.CashPayamt              //现金支付金额
878
-	inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
933
+	inputMessage["infno"] = "3202"                                              // 交易编码
934
+	inputData["file_qury_no"] = "fsi/H44022900158/" + businessParams.FileQuryNo // 险种
935
+	inputData["setl_optins"] = baseParams.OrgName                               // 结算经办机构
936
+	inputData["stmt_begndate"] = businessParams.StmtBegndate                    // 对帐开始时间
937
+	inputData["stmt_enddate"] = businessParams.StmtEnddate                      //对帐结束时间
938
+	inputData["medfee_sumamt"] = businessParams.MedfeeSumamt                    //医疗费总额
939
+	inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt                 //基金支付总额
940
+	inputData["cash_payamt"] = businessParams.CashPayamt                        //现金支付金额
941
+	inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt           //定点医药机构结算笔数
879 942
 
880 943
 	input["data"] = inputData
881 944
 	inputMessage["input"] = input //交易输入
@@ -1261,3 +1324,31 @@ func postFile(filename string, target_url string) (*http.Response, error) {
1261 1324
 //	fmt.Println(str)
1262 1325
 //	return str
1263 1326
 //}
1327
+
1328
+func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
1329
+	file, err := os.Open(path)
1330
+	if err != nil {
1331
+		return nil, err
1332
+	}
1333
+	defer file.Close()
1334
+
1335
+	body := &bytes.Buffer{}
1336
+	writer := multipart.NewWriter(body)
1337
+	part, err := writer.CreateFormFile(paramName, filepath.Base(path))
1338
+	if err != nil {
1339
+		return nil, err
1340
+	}
1341
+	_, err = io.Copy(part, file)
1342
+
1343
+	for key, val := range params {
1344
+		_ = writer.WriteField(key, val)
1345
+	}
1346
+	err = writer.Close()
1347
+	if err != nil {
1348
+		return nil, err
1349
+	}
1350
+
1351
+	req, err := http.NewRequest("POST", uri, body)
1352
+	req.Header.Set("Content-Type", writer.FormDataContentType())
1353
+	return req, err
1354
+}