Browse Source

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

csx 3 years ago
parent
commit
967f00de95
1 changed files with 19 additions and 4 deletions
  1. 19 4
      controllers/sg/his_api_controller.go

+ 19 - 4
controllers/sg/his_api_controller.go View File

11
 	"gdyb/service"
11
 	"gdyb/service"
12
 	"gdyb/utils"
12
 	"gdyb/utils"
13
 	"github.com/astaxie/beego"
13
 	"github.com/astaxie/beego"
14
+	"github.com/axgle/mahonia"
14
 	"github.com/jinzhu/gorm"
15
 	"github.com/jinzhu/gorm"
15
 	"github.com/shopspring/decimal"
16
 	"github.com/shopspring/decimal"
16
 	"io"
17
 	"io"
444
 		fmt.Println("readcard is nil")
445
 		fmt.Println("readcard is nil")
445
 		readCard = DllDef.MustFindProc("ReadCardBas")
446
 		readCard = DllDef.MustFindProc("ReadCardBas")
446
 	}
447
 	}
447
-
448
 	str := make([]byte, 1024)
448
 	str := make([]byte, 1024)
449
 	str1 := make([]byte, 1024)
449
 	str1 := make([]byte, 1024)
450
 	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
450
 	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
451
-
452
 	fmt.Println(string(str1))
451
 	fmt.Println(string(str1))
453
 	fmt.Println(string(str))
452
 	fmt.Println(string(str))
454
-
453
+	fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
454
+	fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
455
 	if ret2 != 0 {
455
 	if ret2 != 0 {
456
 		return ""
456
 		return ""
457
 	}
457
 	}
458
 	return string(str)
458
 	return string(str)
459
-
460
 }
459
 }
461
 
460
 
462
 func prttostr(vcode uintptr) string {
461
 func prttostr(vcode uintptr) string {
6799
 	}
6798
 	}
6800
 
6799
 
6801
 }
6800
 }
6801
+
6802
+type Charset string
6803
+
6804
+const (
6805
+	UTF8    = Charset("UTF-8")
6806
+	GB18030 = Charset("GB18030")
6807
+)
6808
+
6809
+func ConvertToString(src string, srcCode string, tagCode string) string {
6810
+	srcCoder := mahonia.NewDecoder(srcCode)
6811
+	srcResult := srcCoder.ConvertString(src)
6812
+	tagCoder := mahonia.NewDecoder(tagCode)
6813
+	_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
6814
+	result := string(cdata)
6815
+	return result
6816
+}