|
@@ -4,11 +4,15 @@ import (
|
4
|
4
|
"encoding/json"
|
5
|
5
|
"fmt"
|
6
|
6
|
"gdyb/controllers"
|
|
7
|
+ "gdyb/enums"
|
7
|
8
|
"gdyb/models"
|
8
|
9
|
"gdyb/service"
|
9
|
10
|
"gdyb/utils"
|
10
|
11
|
"github.com/astaxie/beego"
|
|
12
|
+ "github.com/axgle/mahonia"
|
11
|
13
|
"io/ioutil"
|
|
14
|
+ "syscall"
|
|
15
|
+ "unsafe"
|
12
|
16
|
)
|
13
|
17
|
|
14
|
18
|
type JSybController struct {
|
|
@@ -26,7 +30,7 @@ func JSybRegistRouters() {
|
26
|
30
|
beego.Router("/jsyb/2207", &JSybController{}, "get:PostEight")
|
27
|
31
|
beego.Router("/jsyb/2208", &JSybController{}, "get:PostNine")
|
28
|
32
|
beego.Router("/jsyb/5203", &JSybController{}, "get:PostTen")
|
29
|
|
- //beego.Router("/jsyb/readcard", &JSybController{}, "get:ReadCard")
|
|
33
|
+ beego.Router("/jsyb/readcard", &JSybController{}, "get:ReadCard")
|
30
|
34
|
|
31
|
35
|
}
|
32
|
36
|
|
|
@@ -462,29 +466,96 @@ func (c *JSybController) PostTen() {
|
462
|
466
|
})
|
463
|
467
|
}
|
464
|
468
|
|
465
|
|
-//var initFlag int64 = 0
|
466
|
|
-
|
467
|
|
-//func (c *JSybController) ReadCard() {
|
468
|
|
-// if initFlag == 0 {
|
469
|
|
-// c.TestGetBasBaseInit()
|
470
|
|
-// }
|
471
|
|
-//}
|
472
|
|
-//
|
473
|
|
-//func (c *JSybController) TestGetBasBaseInit() {
|
474
|
|
-// DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
|
475
|
|
-// Iinit := DllDef.MustFindProc("Init")
|
476
|
|
-// miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
|
477
|
|
-//
|
478
|
|
-// ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.InsuplcAdmdvs))
|
479
|
|
-// if ret != 0 {
|
480
|
|
-// fmt.Println("SSCard的报错原因:", err)
|
481
|
|
-// fmt.Println("SSCard的运算结果为:", ret)
|
482
|
|
-// c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
|
483
|
|
-// return
|
484
|
|
-// }
|
485
|
|
-//
|
486
|
|
-// result := int(ret)
|
487
|
|
-// fmt.Println("SSCard的运算结果为1:", result)
|
488
|
|
-// initFlag = 1
|
489
|
|
-// return
|
490
|
|
-//}
|
|
469
|
+var initFlag int64 = 0
|
|
470
|
+
|
|
471
|
+func (c *JSybController) ReadCard() {
|
|
472
|
+ fixmedins_code := c.GetString("fixmedins_code")
|
|
473
|
+ secret_key := c.GetString("secret_key")
|
|
474
|
+ ak := c.GetString("ak")
|
|
475
|
+
|
|
476
|
+ if initFlag == 0 {
|
|
477
|
+ c.TestGetBasBaseInit(fixmedins_code, secret_key, ak)
|
|
478
|
+ }
|
|
479
|
+ basStr := c.GetBasBaseInfo()
|
|
480
|
+ fmt.Println(basStr)
|
|
481
|
+
|
|
482
|
+}
|
|
483
|
+
|
|
484
|
+func (c *JSybController) TestGetBasBaseInit(code string, secret_key string, ak string) {
|
|
485
|
+ DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
|
|
486
|
+ Iinit := DllDef.MustFindProc("Init")
|
|
487
|
+ //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
|
|
488
|
+ str := make([]byte, 1024)
|
|
489
|
+
|
|
490
|
+ inputData := make(map[string]interface{})
|
|
491
|
+
|
|
492
|
+ inputData["IP"] = "10.72.3.87"
|
|
493
|
+ inputData["PORT"] = "8086"
|
|
494
|
+ inputData["TIMEOUT"] = "180"
|
|
495
|
+ inputData["LOG_PATH"] = "C:\\log\\"
|
|
496
|
+ inputData["EC_URL"] = "http://10.72.42.210:10081/localcfc/api/hsecfc/localQrCodeQuery"
|
|
497
|
+ inputData["CARD_PASSTYPE"] = "1"
|
|
498
|
+ inputData["API_NAME"] = "hssServives"
|
|
499
|
+ inputData["API_VERSION"] = "1.0.0"
|
|
500
|
+ inputData["ACCESS_KEY"] = ak
|
|
501
|
+ inputData["SECRETKEY"] = secret_key
|
|
502
|
+ inputData["ORG_ID"] = code
|
|
503
|
+ inputData["EXT"] = ""
|
|
504
|
+ bytesData, _ := json.Marshal(inputData)
|
|
505
|
+ ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
|
|
506
|
+ if ret != 0 {
|
|
507
|
+ fmt.Println("SSCard的报错原因:", err)
|
|
508
|
+ fmt.Println("SSCard的运算结果为:", ret)
|
|
509
|
+ fmt.Println("SSCard的返回结果为:", string(str))
|
|
510
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
|
|
511
|
+ return
|
|
512
|
+ }
|
|
513
|
+
|
|
514
|
+ result := int(ret)
|
|
515
|
+ fmt.Println("SSCard的运算结果为1:", result)
|
|
516
|
+ initFlag = 1
|
|
517
|
+ return
|
|
518
|
+}
|
|
519
|
+func (c *JSybController) GetBasBaseInfo() string {
|
|
520
|
+ DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
|
|
521
|
+ readCard := DllDef.MustFindProc("ReadCardBas")
|
|
522
|
+ if readCard == nil {
|
|
523
|
+ fmt.Println("readcard is nil")
|
|
524
|
+ readCard = DllDef.MustFindProc("ReadCardBas")
|
|
525
|
+ }
|
|
526
|
+ str := make([]byte, 2048)
|
|
527
|
+ str1 := make([]byte, 8192)
|
|
528
|
+ ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
|
|
529
|
+ fmt.Println(string(str1))
|
|
530
|
+ fmt.Println(string(str))
|
|
531
|
+ fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
|
|
532
|
+ fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
|
|
533
|
+ if ret2 != 0 {
|
|
534
|
+ return ""
|
|
535
|
+ }
|
|
536
|
+ return string(str)
|
|
537
|
+}
|
|
538
|
+
|
|
539
|
+func IntPtr(n int) uintptr {
|
|
540
|
+ return uintptr(n)
|
|
541
|
+}
|
|
542
|
+
|
|
543
|
+func StrPtr(s string) uintptr {
|
|
544
|
+ return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
|
|
545
|
+}
|
|
546
|
+
|
|
547
|
+type Charset string
|
|
548
|
+
|
|
549
|
+const (
|
|
550
|
+ UTF8 = Charset("UTF-8")
|
|
551
|
+ GB18030 = Charset("GB18030")
|
|
552
|
+)
|
|
553
|
+
|
|
554
|
+func ConvertToString(src string, srcCode string, tagCode string) string {
|
|
555
|
+ srcCoder := mahonia.NewDecoder(srcCode)
|
|
556
|
+ srcResult := srcCoder.ConvertString(src)
|
|
557
|
+ tagCoder := mahonia.NewDecoder(tagCode)
|
|
558
|
+ _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
|
|
559
|
+ result := string(cdata)
|
|
560
|
+ return result
|
|
561
|
+}
|