Przeglądaj źródła

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

csx 3 lat temu
rodzic
commit
0a78b586c0

+ 3 - 3
conf/app.conf Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 appname = 血透
2 2
 httpport = 9532
3
-runmode = prod
3
+runmode = dev
4 4
 
5 5
 
6 6
 #
@@ -166,14 +166,14 @@ front_end_domain = "http://xt.test.sgjyun.com/#"
166 166
 
167 167
 org_id = 4
168 168
 #url  = "http://192.168.1.228:17001/szsi-portal/transData"
169
-gdyb_url = "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/"
169
+# gdyb_url = "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/"
170 170
 #gdyb_url = "http://10.97.240.206/ebus/sztest_hosp/poc/hsa/hgs/"
171 171
 #url = "http://192.168.1.88:6666/szsi-portal/transData"
172 172
 #gdyb_url = "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/"
173 173
 #gdyb_url = "http://10.87.67.83:8080/mbs-hi-intf/web/api/webservices/hb/interface/"
174 174
 #gdyb_paasid = "test_sz"
175 175
 #gdyb_paasid = zh_cs
176
-gdyb_paasid = test_hosp
176
+# gdyb_paasid = test_hosp
177 177
 #gdyb_paasid = zq_prd_yjyy
178 178
 
179 179
 #gdyb_paasid = "zh_prd_yjyy"

+ 402 - 0
controllers/js/jsyb_controller.go Wyświetl plik

@@ -0,0 +1,402 @@
1
+package js
2
+
3
+import (
4
+	"encoding/json"
5
+	"fmt"
6
+	"gdyb/controllers"
7
+	"gdyb/models"
8
+	"gdyb/service"
9
+	"gdyb/utils"
10
+	"github.com/astaxie/beego"
11
+	"io/ioutil"
12
+)
13
+
14
+type JSybController struct {
15
+	controllers.BaseAuthAPIController
16
+}
17
+
18
+func JSybRegistRouters() {
19
+	beego.Router("/jsyb/1101", &JSybController{}, "get:PostOne")
20
+	beego.Router("/jsyb/2201", &JSybController{}, "get:PostTwo")
21
+	beego.Router("/jsyb/2202", &JSybController{}, "get:PostThree")
22
+	beego.Router("/jsyb/2203", &JSybController{}, "post:PostFour")
23
+	beego.Router("/jsyb/2204", &JSybController{}, "post:PostFive")
24
+	beego.Router("/jsyb/2205", &JSybController{}, "get:PostSix")
25
+	beego.Router("/jsyb/2206", &JSybController{}, "get:PostSeven")
26
+	beego.Router("/jsyb/2207", &JSybController{}, "get:PostEight")
27
+	beego.Router("/jsyb/2208", &JSybController{}, "get:PostNine")
28
+	beego.Router("/jsyb/5203", &JSybController{}, "get:PostTen")
29
+}
30
+
31
+func (c *JSybController) PostOne() {
32
+	certNo := c.GetString("cert_no")
33
+	org_name := c.GetString("org_name")
34
+	doctor := c.GetString("doctor")
35
+	fixmedins_code := c.GetString("fixmedins_code")
36
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
37
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
38
+	secret_key := c.GetString("secret_key")
39
+	id_card_type, _ := c.GetInt64("id_card_type")
40
+	card_sn := c.GetString("card_sn")
41
+	certificates := c.GetString("certificates")
42
+	url := c.GetString("url")
43
+	ak := c.GetString("ak")
44
+	result, inputLog := service.Jsyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type, card_sn, certificates, url, ak)
45
+	fmt.Println(result)
46
+	fmt.Println(inputLog)
47
+	var dat map[string]interface{}
48
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
49
+
50
+	} else {
51
+
52
+	}
53
+
54
+	var dat2 map[string]interface{}
55
+	if err := json.Unmarshal([]byte(inputLog), &dat2); err == nil {
56
+
57
+	} else {
58
+
59
+	}
60
+
61
+	c.ServeSuccessJSON(map[string]interface{}{
62
+		"pre": dat,
63
+		"log": dat2,
64
+	})
65
+}
66
+func (c *JSybController) PostTwo() {
67
+	psnNo := c.GetString("psn_no")
68
+	insutype := c.GetString("insutype")
69
+	certNo := c.GetString("cert_no")
70
+	org_name := c.GetString("org_name")
71
+	doctor := c.GetString("doctor")
72
+	ipt_otp_no := c.GetString("ipt_otp_no")
73
+	dept := c.GetString("dept")
74
+	fixmedins_code := c.GetString("fixmedins_code")
75
+
76
+	dept_code := c.GetString("dept_code")
77
+	doctor_id := c.GetString("doctor_id")
78
+
79
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
80
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
81
+
82
+	secret_key := c.GetString("secret_key")
83
+
84
+	id_card_type, _ := c.GetInt64("id_card_type")
85
+
86
+	result, _ := service.Hbyb2201(psnNo, insutype, certNo, org_name, doctor, ipt_otp_no, dept, fixmedins_code, dept_code, doctor_id, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type)
87
+
88
+	var dat map[string]interface{}
89
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
90
+		//fmt.Println(dat["status"])
91
+	} else {
92
+	}
93
+
94
+	c.ServeSuccessJSON(map[string]interface{}{
95
+		"pre": dat,
96
+	})
97
+}
98
+func (c *JSybController) PostThree() {
99
+	psnNo := c.GetString("psn_no")
100
+	mdtrtId := c.GetString("mdtrt_id")
101
+	iptOtpNo := c.GetString("ipt_otp_no")
102
+	org_name := c.GetString("org_name")
103
+	doctor := c.GetString("doctor")
104
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
105
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
106
+	secret_key := c.GetString("secret_key")
107
+	fixmedins_code := c.GetString("fixmedins_code")
108
+	result, requestLog := service.Hbyb2202(psnNo, mdtrtId, iptOtpNo, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
109
+	var dat map[string]interface{}
110
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
111
+	} else {
112
+	}
113
+
114
+	c.ServeSuccessJSON(map[string]interface{}{
115
+		"pre":         dat,
116
+		"request_log": requestLog,
117
+	})
118
+}
119
+
120
+func (c *JSybController) PostFour() {
121
+
122
+	body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
123
+	var respJSON map[string]interface{}
124
+	if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
125
+		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
126
+		return
127
+	}
128
+	userJSONBytes, _ := json.Marshal(respJSON["config"])
129
+	var config []*models.HisXtDiagnoseConfig
130
+	if err := json.Unmarshal(userJSONBytes, &config); err != nil {
131
+		utils.ErrorLog("解析失败:%v", err)
132
+		return
133
+	}
134
+	fmt.Println(respJSON["psn_no"].(string))
135
+	fmt.Println(respJSON["mdtrt_id"].(string))
136
+
137
+	psnNo := respJSON["psn_no"].(string)
138
+	mdtrtId := respJSON["mdtrt_id"].(string)
139
+	doctor := respJSON["doctor"].(string)
140
+	department := respJSON["department"].(string)
141
+
142
+	org_name := respJSON["org_name"].(string)
143
+	med_type := respJSON["med_type"].(string)
144
+	doctor_id := respJSON["doctor_id"].(string)
145
+	fixmedins_code := respJSON["fixmedins_code"].(string)
146
+	sick_code := respJSON["sick_code"].(string)
147
+	sick_name := respJSON["sick_name"].(string)
148
+	dept := respJSON["dept"].(string)
149
+
150
+	insuplc_admdvs := respJSON["insuplc_admdvs"].(string)
151
+	mdtrtarea_admvs := respJSON["mdtrtarea_admvs"].(string)
152
+	secret_key := respJSON["secret_key"].(string)
153
+
154
+	result, request_log := service.Hbyb2203(psnNo, mdtrtId, doctor, department, org_name, med_type, doctor_id, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, sick_code, sick_name, dept, config)
155
+
156
+	fmt.Println(request_log)
157
+
158
+	var dat map[string]interface{}
159
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
160
+
161
+	} else {
162
+
163
+	}
164
+	c.ServeSuccessJSON(map[string]interface{}{
165
+		"pre": dat,
166
+	})
167
+}
168
+
169
+type All struct {
170
+	HisPrescription HisPrescription
171
+	mdtrt_id        string
172
+	psn_no          string
173
+}
174
+type HisPrescription struct {
175
+	ID                     int64                            `gorm:"column:id" json:"id" form:"id"`
176
+	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
177
+	RecordDate             int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
178
+	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
179
+	HisPatientId           int64                            `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
180
+	Status                 int64                            `gorm:"column:status" json:"status" form:"status"`
181
+	Ctime                  int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
182
+	Mtime                  int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
183
+	Number                 string                           `gorm:"column:number" json:"number" form:"number"`
184
+	Type                   int64                            `gorm:"column:type" json:"type" form:"type"`
185
+	Doctor                 int64                            `gorm:"column:doctor" json:"doctor" form:"doctor"`
186
+	Creator                int64                            `gorm:"column:creator" json:"creator" form:"creator"`
187
+	Modifier               int64                            `gorm:"column:modifier" json:"modifier" form:"modifier"`
188
+	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"advices"`
189
+	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"project"`
190
+}
191
+
192
+func (c *JSybController) PostFive() {
193
+	body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
194
+	var respJSON map[string]interface{}
195
+	if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
196
+		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
197
+		return
198
+	}
199
+	userJSONBytes, _ := json.Marshal(respJSON["pre"])
200
+	var hp []*models.HisPrescription
201
+	if err := json.Unmarshal(userJSONBytes, &hp); err != nil {
202
+		utils.ErrorLog("解析失败:%v", err)
203
+		return
204
+	}
205
+	fmt.Println(respJSON["psn_no"].(string))
206
+	fmt.Println(respJSON["mdtrt_id"].(string))
207
+
208
+	fmt.Println(respJSON["chrg_bchno"].(string))
209
+	fmt.Println(respJSON["org_name"].(string))
210
+	fmt.Println(respJSON["doctor"].(string))
211
+	fmt.Println(respJSON["dept"].(string))
212
+
213
+	fmt.Println(respJSON["fixmedins_code"].(string))
214
+	fmt.Println(respJSON["dept_code"].(string))
215
+	fmt.Println(respJSON["doctor_id"].(string))
216
+
217
+	fmt.Println(respJSON["insuplc_admdvs"].(string))
218
+	fmt.Println(respJSON["mdtrtarea_admvs"].(string))
219
+	fmt.Println(respJSON["secret_key"].(string))
220
+
221
+	result, requestLog := service.Hbyb2204(respJSON["psn_no"].(string), respJSON["mdtrt_id"].(string), hp, respJSON["chrg_bchno"].(string), respJSON["org_name"].(string),
222
+		respJSON["doctor"].(string), respJSON["dept"].(string), respJSON["fixmedins_code"].(string), respJSON["dept_code"].(string), respJSON["doctor_id"].(string), respJSON["insuplc_admdvs"].(string), respJSON["mdtrtarea_admvs"].(string), respJSON["secret_key"].(string), respJSON["balance_accounts_type"].(string))
223
+
224
+	var dat map[string]interface{}
225
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
226
+		fmt.Println(dat)
227
+	} else {
228
+		fmt.Println(err)
229
+	}
230
+
231
+	var dat2 map[string]interface{}
232
+	if err := json.Unmarshal([]byte(requestLog), &dat2); err == nil {
233
+		fmt.Println(dat2)
234
+	} else {
235
+		fmt.Println(err)
236
+	}
237
+
238
+	c.ServeSuccessJSON(map[string]interface{}{
239
+		"pre":         dat,
240
+		"request_log": requestLog,
241
+	})
242
+}
243
+func (c *JSybController) PostSix() {
244
+	psnNo := c.GetString("psn_no")
245
+	mdtrtId := c.GetString("mdtrt_id")
246
+	chrgBchno := c.GetString("chrg_bchno")
247
+	org_name := c.GetString("org_name")
248
+	doctor := c.GetString("doctor")
249
+
250
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
251
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
252
+
253
+	secret_key := c.GetString("secret_key")
254
+	fixmedins_code := c.GetString("fixmedins_code")
255
+
256
+	result, requestlog := service.Hbyb2205(psnNo, mdtrtId, chrgBchno, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
257
+	fmt.Println(requestlog)
258
+	var dat map[string]interface{}
259
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
260
+		fmt.Println(dat)
261
+	} else {
262
+		fmt.Println(err)
263
+	}
264
+	c.ServeSuccessJSON(map[string]interface{}{
265
+		"pre": dat,
266
+	})
267
+}
268
+func (c *JSybController) PostSeven() {
269
+	psnNo := c.GetString("psn_no")
270
+	mdtrtId := c.GetString("mdtrt_id")
271
+	chrgBchno := c.GetString("chrg_bchno")
272
+	certNo := c.GetString("cert_no")
273
+	insutype := c.GetString("insutype")
274
+	total := c.GetString("total")
275
+	org_name := c.GetString("org_name")
276
+	doctor := c.GetString("doctor")
277
+	fixmedins_code := c.GetString("fixmedins_code")
278
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
279
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
280
+	secret_key := c.GetString("secret_key")
281
+	med_type := c.GetString("med_type")
282
+	id_card_type, _ := c.GetInt64("id_card_type")
283
+	certificates, _ := c.GetInt64("certificates")
284
+
285
+	result, requestlog := service.Hbyb2206(psnNo, mdtrtId, chrgBchno, certNo, insutype, total, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, med_type, id_card_type, 0, 0, 0, 0, certificates)
286
+	fmt.Println(requestlog)
287
+
288
+	var dat map[string]interface{}
289
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
290
+		fmt.Println(dat)
291
+	} else {
292
+		fmt.Println(err)
293
+	}
294
+	c.ServeSuccessJSON(map[string]interface{}{
295
+		"pre": dat,
296
+	})
297
+}
298
+func (c *JSybController) PostEight() {
299
+	psnNo := c.GetString("psn_no")
300
+	mdtrtId := c.GetString("mdtrt_id")
301
+	chrgBchno := c.GetString("chrg_bchno")
302
+	certNo := c.GetString("cert_no")
303
+	insutype := c.GetString("insutype")
304
+	total := c.GetString("total")
305
+	org_name := c.GetString("org_name")
306
+	doctor := c.GetString("doctor")
307
+	fixmedins_code := c.GetString("fixmedins_code")
308
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
309
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
310
+	secret_key := c.GetString("secret_key")
311
+	med_type := c.GetString("med_type")
312
+	id_card_type, _ := c.GetInt64("id_card_type")
313
+	certificates, _ := c.GetInt64("certificates")
314
+
315
+	fulamt_ownpay_amt, _ := c.GetFloat("fulamt_ownpay_amt")
316
+	overlmt_selfpay, _ := c.GetFloat("overlmt_selfpay")
317
+	preselfpay_amt, _ := c.GetFloat("preselfpay_amt")
318
+	inscp_scp_amt, _ := c.GetFloat("inscp_scp_amt")
319
+
320
+	acct_used_flag, _ := c.GetInt64("acct_used_flag")
321
+
322
+	result, srcRequest := service.Hbyb2207(psnNo, mdtrtId, chrgBchno, certNo, insutype, total, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, med_type, id_card_type, fulamt_ownpay_amt, overlmt_selfpay, preselfpay_amt, inscp_scp_amt, certificates, acct_used_flag)
323
+	var dat map[string]interface{}
324
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
325
+		fmt.Println(dat)
326
+	} else {
327
+		fmt.Println(err)
328
+	}
329
+
330
+	var dat2 map[string]interface{}
331
+	if err := json.Unmarshal([]byte(srcRequest), &dat2); err == nil {
332
+		fmt.Println(dat2)
333
+	} else {
334
+		fmt.Println(err)
335
+	}
336
+
337
+	c.ServeSuccessJSON(map[string]interface{}{
338
+		"pre":  dat,
339
+		"pre2": dat2,
340
+	})
341
+}
342
+func (c *JSybController) PostNine() {
343
+	psnNo := c.GetString("psn_no")
344
+	mdtrtId := c.GetString("mdtrt_id")
345
+	setlId := c.GetString("setl_id")
346
+	org_name := c.GetString("org_name")
347
+	doctor := c.GetString("doctor")
348
+	secret_key := c.GetString("secret_key")
349
+	fixmedins_code := c.GetString("fixmedins_code")
350
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
351
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
352
+	result, src_request := service.Hbyb2208(psnNo, mdtrtId, setlId, org_name, doctor, secret_key, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
353
+	fmt.Println(src_request)
354
+	var dat map[string]interface{}
355
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
356
+		fmt.Println(dat)
357
+	} else {
358
+		fmt.Println(err)
359
+	}
360
+	c.ServeSuccessJSON(map[string]interface{}{
361
+		"pre": dat,
362
+	})
363
+}
364
+func (c *JSybController) PostTen() {
365
+	psnNo := c.GetString("psn_no")
366
+	mdtrtId := c.GetString("mdtrt_id")
367
+	setlId := c.GetString("setl_id")
368
+	org_name := c.GetString("org_name")
369
+	doctor := c.GetString("doctor")
370
+	med_type := c.GetString("med_type")
371
+
372
+	secret_key := c.GetString("secret_key")
373
+	fixmedins_code := c.GetString("fixmedins_code")
374
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
375
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
376
+
377
+	baseParams := models.BaseParams{
378
+		SecretKey:      secret_key,
379
+		FixmedinsCode:  fixmedins_code,
380
+		InsuplcAdmdvs:  insuplc_admdvs,
381
+		MdtrtareaAdmvs: mdtrtarea_admvs,
382
+		OrgName:        org_name,
383
+		Doctor:         doctor,
384
+	}
385
+
386
+	businessParams := models.BusinessParams{
387
+		PsnNo:   psnNo,
388
+		MdtrtId: mdtrtId,
389
+		SetlId:  setlId,
390
+	}
391
+
392
+	result := service.Hbyb5203(baseParams, businessParams, med_type)
393
+	var dat map[string]interface{}
394
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
395
+		fmt.Println(dat)
396
+	} else {
397
+		fmt.Println(err)
398
+	}
399
+	c.ServeSuccessJSON(map[string]interface{}{
400
+		"pre": dat,
401
+	})
402
+}

+ 9 - 9
controllers/sg/gdyb_controller.go Wyświetl plik

@@ -561,16 +561,16 @@ func (c *GdybController) PostZHFive() {
561 561
 	fmt.Println(respJSON["mdtrtarea_admvs"].(string))
562 562
 	fmt.Println(respJSON["secret_key"].(string))
563 563
 
564
-	result := service.ZHGdyb2301(respJSON["psn_no"].(string), respJSON["mdtrt_id"].(string), hp, respJSON["chrg_bchno"].(string), respJSON["org_name"].(string),
565
-		respJSON["doctor"].(string), respJSON["dept"].(string), respJSON["fixmedins_code"].(string), respJSON["dept_code"].(string), respJSON["doctor_id"].(string), respJSON["insuplc_admdvs"].(string), respJSON["mdtrtarea_admvs"].(string), respJSON["secret_key"].(string), respJSON["med_type"].(string))
564
+	//result := service.ZHGdyb2301(respJSON["psn_no"].(string), respJSON["mdtrt_id"].(string), hp, respJSON["chrg_bchno"].(string), respJSON["org_name"].(string),
565
+	//	respJSON["doctor"].(string), respJSON["dept"].(string), respJSON["fixmedins_code"].(string), respJSON["dept_code"].(string), respJSON["doctor_id"].(string), respJSON["insuplc_admdvs"].(string), respJSON["mdtrtarea_admvs"].(string), respJSON["secret_key"].(string), respJSON["med_type"].(string))
566 566
 
567
-	var dat map[string]interface{}
568
-	if err := json.Unmarshal([]byte(result), &dat); err == nil {
569
-		fmt.Println(dat)
570
-	} else {
571
-		fmt.Println(err)
572
-	}
567
+	//var dat map[string]interface{}
568
+	//if err := json.Unmarshal([]byte(result), &dat); err == nil {
569
+	//	fmt.Println(dat)
570
+	//} else {
571
+	//	fmt.Println(err)
572
+	//}
573 573
 	c.ServeSuccessJSON(map[string]interface{}{
574
-		"pre": dat,
574
+		"pre": "",
575 575
 	})
576 576
 }

+ 150 - 119
controllers/sg/his_api_controller.go Wyświetl plik

@@ -80,12 +80,6 @@ func HisManagerApiRegistRouters() {
80 80
 
81 81
 	beego.Router("/api/psn/info", &HisApiController{}, "get:GetPsnNcdsInfo")
82 82
 
83
-	//beego.Router("/api/checkdetailaccount/handle", &HisApiController{}, "get:HandleCheckDetailAccount")
84
-
85
-	//beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
86
-	//beego.Router("/api/testinit", &HisApiController{}, "get:TestGetBasBaseInit")
87
-	//beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
88
-
89 83
 }
90 84
 func (c *HisApiController) GetPsnNcdsInfo() {
91 85
 	admin_user_id, _ := c.GetInt64("admin_user_id")
@@ -512,19 +506,6 @@ func (c *HisApiController) GetBasBaseInfo() string {
512 506
 	return string(str)
513 507
 }
514 508
 
515
-func prttostr(vcode uintptr) string {
516
-	var vbyte []byte
517
-	for i := 0; i < 10; i++ {
518
-		sbyte := *((*byte)(unsafe.Pointer(vcode)))
519
-		if sbyte == 0 {
520
-			break
521
-		}
522
-		vbyte = append(vbyte, sbyte)
523
-		vcode += 1
524
-	}
525
-	return string(vbyte)
526
-}
527
-
528 509
 type CustomFundPay struct {
529 510
 	FundPayType string  `json:"fund_pay_type"`
530 511
 	FundPayamt  float64 `json:"fund_payamt"`
@@ -1786,90 +1767,6 @@ func (c *HisApiController) GetBatchSettleList() {
1786 1767
 	}
1787 1768
 }
1788 1769
 
1789
-//func (c *HisApiController) TestPay() {
1790
-//	DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
1791
-//	readCards := DllDef2.MustFindProc("BankTrans")
1792
-//	inputData := make(map[string]interface{})
1793
-//	inputData["transId"] = "05"
1794
-//	inputData["amount"] = "0.01"
1795
-//	inputData["traceNo"] = "20210227093601325405377"
1796
-//	inputData["cardNo"] = "F36084348"
1797
-//	inputData["id"] = "44022919620927046X"
1798
-//	//jsonStr := `
1799
-//	//    {
1800
-//	//            "transId": "05",
1801
-//	//            "amount":"1.00",
1802
-//	//            "traceNo":"20210227093601325405377",
1803
-//	//            "cardNo":"F36084348",
1804
-//	//            "id":"44022919620927046X"
1805
-//	//
1806
-//	//    }
1807
-//	//`
1808
-//
1809
-//	bytes_arr, _ := json.Marshal(inputData)
1810
-//	str3 := make([]byte, 256)
1811
-//	ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
1812
-//	fmt.Println(":", string(str3))
1813
-//
1814
-//	if err4 != nil {
1815
-//		fmt.Println("SSCard的运算结果为:", ret4)
1816
-//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
1817
-//		return
1818
-//	}
1819
-//
1820
-//}
1821
-
1822
-//func (c *HisApiController) TestGetBasBaseInfo() {
1823
-//
1824
-//	//result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
1825
-//	//fmt.Println(result)
1826
-//	//cs1 := C.CString("")
1827
-//	//cs2 := C.CString("")
1828
-//	//C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
1829
-//	//fmt.Println(cs1)
1830
-//	//fmt.Println(cs2)
1831
-//	//C.free(unsafe.Pointer(cs1))
1832
-//	//C.free(unsafe.Pointer(cs2))
1833
-//
1834
-//	//
1835
-//
1836
-//	DllDef := syscall.MustLoadDLL("SSCard.dll")
1837
-//	Iinit := DllDef.MustFindProc("Init")
1838
-//	readCard := DllDef.MustFindProc("ReadCardBas")
1839
-//	ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
1840
-//	if ret != 0 {
1841
-//		fmt.Println("SSCard的报错原因:", err)
1842
-//		fmt.Println("SSCard的运算结果为:", ret)
1843
-//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
1844
-//		return
1845
-//	}
1846
-//
1847
-//	result := int(ret)
1848
-//	fmt.Println("SSCard的运算结果为1:", result)
1849
-//
1850
-//	//path := ""
1851
-//	//bytePath := []byte(  "\x00")
1852
-//	//bytePath2 := []byte(  "\x00")
1853
-//	//ssss
1854
-//
1855
-//	str := make([]byte, 256)
1856
-//	str1 := make([]byte, 256)
1857
-//	s2 := []byte(string(str))
1858
-//	s3 := []byte(string(str1))
1859
-//	ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
1860
-//	fmt.Println(" Add(4,5)的结果为:", ret2)
1861
-//	fmt.Println(" str:", s2)
1862
-//	fmt.Println(" str1:", s3)
1863
-//	if err2 != nil {
1864
-//		fmt.Println("SSCard的运算结果为:", ret2)
1865
-//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
1866
-//		return
1867
-//	}
1868
-//
1869
-//	//DllDef := syscall.MustLoadDLL("SSCard.dll")
1870
-//
1871
-//}
1872
-
1873 1770
 func (c *HisApiController) GetOrgInfo() {
1874 1771
 	miConfig, _ := service.FindMedicalInsuranceInfo(4)
1875 1772
 	service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
@@ -2020,6 +1917,49 @@ func StrPtr(s string) uintptr {
2020 1917
 	return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
2021 1918
 }
2022 1919
 
1920
+type Result2001 struct {
1921
+	Cainfo      interface{} `json:"cainfo"`
1922
+	ErrMsg      string      `json:"err_msg"`
1923
+	InfRefmsgid string      `json:"inf_refmsgid"`
1924
+	Infcode     int64       `json:"infcode"`
1925
+	Output      struct {
1926
+		Trtinfo struct {
1927
+			PsnNo          string `json:"psn_no"`
1928
+			TrtChkType     string `json:"trt_chk_type"`
1929
+			FundPayType    string `json:"fund_pay_type"`
1930
+			TrtEnjymntFlag string `json:"trt_enjymnt_flag"`
1931
+			Begndate       string `json:"begndate"`
1932
+			Enddate        string `json:"enddate"`
1933
+			TrtChkRslt     string `json:"trt_chk_rslt"`
1934
+		} `json:"trtinfo"`
1935
+	} `json:"output"`
1936
+	RefmsgTime  string      `json:"refmsg_time"`
1937
+	RespondTime string      `json:"respond_time"`
1938
+	Signtype    interface{} `json:"signtype"`
1939
+	WarnMsg     interface{} `json:"warn_msg"`
1940
+}
1941
+type Result2001Org10265 struct {
1942
+	Cainfo      interface{} `json:"cainfo"`
1943
+	ErrMsg      string      `json:"err_msg"`
1944
+	InfRefmsgid string      `json:"inf_refmsgid"`
1945
+	Infcode     string      `json:"infcode"`
1946
+	Output      struct {
1947
+		Trtinfo struct {
1948
+			PsnNo          string `json:"psn_no"`
1949
+			TrtChkType     string `json:"trt_chk_type"`
1950
+			FundPayType    string `json:"fund_pay_type"`
1951
+			TrtEnjymntFlag string `json:"trt_enjymnt_flag"`
1952
+			Begndate       string `json:"begndate"`
1953
+			Enddate        string `json:"enddate"`
1954
+			TrtChkRslt     string `json:"trt_chk_rslt"`
1955
+		} `json:"trtinfo"`
1956
+	} `json:"output"`
1957
+	RefmsgTime  string      `json:"refmsg_time"`
1958
+	RespondTime string      `json:"respond_time"`
1959
+	Signtype    interface{} `json:"signtype"`
1960
+	WarnMsg     interface{} `json:"warn_msg"`
1961
+}
1962
+
2023 1963
 type ResultTwo struct {
2024 1964
 	ErrMsg      string `json:"err_msg"`
2025 1965
 	InfRefmsgid string `json:"inf_refmsgid"`
@@ -2996,6 +2936,41 @@ func (c *HisApiController) GetRegisterInfo() {
2996 2936
 			infoStr = psn_info.Insuinfo
2997 2937
 			idetinfoStr = psn_info.Idetinfo
2998 2938
 
2939
+		} else if miConfig.MdtrtareaAdmvs == "320921" {
2940
+			var res ResultTwo
2941
+			api := "http://192.168.3.130:9532/" + "jsyb/1101?cert_no=" + "" +
2942
+				"&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
2943
+				"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(certificates, 10) + "&url=" + miConfig.Url + "&ak=" + "fb4f41a047934d588a89cdac7a102410"
2944
+			resp, requestErr := http.Get(api)
2945
+			if requestErr != nil {
2946
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2947
+				return
2948
+			}
2949
+
2950
+			body, ioErr := ioutil.ReadAll(resp.Body)
2951
+			if ioErr != nil {
2952
+				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2953
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2954
+				return
2955
+			}
2956
+			var respJSON map[string]interface{}
2957
+			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2958
+				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2959
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2960
+				return
2961
+			}
2962
+
2963
+			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2964
+			result, _ := json.Marshal(respJSON)
2965
+			fmt.Println("log")
2966
+			fmt.Println(string(result))
2967
+
2968
+			if err := json.Unmarshal([]byte(result), &res); err != nil {
2969
+				utils.ErrorLog("解析失败:%v", err)
2970
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2971
+				return
2972
+			}
2973
+
2999 2974
 		} else {
3000 2975
 			result, requestLog := service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10), name)
3001 2976
 			saveLog(result, requestLog, "1101", "人员基本信息获取")
@@ -7156,25 +7131,47 @@ func (c *HisApiController) GetSettleAccounts() {
7156 7131
 }
7157 7132
 
7158 7133
 func (c *HisApiController) CheckTreatment() {
7159
-	patient_id, _ := c.GetInt64("patient_id", 0)
7160
-	record_time := c.GetString("record_time")
7134
+	patient_id, _ := c.GetInt64("patient_id")
7135
+	id_card_no := c.GetString("id_card_no")
7161 7136
 	insutype := c.GetString("insutype")
7137
+	med_type := c.GetString("med_type")
7138
+	admin_user_id, _ := c.GetInt64("admin_user_id")
7162 7139
 
7163
-	timeLayout := "2006-01-02"
7164
-	loc, _ := time.LoadLocation("Local")
7165 7140
 	adminUser := c.GetAdminUserInfo()
7166
-	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
7167
-	fmt.Println(err)
7168
-	if err != nil {
7169
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7170
-		return
7171
-	}
7172
-	recordDateTime := theTime.Unix()
7173
-	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
7174
-	patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
7141
+	patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
7175 7142
 
7176 7143
 	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
7177 7144
 	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
7145
+	roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
7146
+
7147
+	result := service.Gdyb1101A(id_card_no, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
7148
+	var dat map[string]interface{}
7149
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
7150
+		fmt.Println(dat)
7151
+	} else {
7152
+		fmt.Println(err)
7153
+	}
7154
+	userJSONBytes, _ := json.Marshal(dat)
7155
+	var res ResultTwo
7156
+	var res10265 ResultTwo10265
7157
+	if miConfig.Code == "H15049901371" {
7158
+		if err := json.Unmarshal(userJSONBytes, &res10265); err != nil {
7159
+			utils.ErrorLog("解析失败:%v", err)
7160
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7161
+			return
7162
+		}
7163
+		res.ErrMsg = res10265.ErrMsg
7164
+		infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
7165
+		res.Infcode = infocode
7166
+		res.Output = res10265.Output
7167
+		res.InfRefmsgid = res10265.InfRefmsgid
7168
+	} else {
7169
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
7170
+			utils.ErrorLog("解析失败:%v", err)
7171
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7172
+			return
7173
+		}
7174
+	}
7178 7175
 
7179 7176
 	var user_name string
7180 7177
 	role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
@@ -7194,16 +7191,50 @@ func (c *HisApiController) CheckTreatment() {
7194 7191
 	}
7195 7192
 
7196 7193
 	if config.IsOpen == 1 {
7197
-		result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
7194
+		if miConfig.Code == "H15049901371" {
7195
+			if med_type == "14" {
7196
+				if insutype == "390" {
7197
+					med_type = "9933"
7198
+				} else if insutype == "310" {
7199
+					med_type = "990502"
7200
+				}
7201
+			} else if med_type == "11" {
7202
+				med_type = "11"
7203
+			}
7204
+		}
7205
+		result := service.Gdyb2001(baseParams, res.Output.Baseinfo.PsnNo, insutype, med_type)
7198 7206
 		var dat map[string]interface{}
7199 7207
 		if err := json.Unmarshal([]byte(result), &dat); err == nil {
7200 7208
 			fmt.Println(dat)
7201 7209
 		} else {
7202 7210
 			fmt.Println(err)
7203 7211
 		}
7204
-
7212
+		var res Result2001
7213
+		var res10265 Result2001Org10265
7214
+		if miConfig.Code == "H15049901371" {
7215
+			if err := json.Unmarshal([]byte(result), &res10265); err != nil {
7216
+				utils.ErrorLog("解析失败:%v", err)
7217
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7218
+				return
7219
+			}
7220
+			res.ErrMsg = res10265.ErrMsg
7221
+			res.Output = res10265.Output
7222
+			res.InfRefmsgid = res10265.InfRefmsgid
7223
+			infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
7224
+			res.Infcode = infocode
7225
+		} else {
7226
+			if err := json.Unmarshal([]byte(result), &res); err != nil {
7227
+				utils.ErrorLog("解析失败:%v", err)
7228
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7229
+				return
7230
+			}
7231
+		}
7232
+		if res.Infcode == 0 {
7233
+			c.ServeSuccessJSON(map[string]interface{}{
7234
+				"msg": res.Output.Trtinfo,
7235
+			})
7236
+		}
7205 7237
 	}
7206
-
7207 7238
 }
7208 7239
 
7209 7240
 //func (c *HisApiController) PutRecord() {

+ 21 - 23
controllers/zh/zh_his_api_controller.go Wyświetl plik

@@ -1,7 +1,6 @@
1 1
 package zh
2 2
 
3 3
 import (
4
-	"bytes"
5 4
 	"encoding/json"
6 5
 	"fmt"
7 6
 	"gdyb/controllers"
@@ -11,10 +10,8 @@ import (
11 10
 	"gdyb/utils"
12 11
 	"github.com/astaxie/beego"
13 12
 	"github.com/axgle/mahonia"
14
-	"io/ioutil"
15 13
 	"math"
16 14
 	"math/rand"
17
-	"net/http"
18 15
 	"os"
19 16
 	"strconv"
20 17
 	"strings"
@@ -1355,7 +1352,7 @@ func (c *ZHHisApiController) GetUploadInfo() {
1355 1352
 	department, _ := service.GetDepartMentDetail(record.Departments)
1356 1353
 	strconv.FormatInt(record.PatientId, 10)
1357 1354
 
1358
-	client := &http.Client{}
1355
+	//client := &http.Client{}
1359 1356
 	data["psn_no"] = record.PsnNo
1360 1357
 	data["mdtrt_id"] = record.Number
1361 1358
 	data["chrg_bchno"] = chrg_bchno
@@ -1501,26 +1498,27 @@ func (c *ZHHisApiController) GetUploadInfo() {
1501 1498
 				stop = len(customs)
1502 1499
 			}
1503 1500
 
1504
-			data["pre"] = customs[start-1 : stop]
1505
-			bytesData, _ := json.Marshal(data)
1506
-			req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
1507
-			resp, _ := client.Do(req)
1508
-			defer resp.Body.Close()
1509
-			body, ioErr := ioutil.ReadAll(resp.Body)
1510
-			if ioErr != nil {
1511
-				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1512
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1513
-				return
1514
-			}
1515
-			var respJSON map[string]interface{}
1516
-			if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
1517
-				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1518
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1519
-				return
1520
-			}
1501
+			//data["pre"] = customs[start-1 : stop]
1502
+			//bytesData, _ := json.Marshal(data)
1503
+			//req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
1504
+			//resp, _ := client.Do(req)
1505
+			//defer resp.Body.Close()
1506
+			//body, ioErr := ioutil.ReadAll(resp.Body)
1507
+			//if ioErr != nil {
1508
+			//	utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1509
+			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1510
+			//	return
1511
+			//}
1512
+			resultLog, requestLog := service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string))
1513
+			saveLog(resultLog, requestLog, "2301", "上传明细")
1521 1514
 
1522
-			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1523
-			userJSONBytes, _ := json.Marshal(respJSON)
1515
+			var dat map[string]interface{}
1516
+			if err := json.Unmarshal([]byte(resultLog), &dat); err == nil {
1517
+				fmt.Println(dat)
1518
+			} else {
1519
+				fmt.Println(err)
1520
+			}
1521
+			userJSONBytes, _ := json.Marshal(dat)
1524 1522
 			var res ResultFour
1525 1523
 			var resFour10265 ResultFour10265
1526 1524
 			if miConfig.Code == "H15049901371" {

+ 0 - 1
main.go Wyświetl plik

@@ -5,7 +5,6 @@ import (
5 5
 	"fmt"
6 6
 	"gdyb/models"
7 7
 	_ "gdyb/routers"
8
-	"gdyb/service"
9 8
 	"github.com/astaxie/beego"
10 9
 	"github.com/qiniu/api.v7/auth/qbox"
11 10
 	"github.com/qiniu/api.v7/storage"

+ 1 - 0
models/his_models.go Wyświetl plik

@@ -857,6 +857,7 @@ type MedicalInsuranceOrgConfig struct {
857 857
 	MdtrtareaAdmvs string `gorm:"column:mdtrtarea_admvs" json:"mdtrtarea_admvs" form:"mdtrtarea_admvs"`
858 858
 	InsuplcAdmdvs  string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
859 859
 	SecretKey      string `gorm:"column:secret_key" json:"secret_key" form:"secret_key"`
860
+	Url            string `gorm:"column:url" json:"url" form:"url"`
860 861
 }
861 862
 
862 863
 func (MedicalInsuranceOrgConfig) TableName() string {

+ 4 - 3
routers/router.go Wyświetl plik

@@ -1,10 +1,10 @@
1 1
 package routers
2 2
 
3 3
 import (
4
-	//"gdyb/controllers/sz"
5
-
6 4
 	"gdyb/controllers/hb"
5
+	"gdyb/controllers/js"
7 6
 	"gdyb/controllers/sg"
7
+	"gdyb/controllers/sz"
8 8
 	"gdyb/controllers/zh"
9 9
 
10 10
 	//"gdyb/controllers/sz"
@@ -27,7 +27,8 @@ func init() {
27 27
 	sg.HisManagerApiRegistRouters()
28 28
 	sg.GdybRegistRouters()
29 29
 	hb.HbybRegistRouters()
30
-	//sz.SZHisManagerApiRegistRouters()
30
+	sz.SZHisManagerApiRegistRouters()
31 31
 	zh.ZHHisManagerApiRegistRouters()
32
+	js.JSybRegistRouters()
32 33
 
33 34
 }

+ 1 - 6
service/gdyb_service.go Wyświetl plik

@@ -513,9 +513,7 @@ func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string,
513 513
 		}
514 514
 
515 515
 		request.Header.Set("Content-Type", "application/json;charset=UTF-8")
516
-		//request.Header.Set("x-tif-paasid", "test_hosp")
517 516
 		request.Header.Set("x-tif-paasid", gdyb_paasid)
518
-
519 517
 		request.Header.Set("x-tif-signature", signature)
520 518
 		request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
521 519
 		request.Header.Set("x-tif-nonce", nonce)
@@ -2046,6 +2044,7 @@ func Gdyb2001(baseParams models.BaseParams, psn_no string, insutype string, med_
2046 2044
 	if med_type == "1111" || med_type == "1112" {
2047 2045
 		med_type = "11"
2048 2046
 	}
2047
+
2049 2048
 	// 生成签名
2050 2049
 	nonce := GetRandomString(32)
2051 2050
 	timestamp := time.Now().Unix()
@@ -3714,7 +3713,3 @@ func Gdyb90100(psn_no string, org_name string, doctor string, fixmedins_code str
3714 3713
 	str := string(respBytes)
3715 3714
 	return str
3716 3715
 }
3717
-
3718
-//func StrPtr(s string) uintptr {
3719
-//	return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
3720
-//}

+ 107 - 0
service/jsyb_service.go Wyświetl plik

@@ -0,0 +1,107 @@
1
+package service
2
+
3
+import (
4
+	"crypto/hmac"
5
+	"crypto/sha1"
6
+	"encoding/base64"
7
+	"encoding/json"
8
+	"fmt"
9
+	"gdyb/utils/csbhttp"
10
+	"strconv"
11
+	"time"
12
+)
13
+
14
+// 人员基本信息
15
+func Jsyb1101(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, certificates string, request_url string, access_key string) (string, string) {
16
+	//生成签名
17
+	nonce := GetRandomString(32)
18
+	timestamp := time.Now().Unix()
19
+	//signature := setSignature(timestamp, nonce, secret_key)
20
+	//生成输入报文
21
+	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
22
+
23
+	input := make(map[string]interface{})
24
+	inputData := make(map[string]interface{})
25
+	inputMessage["infno"] = "1101" // 交易编码
26
+
27
+	if certificates == "3" {
28
+		inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
29
+		inputData["certno"] = certNo        // 证件号码
30
+		inputData["psn_cert_type"] = "99"   // 人员证件类型
31
+
32
+	} else {
33
+		if id_card_type == 1 {
34
+			inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
35
+			inputData["card_sn"] = card_sn      // 卡识别码
36
+			inputData["certno"] = certNo        // 证件号码
37
+			inputData["psn_cert_type"] = "01"   // 人员证件类型
38
+
39
+		} else {
40
+			inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
41
+			inputData["card_sn"] = ""           // 卡识别码
42
+			inputData["certno"] = certNo        // 证件号码
43
+			inputData["psn_cert_type"] = "01"   // 人员证件类型
44
+		}
45
+	}
46
+
47
+	inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
48
+	inputData["begntime"] = ""          // 开始时间
49
+	inputData["psn_name"] = ""          // 人员姓名
50
+	input["data"] = inputData
51
+	inputMessage["input"] = input //交易输入
52
+
53
+	var inputLog string
54
+	bytesData, err := json.Marshal(inputMessage)
55
+	inputLog = string(bytesData)
56
+	fmt.Println(string(bytesData))
57
+	if err != nil {
58
+		fmt.Println(err.Error())
59
+		return err.Error(), ""
60
+	}
61
+
62
+	return HttpRequest(request_url, access_key, secret_key, timestamp, bytesData, string(bytesData)), inputLog
63
+
64
+}
65
+func HttpRequest(url string, ak string, sk string, timestamp int64, requestByte []byte, json string) string {
66
+
67
+	//step 1. 设置请求参数
68
+	csbHP := csbhttp.NewHttpParams(url) //设置请求地址及url参数
69
+	//设置调用方式 get 或者 post
70
+	csbHP.SetMethod("post")
71
+	//设置 调用的服务名和版本
72
+	csbHP.SetApi("hssServives")
73
+	csbHP.SetVersion("1.0.0")
74
+
75
+	//添加附加的http请求头 (可以定义多条)
76
+	key := "_api_access_key=" + ak + "&_api_name=" + "hssServives" + "&_api_timestamp=" + strconv.FormatInt(timestamp, 10) + "&_api_version=" + "1.0.0"
77
+	csbHP.AddHeader("_api_timestamp", strconv.FormatInt(timestamp, 10))
78
+	csbHP.AddHeader("_api_name", "hssServives")
79
+	csbHP.AddHeader("_api_version", "1.0.0")
80
+	csbHP.AddHeader("_api_access_key", ak)
81
+	csbHP.AddHeader("_api_signature", hmacsha1(key, sk))
82
+	//还可以,设置附加的byte[]或者json请求体
83
+	csbHP.SetContentBody(json, requestByte)
84
+	//设置请求的ak和sk
85
+	csbHP.SetAK(ak)
86
+	csbHP.SetSK(sk)
87
+	//打印请求参数信息
88
+	csbHP.Print()
89
+	//进行调用, 返回的第二项为resonse http headers (map[string][]string类型)
90
+	res, _, err := csbhttp.Invoke(*csbHP)
91
+	//是否发成错误
92
+	if err != nil {
93
+		fmt.Println(err)
94
+		return ""
95
+	}
96
+	return res
97
+}
98
+func hmacsha1(keyStr, value string) string {
99
+
100
+	key := []byte(keyStr)
101
+	mac := hmac.New(sha1.New, key)
102
+	mac.Write([]byte(value))
103
+	//进行base64编码
104
+	res := base64.StdEncoding.EncodeToString(mac.Sum(nil))
105
+
106
+	return res
107
+}

+ 7 - 6
service/zh_his_service.go Wyświetl plik

@@ -554,7 +554,7 @@ type ZHResult struct {
554 554
 }
555 555
 
556 556
 //  住院费用明细信息上传
557
-func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCustom, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, med_type string) string {
557
+func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCustom, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, med_type string) (string, string) {
558 558
 	// 生成签名
559 559
 	nonce := GetRandomString(32)
560 560
 	timestamp := time.Now().Unix()
@@ -632,10 +632,11 @@ func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCusto
632 632
 	fmt.Println("----------")
633 633
 	fmt.Println(string(bytesData))
634 634
 	fmt.Println("----------")
635
+	requestLog := string(bytesData)
635 636
 
636 637
 	if err != nil {
637 638
 		fmt.Println(err.Error())
638
-		return ""
639
+		return "", ""
639 640
 	}
640 641
 	reader := bytes.NewReader(bytesData)
641 642
 
@@ -648,7 +649,7 @@ func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCusto
648 649
 	request, err := http.NewRequest("POST", url, reader)
649 650
 	if err != nil {
650 651
 		fmt.Println(err.Error())
651
-		return ""
652
+		return "", ""
652 653
 	}
653 654
 
654 655
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -661,14 +662,14 @@ func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCusto
661 662
 	resp, err := client.Do(request)
662 663
 	if err != nil {
663 664
 		fmt.Println(err.Error())
664
-		return ""
665
+		return "", ""
665 666
 	}
666 667
 	respBytes, err := ioutil.ReadAll(resp.Body)
667 668
 	if err != nil {
668 669
 		fmt.Println(err.Error())
669
-		return ""
670
+		return "", ""
670 671
 	}
671
-	return string(respBytes)
672
+	return string(respBytes), requestLog
672 673
 
673 674
 }
674 675
 

+ 294 - 0
utils/csbhttp/httpcaller.go Wyświetl plik

@@ -0,0 +1,294 @@
1
+/**
2
+Copyright 1999-2017 Alibaba Group Holding Ltd.
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+CSB-HTTP-SDK based on GO language.
17
+
18
+*/
19
+package csbhttp
20
+
21
+import (
22
+	"bytes"
23
+	"encoding/json"
24
+	"fmt"
25
+	"io/ioutil"
26
+	"net"
27
+	"net/http"
28
+	"net/url"
29
+	"strconv"
30
+	"strings"
31
+	"sync"
32
+	//"crypto/tls"
33
+	"time"
34
+)
35
+
36
+var settingMutex sync.Mutex
37
+
38
+const (
39
+	CSB_SDK_VERSION = "1.1.0"
40
+
41
+	API_NAME_KEY               = "_api_name"
42
+	VERSION_KEY                = "_api_version"
43
+	ACCESS_KEY                 = "_api_access_key"
44
+	SECRET_KEY                 = "_api_secret_key"
45
+	SIGNATURE_KEY              = "_api_signature"
46
+	TIMESTAMP_KEY              = "_api_timestamp"
47
+	RESTFUL_PATH_SIGNATURE_KEY = "csb_restful_path_signature_key" //TODO: fix the terrible key name!
48
+)
49
+
50
+/**
51
+CSBHttp的基本设置结构
52
+*/
53
+type CSBHTTPSettings struct {
54
+	ShowDebug        bool          //  "运行时是否显示调试信息"
55
+	UserAgent        string        //  "调用CSB服务的客户端代理, 默认为 csbBroker"
56
+	ConnectTimeout   time.Duration //  "连接超时时间"
57
+	ReadWriteTimeout time.Duration //  "读写超时时间"
58
+
59
+	Retries                int  // if set to -1 means will retry forever
60
+	CareResponseHttpHeader bool // if return the response http headers
61
+	SignPath               bool
62
+
63
+	/* TODO:support the following fields
64
+	TLSClientConfig  *tls.Config
65
+	Proxy            func(*http.Request) (*url.URL, error)
66
+	Transport        http.RoundTripper
67
+	CheckRedirect    func(req *http.Request, via []*http.Request) error
68
+	EnableCookie     bool
69
+	*/
70
+}
71
+
72
+var defaultSetting = CSBHTTPSettings{
73
+	ShowDebug:              true,
74
+	UserAgent:              "csbBroker",
75
+	ConnectTimeout:         60 * time.Second,
76
+	ReadWriteTimeout:       60 * time.Second,
77
+	CareResponseHttpHeader: true,
78
+}
79
+
80
+/**
81
+  定义自己的http属性的结构来覆盖默认的设置
82
+*/
83
+func SetDefaultSetting(setting CSBHTTPSettings) {
84
+	settingMutex.Lock()
85
+	defer settingMutex.Unlock()
86
+	defaultSetting = setting
87
+}
88
+
89
+/**
90
+内部方法: 拼接请求参数
91
+*/
92
+func appendParams(reqUrl string, params string) string {
93
+	if strings.Contains(reqUrl, "?") {
94
+		return reqUrl + "&" + params
95
+	} else {
96
+		return reqUrl + "?" + params
97
+	}
98
+}
99
+
100
+/**
101
+内部方法: 将请求串中的请求参数装换为map
102
+*/
103
+func parseUrlParamsMap(reqUrl string) (params map[string]string, err *HttpCallerException) {
104
+	params = make(map[string]string) //must init the map
105
+	if strings.Contains(reqUrl, "?") {
106
+		i := strings.Index(reqUrl, "?")
107
+		reqUrl = string(reqUrl[i+1:])
108
+		fmt.Println(reqUrl)
109
+		kvs := strings.Split(reqUrl, "&")
110
+
111
+		if len(kvs) > 0 {
112
+			for _, kv := range kvs {
113
+				i = strings.Index(kv, "=")
114
+				if i >= 0 {
115
+					params[string(kv[0:i])] = string(kv[i+1:])
116
+				} else {
117
+					//TODO: write or throw exception
118
+					fmt.Errorf("bad kv pair:", kv)
119
+				}
120
+			}
121
+		}
122
+	}
123
+	return params, nil
124
+}
125
+
126
+/**
127
+内部方法: 进行参数的签名处理
128
+*/
129
+func signParams(params map[string]string, api string, version string, ak string, sk string) (headMaps map[string]string) {
130
+	headMaps = make(map[string]string)
131
+
132
+	params[API_NAME_KEY] = api
133
+	headMaps[API_NAME_KEY] = api
134
+
135
+	params[VERSION_KEY] = version
136
+	headMaps[VERSION_KEY] = version
137
+
138
+	//https://currentmillis.com/  calc current time with varies languages
139
+	v := time.Now().UnixNano() / 1000000
140
+	params[TIMESTAMP_KEY] = strconv.FormatInt(v, 10)
141
+	headMaps[TIMESTAMP_KEY] = strconv.FormatInt(v, 10)
142
+
143
+	if ak != "" {
144
+		params[ACCESS_KEY] = ak
145
+		headMaps[ACCESS_KEY] = ak
146
+
147
+		delete(params, SECRET_KEY)
148
+		delete(params, SIGNATURE_KEY)
149
+
150
+		signValue := doSign(params, sk)
151
+
152
+		headMaps[SIGNATURE_KEY] = signValue
153
+	}
154
+
155
+	return headMaps
156
+}
157
+
158
+/**
159
+调用CSB开放出来的服务(后者CSB控制台的Open API),并放回结果
160
+
161
+请求参数的内容根据 HttpParams 的定义进行设置
162
+
163
+返回的结果包含: 调用fa返回结果串, 返回的httpheaders 和 异常
164
+当处理正常时,异常为nil
165
+
166
+*/
167
+func Invoke(params HttpParams) (str string, rtnHeaders map[string][]string, hcError *HttpCallerException) {
168
+	//init rtnHeaders
169
+	rtnHeaders = make(map[string][]string)
170
+
171
+	hcError = params.Validate()
172
+	if hcError != nil {
173
+		return str, rtnHeaders, hcError
174
+	}
175
+
176
+	_, err := url.Parse(params.requestUrl)
177
+	if err != nil {
178
+		return str, rtnHeaders, &HttpCallerException{CauseErr: err}
179
+	}
180
+
181
+	client := &http.Client{
182
+		Transport: &http.Transport{
183
+			Dial: func(netw, addr string) (net.Conn, error) {
184
+				conn, err := net.DialTimeout(netw, addr, defaultSetting.ConnectTimeout) //设置建立连接超时
185
+				if err != nil {
186
+					return nil, err
187
+				}
188
+				conn.SetDeadline(time.Now().Add(defaultSetting.ReadWriteTimeout)) //设置发送接受数据超时
189
+				return conn, nil
190
+			},
191
+			ResponseHeaderTimeout: time.Second * 2,
192
+		},
193
+	}
194
+
195
+	//resp := &http.Response{}
196
+	//for request parmas
197
+	data := url.Values{}
198
+	if params.params != nil {
199
+		for k, v := range params.params {
200
+			//strParams += fmt.Sprintf("%s=%s", k, url.QueryEscape())
201
+			data.Set(k, v)
202
+		}
203
+	}
204
+	var reqStr string
205
+	var method string
206
+	//method := "GET"
207
+	if params.method == "post" {
208
+		//genSignHeaders
209
+		method = "POST"
210
+	} else {
211
+		method = "GET"
212
+	}
213
+
214
+	reqUrl := params.requestUrl
215
+
216
+	defaultContentType := "application/x-www-form-urlencoded"
217
+	if params.ct.jsonBody != "" {
218
+		_, err = json.Marshal(params.ct.jsonBody)
219
+		if err == nil {
220
+			return str, rtnHeaders, &HttpCallerException{Message: "failed to bad content type json string", CauseErr: err}
221
+		}
222
+		reqStr = params.ct.jsonBody
223
+		defaultContentType = params.ct.contentType
224
+		reqUrl = appendParams(reqUrl, data.Encode())
225
+	} else if params.ct.bytesBody != nil {
226
+		reqStr = string(params.ct.bytesBody)
227
+		defaultContentType = params.ct.contentType
228
+		reqUrl = appendParams(reqUrl, data.Encode())
229
+	} else {
230
+		reqStr = data.Encode()
231
+	}
232
+
233
+	req, err := http.NewRequest(method, reqUrl, bytes.NewBufferString(reqStr))
234
+
235
+	if err != nil {
236
+		return str, rtnHeaders, &HttpCallerException{Message: "failed to construct http post request", CauseErr: err}
237
+	}
238
+
239
+	//set signature related headers
240
+	urlParams, hcError := parseUrlParamsMap(params.requestUrl)
241
+	if err != nil {
242
+		return str, rtnHeaders, hcError
243
+	}
244
+	printDebug("urlparams", urlParams)
245
+	mergeTwoMaps(urlParams, params.params)
246
+	printDebug("merged urlparams", urlParams)
247
+	signHeaders := signParams(urlParams, params.api, params.version, params.ak, params.sk)
248
+	printDebug("signHeaders", signHeaders)
249
+
250
+	req.Header.Add("Content-Type", defaultContentType)
251
+	if params.headers != nil {
252
+		for k, v := range params.headers {
253
+			req.Header.Add(k, v)
254
+		}
255
+	}
256
+	//add sign related headers
257
+	if signHeaders != nil {
258
+		for k, v := range signHeaders {
259
+			req.Header.Add(k, v)
260
+		}
261
+	}
262
+
263
+	//client.Timeout
264
+	resp, err := client.Do(req)
265
+
266
+	if err != nil {
267
+		return str, rtnHeaders, &HttpCallerException{Message: "failed to invoke http post", CauseErr: err}
268
+	}
269
+
270
+	if err != nil {
271
+		fmt.Println(err)
272
+	}
273
+
274
+	defer resp.Body.Close()
275
+
276
+	body, err := ioutil.ReadAll(resp.Body)
277
+	if err != nil {
278
+		fmt.Println(err)
279
+	}
280
+	str = string(body)
281
+	if defaultSetting.CareResponseHttpHeader {
282
+		rtnHeaders = resp.Header
283
+	}
284
+	/*
285
+		fmt.Println("jsonStr", jsonStr)
286
+		var dat map[string]string
287
+		if err := json.Unmarshal([]byte(jsonStr), &dat); err == nil {
288
+			fmt.Println("token", dat["token"])
289
+		} else {
290
+			fmt.Println("json str to struct error")
291
+		}
292
+	*/
293
+	return str, rtnHeaders, nil
294
+}

+ 36 - 0
utils/csbhttp/httpexception.go Wyświetl plik

@@ -0,0 +1,36 @@
1
+/**
2
+Copyright 1999-2017 Alibaba Group Holding Ltd.
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+CSB-HTTP-SDK based on GO language.
17
+
18
+*/
19
+
20
+package csbhttp
21
+
22
+import "fmt"
23
+
24
+/**
25
+  CSB调用异常结构
26
+*/
27
+type HttpCallerException struct {
28
+	Message   string `xml:"Message"`   // CSB给出的详细错误信息
29
+	RequestID string `xml:"RequestId"` // 用于唯一标识该次请求的UUID
30
+	CauseErr  error  //具体的error
31
+}
32
+
33
+// Implement interface error
34
+func (e HttpCallerException) Error() string {
35
+	return fmt.Sprintf("csb: service returned error: ErrorMessage=%s, RequestId=%s, CauseErr=%v", e.Message, e.RequestID, e.CauseErr)
36
+}

+ 154 - 0
utils/csbhttp/httpparams.go Wyświetl plik

@@ -0,0 +1,154 @@
1
+/**
2
+Copyright 1999-2017 Alibaba Group Holding Ltd.
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+CSB-HTTP-SDK based on GO language.
17
+
18
+*/
19
+package csbhttp
20
+
21
+import (
22
+	"encoding/json"
23
+	"fmt"
24
+	"strings"
25
+)
26
+
27
+/**
28
+构造Http请求参数的struct
29
+*/
30
+const (
31
+	JSON   = "application/json"
32
+	BINARY = "application/octet-stream"
33
+)
34
+
35
+type contentBody struct {
36
+	jsonBody    string
37
+	bytesBody   []byte
38
+	contentType string
39
+}
40
+
41
+type (
42
+	HttpParams struct {
43
+		method     string // "设置方法: get, post"
44
+		api        string
45
+		version    string
46
+		ak         string
47
+		sk         string
48
+		requestUrl string
49
+		params     map[string]string // "form 参数对"
50
+		headers    map[string]string // "http headers"
51
+		ct         contentBody       //  "设置传输的jsonBody 或者 byte[]"
52
+	}
53
+	Builder func(map[string]HttpParams) string
54
+)
55
+
56
+func NewHttpParams(reqUrl string) *HttpParams {
57
+	hp := HttpParams{
58
+		requestUrl: reqUrl,
59
+		method:     "get",
60
+		params:     make(map[string]string),
61
+		headers:    make(map[string]string),
62
+	}
63
+
64
+	hp.ct.contentType = "unknown"
65
+
66
+	return &hp
67
+}
68
+
69
+func (hp *HttpParams) SetApi(api string) *HttpParams {
70
+	hp.api = api
71
+	return hp
72
+}
73
+
74
+func (hp *HttpParams) SetVersion(version string) *HttpParams {
75
+	hp.version = version
76
+	return hp
77
+}
78
+
79
+func (hp *HttpParams) SetAK(ak string) *HttpParams {
80
+	hp.ak = ak
81
+	return hp
82
+}
83
+
84
+func (hp *HttpParams) SetSK(sk string) *HttpParams {
85
+	hp.sk = sk
86
+	return hp
87
+}
88
+
89
+func (hp *HttpParams) SetRequest(reqUrl string) *HttpParams {
90
+	hp.requestUrl = reqUrl
91
+	return hp
92
+}
93
+
94
+func (hp *HttpParams) SetMethod(method string) *HttpParams {
95
+	hp.method = method
96
+	return hp
97
+}
98
+
99
+func (hp *HttpParams) AddParam(key string, value string) *HttpParams {
100
+	hp.params[key] = value
101
+	return hp
102
+}
103
+
104
+func (hp *HttpParams) AddHeader(key string, value string) *HttpParams {
105
+	hp.headers[key] = value
106
+	return hp
107
+}
108
+
109
+func (hp *HttpParams) SetContentBody(jsonStr string, byteArr []byte) error {
110
+	if jsonStr != "" && byteArr != nil {
111
+		errRtn := HttpCallerException{Message: "can not set jsonStr and byteArr parameters together!"}
112
+		return errRtn
113
+	}
114
+
115
+	if jsonStr != "" {
116
+		hp.ct.jsonBody = jsonStr
117
+		hp.ct.contentType = JSON
118
+	}
119
+
120
+	if byteArr != nil {
121
+		hp.ct.bytesBody = byteArr //TODO: copy or pointer ?
122
+		hp.ct.contentType = BINARY
123
+	}
124
+
125
+	return nil
126
+}
127
+
128
+/**
129
+校验设置的请求参数项是否有效
130
+*/
131
+func (hp *HttpParams) Validate() *HttpCallerException {
132
+	hp.method = strings.ToLower(hp.method)
133
+	if hp.method != "get" && hp.method != "post" {
134
+		return &HttpCallerException{Message: "bad method, only support 'get' or 'post'"}
135
+	}
136
+
137
+	if hp.ak != "" && hp.sk == "" {
138
+		return &HttpCallerException{Message: "bad request params, ak and sk must be defined together"}
139
+	}
140
+
141
+	if hp.api == "" || hp.version == "" {
142
+		return &HttpCallerException{Message: "bad request params, api or version is not defined"}
143
+	}
144
+
145
+	return nil
146
+}
147
+
148
+/**
149
+打印设置的参数值
150
+*/
151
+func (hp *HttpParams) Print() {
152
+	j, _ := json.Marshal(*hp)
153
+	fmt.Println(string(j))
154
+}

+ 102 - 0
utils/csbhttp/signutil.go Wyświetl plik

@@ -0,0 +1,102 @@
1
+/**
2
+Copyright 1999-2017 Alibaba Group Holding Ltd.
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+CSB-HTTP-SDK based on GO language.
17
+
18
+*/
19
+package csbhttp
20
+
21
+import (
22
+	"bytes"
23
+	"crypto/hmac"
24
+	"crypto/sha1"
25
+	"encoding/base64"
26
+	"hash"
27
+	"io"
28
+	"sort"
29
+)
30
+
31
+/**
32
+  签名处理逻辑
33
+  将请求map中的key按字典顺序排序,然后使用secretKey进行签名处理
34
+*/
35
+
36
+// 用于signParms的字典排序存放容器。
37
+type paramsSorter struct {
38
+	Keys []string
39
+	Vals []string
40
+}
41
+
42
+// params map 转换为paramsSorter格式
43
+func newParamsSorter(m map[string]string) *paramsSorter {
44
+	hs := &paramsSorter{
45
+		Keys: make([]string, 0, len(m)),
46
+		Vals: make([]string, 0, len(m)),
47
+	}
48
+
49
+	for k, v := range m {
50
+		hs.Keys = append(hs.Keys, k)
51
+		hs.Vals = append(hs.Vals, v)
52
+	}
53
+	return hs
54
+}
55
+
56
+// 进行字典顺序排序 sort required method
57
+func (hs *paramsSorter) Sort() {
58
+	sort.Sort(hs)
59
+}
60
+
61
+// Additional function for function  sort required method
62
+func (hs *paramsSorter) Len() int {
63
+	return len(hs.Vals)
64
+}
65
+
66
+// Additional function for function  sort required method
67
+func (hs *paramsSorter) Less(i, j int) bool {
68
+	return bytes.Compare([]byte(hs.Keys[i]), []byte(hs.Keys[j])) < 0
69
+}
70
+
71
+// Additional function for function paramsSorter.
72
+func (hs *paramsSorter) Swap(i, j int) {
73
+	hs.Vals[i], hs.Vals[j] = hs.Vals[j], hs.Vals[i]
74
+	hs.Keys[i], hs.Keys[j] = hs.Keys[j], hs.Keys[i]
75
+}
76
+
77
+// 做签名处理
78
+func doSign(params map[string]string, secretKey string) string {
79
+	hs := newParamsSorter(params)
80
+
81
+	// Sort the temp by the Ascending Order
82
+	hs.Sort()
83
+
84
+	// Get the CanonicalizedOSSHeaders
85
+	canonicalizedParams := ""
86
+	for i := range hs.Keys {
87
+		if i > 0 {
88
+			canonicalizedParams += "&"
89
+		}
90
+		canonicalizedParams += hs.Keys[i] + "=" + hs.Vals[i]
91
+	}
92
+
93
+	printDebug("canonicalizedParams", canonicalizedParams)
94
+
95
+	signStr := canonicalizedParams
96
+
97
+	h := hmac.New(func() hash.Hash { return sha1.New() }, []byte(secretKey))
98
+	io.WriteString(h, signStr)
99
+	signedStr := base64.StdEncoding.EncodeToString(h.Sum(nil))
100
+
101
+	return signedStr
102
+}

+ 38 - 0
utils/csbhttp/utils.go Wyświetl plik

@@ -0,0 +1,38 @@
1
+/**
2
+Copyright 1999-2017 Alibaba Group Holding Ltd.
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+CSB-HTTP-SDK based on GO language.
17
+
18
+*/
19
+package csbhttp
20
+
21
+import "fmt"
22
+
23
+/**
24
+  工具相关的方法定义在这个文件中
25
+*/
26
+// print debug info
27
+func printDebug(prompt string, a ...interface{}) {
28
+	if defaultSetting.ShowDebug {
29
+		fmt.Println(prompt, a)
30
+	}
31
+}
32
+
33
+// merge two maps
34
+func mergeTwoMaps(toMap map[string]string, fromMap map[string]string) {
35
+	for k, v := range fromMap {
36
+		toMap[k] = v
37
+	}
38
+}