Просмотр исходного кода

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

csx 2 лет назад
Родитель
Сommit
f6ba14499b

+ 2 - 2
conf/app.conf Просмотреть файл

@@ -45,7 +45,7 @@ appsecret="61ee2e6268497d5aa9de0b0187c39aea"
45 45
 
46 46
 
47 47
 [prod]
48
-org_id = 10215
48
+org_id = 10188
49 49
 mobile_token_expiration_second = 86400
50 50
 httpdomain = https://api.xt.kuyicloud.com
51 51
 sso_domain = https://sso.kuyicloud.com
@@ -67,7 +67,7 @@ gdyb_url = "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/"
67 67
 #深圳
68 68
 # gdyb_paasid = "sz_prd_yjyy"
69 69
 #肇庆
70
- gdyb_paasid = "zq_prd_yjyy"
70
+#  gdyb_paasid = "zq_prd_yjyy"
71 71
 
72 72
 
73 73
 

+ 2 - 2
controllers/sg/his_api_controller.go Просмотреть файл

@@ -8914,8 +8914,8 @@ func (c *HisApiController) GetSettleAccounts() {
8914 8914
 		} else {
8915 8915
 			//result2 := service.Gdyb1101()
8916 8916
 
8917
-			result2 := service.Gdyb5204(baseParams, businessParams)
8918
-			saveLog(result2, "", "5204", "查询")
8917
+			//result2 := service.Gdyb5204(baseParams, businessParams)
8918
+			//saveLog(result2, "", "5204", "查询")
8919 8919
 			result := service.Gdyb5203(baseParams, businessParams)
8920 8920
 			var dat map[string]interface{}
8921 8921
 			if err := json.Unmarshal([]byte(result), &dat); err == nil {

+ 320 - 0
controllers/zh/zh_his_api_controller.go Просмотреть файл

@@ -10,12 +10,16 @@ import (
10 10
 	"gdyb/utils"
11 11
 	"github.com/astaxie/beego"
12 12
 	"github.com/axgle/mahonia"
13
+	"github.com/jinzhu/gorm"
13 14
 	"math"
14 15
 	"math/rand"
15 16
 	"os"
17
+	"regexp"
16 18
 	"strconv"
17 19
 	"strings"
20
+	"syscall"
18 21
 	"time"
22
+	"unsafe"
19 23
 )
20 24
 
21 25
 type ZHHisApiController struct {
@@ -471,6 +475,7 @@ func ZHHisManagerApiRegistRouters() {
471 475
 	beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
472 476
 	beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
473 477
 	beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
478
+	beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
474 479
 
475 480
 }
476 481
 func (c *ZHHisApiController) GetZHPatientInfo() {
@@ -2408,3 +2413,318 @@ func ConvertToString(src string, srcCode string, tagCode string) string {
2408 2413
 	result := string(cdata)
2409 2414
 	return result
2410 2415
 }
2416
+
2417
+type ELeData struct {
2418
+	Data struct {
2419
+		IdNo        string `json:"idNo"`
2420
+		IdType      string `json:"idType"`
2421
+		UserName    string `json:"userName"`
2422
+		EcToken     string `json:"ecToken"`
2423
+		InsuOrg     string `json:"insuOrg"`
2424
+		Gender      string `json:"gender"`
2425
+		Birthday    string `json:"birthday"`
2426
+		Nationality string `json:"nationality"`
2427
+		Email       string `json:"email"`
2428
+		Extra       string `json:"extra"`
2429
+	} `json:"data"`
2430
+	Code    int    `json:"code"`
2431
+	Message string `json:"message"`
2432
+}
2433
+
2434
+func (c *ZHHisApiController) ReadCard() {
2435
+	id_card_type, _ := c.GetInt64("id_card_type")
2436
+	admin_user_id, _ := c.GetInt64("admin_user_id")
2437
+	certificates, _ := c.GetInt64("certificates")
2438
+	fmt.Println(c.GetAdminUserInfo().CurrentOrgId)
2439
+	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
2440
+	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
2441
+
2442
+	switch id_card_type {
2443
+	case 1:
2444
+		if initFlag == 0 {
2445
+			c.TestGetBasBaseInit()
2446
+		}
2447
+		basStr := c.GetBasBaseInfo(miConfig.Code, miConfig.MdtrtareaAdmvs, roles.UserName, roles.ID, miConfig.OrgName)
2448
+		if len(basStr) == 0 {
2449
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
2450
+			return
2451
+		}
2452
+		fmt.Println(basStr)
2453
+		bas := strings.Split(basStr, "|")
2454
+		basNumber := bas[1]
2455
+		fmt.Println(basNumber)
2456
+		card_sn := bas[3]
2457
+		fmt.Println(card_sn)
2458
+		result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
2459
+		var dat map[string]interface{}
2460
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
2461
+			fmt.Println(dat)
2462
+		} else {
2463
+			fmt.Println(err)
2464
+		}
2465
+
2466
+		userJSONBytes, _ := json.Marshal(dat)
2467
+		var res ResultTwo
2468
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2469
+			utils.ErrorLog("解析失败:%v", err)
2470
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2471
+			return
2472
+		}
2473
+
2474
+		if res.Infcode == 0 {
2475
+			patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
2476
+			if err == gorm.ErrRecordNotFound {
2477
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
2478
+				return
2479
+			} else if err != nil {
2480
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2481
+				return
2482
+
2483
+			} else {
2484
+				c.ServeSuccessJSON(map[string]interface{}{
2485
+					"patient": patient,
2486
+					"number":  basNumber,
2487
+				})
2488
+			}
2489
+		} else {
2490
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
2491
+			return
2492
+		}
2493
+		break
2494
+	case 2:
2495
+		SFZStr := c.GetSFZBaseInfo()
2496
+		id_card_str := strings.Split(SFZStr, "^")
2497
+		id_card_number := id_card_str[0]
2498
+		card_sn := ""
2499
+		result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
2500
+		var dat map[string]interface{}
2501
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
2502
+			fmt.Println(dat)
2503
+		} else {
2504
+			fmt.Println(err)
2505
+		}
2506
+
2507
+		userJSONBytes, _ := json.Marshal(dat)
2508
+		var res ResultTwo
2509
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2510
+			utils.ErrorLog("解析失败:%v", err)
2511
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2512
+			return
2513
+		}
2514
+
2515
+		if res.Infcode == 0 {
2516
+			patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
2517
+			if err == gorm.ErrRecordNotFound {
2518
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
2519
+				return
2520
+			} else if err != nil {
2521
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2522
+				return
2523
+
2524
+			} else {
2525
+				c.ServeSuccessJSON(map[string]interface{}{
2526
+					"patient": patient,
2527
+					"number":  id_card_number,
2528
+				})
2529
+			}
2530
+		} else {
2531
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
2532
+			return
2533
+		}
2534
+
2535
+		break
2536
+	case 3:
2537
+		_, pBusiCardInfo := c.GetELeInfo(miConfig.Code, strconv.FormatInt(roles.ID, 64), roles.UserName)
2538
+
2539
+		var ele ELeData
2540
+		err := json.Unmarshal([]byte(pBusiCardInfo), &ele)
2541
+		if err != nil {
2542
+			utils.ErrorLog("解析失败:%v", err)
2543
+		}
2544
+		token := ele.Data.EcToken
2545
+		if len(token) > 0 {
2546
+			result, _ := service.Gdyb1101B(org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, url, ak, token, cainfo, ele.Data.IdNo)
2547
+			var dat map[string]interface{}
2548
+			if err := json.Unmarshal([]byte(result), &dat); err == nil {
2549
+				fmt.Println(dat)
2550
+			} else {
2551
+				fmt.Println(err)
2552
+			}
2553
+			c.ServeSuccessJSON(map[string]interface{}{
2554
+				"status": "0",
2555
+				//"card_info":      pCardInfo,
2556
+				"busi_card_info": pBusiCardInfo,
2557
+				"token":          token,
2558
+				"result":         dat,
2559
+				"type":           "2",
2560
+			})
2561
+		} else {
2562
+			c.ServeSuccessJSON(map[string]interface{}{
2563
+				"status": "-1",
2564
+			})
2565
+
2566
+		}
2567
+		break
2568
+	}
2569
+
2570
+}
2571
+
2572
+var initFlag int64 = 0
2573
+
2574
+func (c *ZHHisApiController) TestGetBasBaseInit() {
2575
+	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
2576
+	Iinit := DllDef.MustFindProc("Init")
2577
+	//miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
2578
+	str := make([]byte, 2048)
2579
+	inputData := make(map[string]interface{})
2580
+	inputData["IP"] = "10.144.211.75"
2581
+	inputData["PORT"] = "7021"
2582
+	inputData["TIMEOUT"] = "180"
2583
+	inputData["LOG_PATH"] = "C:\\log\\"
2584
+
2585
+	bytesData, _ := json.Marshal(inputData)
2586
+	fmt.Println(inputData)
2587
+	fmt.Println(bytesData)
2588
+
2589
+	ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
2590
+	if ret != 0 {
2591
+		fmt.Println("SSCard的报错原因:", err)
2592
+		fmt.Println("SSCard的运算结果为:", ret)
2593
+		fmt.Println("SSCard的返回结果为:", string(str))
2594
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
2595
+		return
2596
+	}
2597
+	fmt.Println("SSCard的返回结果为:", string(str))
2598
+
2599
+	result := int(ret)
2600
+	fmt.Println("SSCard的运算结果为1:", result)
2601
+	//initFlag = 1
2602
+	return
2603
+}
2604
+
2605
+func (c *ZHHisApiController) GetSFZBaseInfo() string {
2606
+	DllDef := syscall.MustLoadDLL("SSCard.dll")
2607
+	readCard := DllDef.MustFindProc("ReadSFZ")
2608
+	if readCard == nil {
2609
+		fmt.Println("readcard is nil")
2610
+		readCard = DllDef.MustFindProc("ReadSFZ")
2611
+	}
2612
+
2613
+	str := make([]byte, 256)
2614
+	str1 := make([]byte, 256)
2615
+	r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
2616
+
2617
+	fmt.Println(r)
2618
+	return string(str)
2619
+}
2620
+
2621
+func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
2622
+	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
2623
+	readCard := DllDef.MustFindProc("ReadCardBas")
2624
+	fmt.Println(readCard)
2625
+	fmt.Println("!!!!!")
2626
+
2627
+	month := time.Unix(1557042972, 0).Format("1")
2628
+	year := time.Now().Format("2006")
2629
+	month = time.Now().Format("01")
2630
+	day := time.Now().Format("02")
2631
+
2632
+	hour := time.Now().Format("15")
2633
+	min := time.Now().Format("04")
2634
+	sec := time.Now().Format("05")
2635
+
2636
+	msec := time.Now().Format("000")
2637
+	timestamp := time.Now().Unix()
2638
+
2639
+	tempTime := time.Unix(timestamp, 0)
2640
+	//timeFormat := tempTime.Format("20060102150405")
2641
+	timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
2642
+	//randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
2643
+
2644
+	inputData := make(map[string]interface{})
2645
+	inputData["infno"] = "1199"
2646
+	//inputData["msgid"] = "7021"
2647
+	inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
2648
+	inputData["mdtrtarea_admvs"] = mdtrtarea_admvs                                           // 发送方报文 ID
2649
+	inputData["recer_sys_code"] = "01"
2650
+	inputData["infver"] = "V1.0"
2651
+	inputData["opter_type"] = "1"
2652
+	inputData["opter"] = opter_id
2653
+	inputData["opter_name"] = opter_name
2654
+	inputData["inf_time"] = timeFormatOne
2655
+	inputData["fixmedins_code"] = fixmedins_code
2656
+	inputData["fixmedins_name"] = fixmedins_name
2657
+
2658
+	inputData["dev_no"] = ""
2659
+	inputData["dev_safe_info"] = ""
2660
+	inputData["cainfo"] = ""
2661
+	inputData["signtype"] = ""
2662
+	inputData["sign_no"] = ""
2663
+
2664
+	bytesData, _ := json.Marshal(inputData)
2665
+	pBusiCardInfo := make([]byte, 8192)
2666
+	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
2667
+	fmt.Println(ret2)
2668
+	fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
2669
+	fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
2670
+	if ret2 != 0 {
2671
+		return ""
2672
+	}
2673
+	return DeleteExtraSpace(string(pBusiCardInfo))
2674
+}
2675
+
2676
+func DeleteExtraSpace(s string) string {
2677
+	//删除字符串中的多余空格,有多个空格时,仅保留一个空格
2678
+	s1 := strings.Replace(s, "  ", " ", -1)      //替换tab为空格
2679
+	regstr := "\\s{2,}"                          //两个及两个以上空格的正则表达式
2680
+	reg, _ := regexp.Compile(regstr)             //编译正则表达式
2681
+	s2 := make([]byte, len(s1))                  //定义字符数组切片
2682
+	copy(s2, s1)                                 //将字符串复制到切片
2683
+	spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
2684
+	for len(spc_index) > 0 {                     //找到适配项
2685
+		s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
2686
+		spc_index = reg.FindStringIndex(string(s2))            //继续在字符串中搜索
2687
+	}
2688
+	return string(s2)
2689
+}
2690
+
2691
+func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
2692
+	DllDef := syscall.MustLoadDLL("NationECCode.dll")
2693
+	readCard := DllDef.MustFindProc("NationEcTrans")
2694
+	fmt.Println(readCard)
2695
+	fmt.Println("!!!!!")
2696
+	pBusiCardInfo := make([]byte, 8192)
2697
+	inputData := make(map[string]interface{})
2698
+	inputData["orgId"] = code
2699
+	inputData["businessType"] = "01101"
2700
+	inputData["operatorId"] = operator_id
2701
+	inputData["operatorName"] = operator_name
2702
+	inputData["officeId"] = "001"
2703
+	inputData["officeName"] = "血透室"
2704
+	inputData["deviceType"] = ""
2705
+	bytesData, _ := json.Marshal(inputData)
2706
+	url := "http://localcfc/api/hsecfc/localQrCodeQuery"
2707
+	ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
2708
+	fmt.Println(ret2)
2709
+	fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
2710
+	fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
2711
+	if ret2 != 0 {
2712
+		return "", ""
2713
+	}
2714
+	return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
2715
+}
2716
+
2717
+func StrPtr(s string) uintptr {
2718
+	return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
2719
+}
2720
+
2721
+func Remove0000(s string) string {
2722
+	str := make([]rune, 0, len(s))
2723
+	for _, v := range []rune(s) {
2724
+		if v == 0 {
2725
+			continue
2726
+		}
2727
+		str = append(str, v)
2728
+	}
2729
+	return string(str)
2730
+}

+ 7 - 7
main.go Просмотреть файл

@@ -5,7 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"gdyb/models"
7 7
 	_ "gdyb/routers"
8
-	"gdyb/service"
8
+	//"gdyb/service"
9 9
 	"github.com/astaxie/beego"
10 10
 	"github.com/qiniu/api.v7/auth/qbox"
11 11
 	"github.com/qiniu/api.v7/storage"
@@ -15,12 +15,12 @@ import (
15 15
 )
16 16
 
17 17
 func init() {
18
-	service.ConnectDB()
19
-	org_id, _ := beego.AppConfig.Int64("org_id")
20
-
21
-	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
22
-	CreateLog(miConfig)
23
-	UploadLog(miConfig)
18
+	//service.ConnectDB()
19
+	//org_id, _ := beego.AppConfig.Int64("org_id")
20
+	//
21
+	//miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
22
+	//CreateLog(miConfig)
23
+	//UploadLog(miConfig)
24 24
 
25 25
 	//UploadSettleList(org_id)
26 26
 }

+ 1 - 1
service/gdyb_service.go Просмотреть файл

@@ -4381,7 +4381,7 @@ func SetInputMessageFour(nonce string, timestamp int64, org_name string, doctor
4381 4381
 	//randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
4382 4382
 
4383 4383
 	msec := time.Now().Format("000")
4384
-
4384
+	fmt.Println(utils.GetNetTime())
4385 4385
 	// 生成输入报文
4386 4386
 	inputMessage := make(map[string]interface{})
4387 4387
 	inputMessage["msgid"] = fixmedins_code + utils.GetNetTime() + msec + "0" // 发送方报文 ID

+ 3 - 3
service/jsyb_service.go Просмотреть файл

@@ -637,9 +637,9 @@ func Jsyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, d
637 637
 	inputData := make(map[string]interface{})
638 638
 	inputMessage["infno"] = "2205" // 交易编码
639 639
 
640
-	inputData["mdtrt_id"] = mdtrtId     // 就诊 ID(来自2201接口返回)
641
-	inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
642
-	inputData["psn_no"] = psnNo         // 人员编号 (来自1101接口返回)
640
+	inputData["mdtrt_id"] = mdtrtId  // 就诊 ID(来自2201接口返回)
641
+	inputData["chrg_bchno"] = "0000" // 收费批次号(来自2204生成的)
642
+	inputData["psn_no"] = psnNo      // 人员编号 (来自1101接口返回)
643 643
 
644 644
 	input["data"] = inputData
645 645
 	inputMessage["input"] = input //交易输入