Browse Source

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

csx 1 year ago
parent
commit
5128ec12eb
2 changed files with 86 additions and 1 deletions
  1. 32 1
      service/gdyb_service.go
  2. 54 0
      utils/time_helper.go

+ 32 - 1
service/gdyb_service.go View File

@@ -7,6 +7,7 @@ import (
7 7
 	"encoding/json"
8 8
 	"fmt"
9 9
 	"gdyb/models"
10
+	"gdyb/utils"
10 11
 	"github.com/astaxie/beego"
11 12
 	"github.com/go-ole/go-ole"
12 13
 	"github.com/go-ole/go-ole/oleutil"
@@ -1994,7 +1995,7 @@ func Gdyb5203(baseParams models.BaseParams, businessParams models.BusinessParams
1994 1995
 	signature := setSignature(timestamp, nonce, baseParams.SecretKey)
1995 1996
 
1996 1997
 	// 生成输入报文
1997
-	inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
1998
+	inputMessage := SetInputMessageFour(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
1998 1999
 	input := make(map[string]interface{})
1999 2000
 	inputData := make(map[string]interface{})
2000 2001
 	inputMessage["infno"] = "5203" // 交易编码
@@ -4371,3 +4372,33 @@ func Gdyb1101D(certNo string, org_name string, doctor string, fixmedins_code str
4371 4372
 	}
4372 4373
 
4373 4374
 }
4375
+
4376
+func SetInputMessageFour(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} {
4377
+	// 生成签名
4378
+	//tempTime := time.Unix(timestamp, 0)
4379
+	//timeFormat := tempTime.Format("20060102150405")
4380
+	//timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
4381
+	//randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
4382
+
4383
+	msec := time.Now().Format("000")
4384
+
4385
+	// 生成输入报文
4386
+	inputMessage := make(map[string]interface{})
4387
+	inputMessage["msgid"] = fixmedins_code + utils.GetNetTime() + msec + "0" // 发送方报文 ID
4388
+	inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs                        // 就医地医保区划
4389
+	inputMessage["insuplc_admdvs"] = insuplc_admdvs                          // 参保地医保区划
4390
+	inputMessage["recer_sys_code"] = "1"                                     // 接收方系统代码
4391
+	inputMessage["dev_no"] = ""                                              // 设备编号
4392
+	inputMessage["dev_safe_info"] = ""                                       // 设备安全信息
4393
+	inputMessage["cainfo"] = ""                                              // 数字签名信息
4394
+	inputMessage["signtype"] = "SM3"                                         // 签名类型
4395
+	inputMessage["infver"] = "V1.0"                                          // 接收方系统代码
4396
+	inputMessage["opter_type"] = "1"                                         // 经办人类别
4397
+	inputMessage["opter"] = doctor                                           // 经办人
4398
+	inputMessage["opter_name"] = doctor                                      // 经办人姓名
4399
+	inputMessage["inf_time"] = utils.GetNetTime()                            // 交易时间
4400
+	inputMessage["fixmedins_code"] = fixmedins_code                          // 定点医药机构编号
4401
+	inputMessage["fixmedins_name"] = org_name                                //定点医药机构名称
4402
+	inputMessage["sign_no"] = ""                                             //交易签到流水号
4403
+	return inputMessage
4404
+}

+ 54 - 0
utils/time_helper.go View File

@@ -1,9 +1,33 @@
1 1
 package utils
2 2
 
3 3
 import (
4
+	"encoding/binary"
5
+	"flag"
6
+	"log"
7
+	"net"
4 8
 	"time"
5 9
 )
6 10
 
11
+const ntpEpochOffset = 2208988800
12
+
13
+type packet struct {
14
+	Settings       uint8
15
+	Stratum        uint8
16
+	Poll           int8
17
+	Precision      int8
18
+	RootDelay      uint32
19
+	RootDispersion uint32
20
+	ReferenceID    uint32
21
+	RefTimeSec     uint32
22
+	RefTimeFrac    uint32
23
+	OrigTimeSec    uint32
24
+	OrigTimeFrac   uint32
25
+	RxTimeSec      uint32
26
+	RxTimeFrac     uint32
27
+	TxTimeSec      uint32
28
+	TxTimeFrac     uint32
29
+}
30
+
7 31
 // day 当天凌晨0点
8 32
 func ZeroHourTimeOfDay(day time.Time) time.Time {
9 33
 	dayStr := day.Format("2006-01-02")
@@ -25,3 +49,33 @@ func MonthBeginningToEnd(year int, month int) (time.Time, time.Time) {
25 49
 	endOfMonth := beginningOfNextMonth.Add(time.Duration(-1))
26 50
 	return beginningOfMonth, endOfMonth
27 51
 }
52
+
53
+func GetNetTime() string {
54
+	var host string
55
+	flag.StringVar(&host, "e", "182.92.12.11:123", "NTP host")
56
+	flag.Parse()
57
+
58
+	conn, err := net.Dial("udp", host)
59
+	if err != nil {
60
+		log.Fatalf("failed to connect: %v", err)
61
+	}
62
+	defer conn.Close()
63
+	if err := conn.SetDeadline(time.Now().Add(15 * time.Second)); err != nil {
64
+		log.Fatalf("failed to set deadline: %v", err)
65
+	}
66
+
67
+	req := &packet{Settings: 0x1B}
68
+
69
+	if err := binary.Write(conn, binary.BigEndian, req); err != nil {
70
+		log.Fatalf("failed to send request: %v", err)
71
+	}
72
+
73
+	rsp := &packet{}
74
+	if err := binary.Read(conn, binary.BigEndian, rsp); err != nil {
75
+		log.Fatalf("failed to read server response: %v", err)
76
+	}
77
+	secs := float64(rsp.TxTimeSec) - ntpEpochOffset
78
+	nanos := (int64(rsp.TxTimeFrac) * 1e9) >> 32
79
+	showtime := time.Unix(int64(secs), nanos)
80
+	return time.Unix(showtime.Unix(), 0).Format("2006-01-02 15:04:05")
81
+}