csx 3 years ago
parent
commit
664c29c48e
1 changed files with 19 additions and 12 deletions
  1. 19 12
      controllers/his_api_controller.go

+ 19 - 12
controllers/his_api_controller.go View File

@@ -30,11 +30,10 @@ type HisApiController struct {
30 30
 }
31 31
 
32 32
 var (
33
-	DllTestDef, _ = syscall.LoadLibrary("SSCard.dll")
34
-
35
-	add, _           = syscall.GetProcAddress(DllTestDef, "Init")
36
-	ReadCardBas, _   = syscall.GetProcAddress(DllTestDef, "ReadCardBas")
37
-	ReadIDCardBas, _ = syscall.GetProcAddress(DllTestDef, "ReadSFZ")
33
+	DllTestDef, _    = syscall.LoadDLL("SSCard.dll")
34
+	add, _           = DllTestDef.FindProc("Init")
35
+	ReadCardBas, _   = DllTestDef.FindProc("ReadCardBas")
36
+	ReadIDCardBas, _ = DllTestDef.FindProc("ReadSFZ")
38 37
 )
39 38
 
40 39
 func HisManagerApiRegistRouters() {
@@ -158,9 +157,8 @@ func (c *HisApiController) Sscard() {
158 157
 	if r == 0 {
159 158
 		switch id_card_type {
160 159
 		case 1:
160
+			fmt.Println(ReadCardBas)
161 161
 			basStr, err := GetBasBaseInfo()
162
-			defer syscall.FreeLibrary(DllTestDef)
163
-
164 162
 			if err != nil {
165 163
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
166 164
 				return
@@ -346,14 +344,19 @@ func (c *HisApiController) Sscard() {
346 344
 	}
347 345
 }
348 346
 func GetBasBaseInfo() (jsonStr string, err error) {
349
-	//handle := syscall.MustLoadDLL("SSCard.dll")
350 347
 	str := make([]byte, 256)
351 348
 	str1 := make([]byte, 256)
352
-	r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
353
-
349
+	user32, _ := syscall.LoadLibrary("SSCard.dll")
350
+	messageBox, _ := syscall.GetProcAddress(user32, "ReadCardBas")
351
+	defer syscall.FreeLibrary(user32)
352
+	r, _, _ := syscall.Syscall9(messageBox,
353
+		4,
354
+		0,
355
+		(uintptr)(unsafe.Pointer(&str[0])),
356
+		(uintptr)(unsafe.Pointer(&str1[0])),
357
+		0x00000003,
358
+		0, 0, 0, 0)
354 359
 	fmt.Println(r)
355
-	fmt.Println(string(str))
356
-
357 360
 	return string(str), nil
358 361
 }
359 362
 
@@ -2696,3 +2699,7 @@ func RemoveRepeatedCode(arr []string) (newArr []string) {
2696 2699
 	}
2697 2700
 	return
2698 2701
 }
2702
+
2703
+func StrPtr2(s string) uintptr {
2704
+	return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
2705
+}