Browse Source

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

csx 4 years ago
parent
commit
87bc562afa
1 changed files with 9 additions and 18 deletions
  1. 9 18
      controllers/sz/sz_his_api_controller.go

+ 9 - 18
controllers/sz/sz_his_api_controller.go View File

9
 	"gdyb/service"
9
 	"gdyb/service"
10
 	"gdyb/utils"
10
 	"gdyb/utils"
11
 	"github.com/astaxie/beego"
11
 	"github.com/astaxie/beego"
12
+	"github.com/axgle/mahonia"
12
 	"math"
13
 	"math"
13
 	"math/rand"
14
 	"math/rand"
14
 	"strconv"
15
 	"strconv"
1711
 	str3 := make([]byte, 256)
1712
 	str3 := make([]byte, 256)
1712
 	ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
1713
 	ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
1713
 	fmt.Println(":", string(str3))
1714
 	fmt.Println(":", string(str3))
1714
-
1715
-	fmt.Println(":", ConvertByte2String(str3, GB18030))
1716
-
1715
+	fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
1717
 	if ret4 == 0 {
1716
 	if ret4 == 0 {
1718
 		result := string(str3)
1717
 		result := string(str3)
1719
 		fmt.Println(result)
1718
 		fmt.Println(result)
1720
 		result_arr := strings.Split(result, "|")
1719
 		result_arr := strings.Split(result, "|")
1721
 		verifyCode := result_arr[0] + "|" + result_arr[1]
1720
 		verifyCode := result_arr[0] + "|" + result_arr[1]
1722
 		versionCode := result_arr[2]
1721
 		versionCode := result_arr[2]
1723
-
1724
 		return verifyCode, versionCode
1722
 		return verifyCode, versionCode
1725
 
1723
 
1726
 	}
1724
 	}
2723
 	GB18030 = Charset("GB18030")
2721
 	GB18030 = Charset("GB18030")
2724
 )
2722
 )
2725
 
2723
 
2726
-func ConvertByte2String(byte []byte, charset Charset) string {
2727
-
2728
-	var str string
2729
-	switch charset {
2730
-	case GB18030:
2731
-		decodeBytes, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
2732
-		str = string(decodeBytes)
2733
-	case UTF8:
2734
-		fallthrough
2735
-	default:
2736
-		str = string(byte)
2737
-	}
2738
-
2739
-	return str
2724
+func ConvertToString(src string, srcCode string, tagCode string) string {
2725
+	srcCoder := mahonia.NewDecoder(srcCode)
2726
+	srcResult := srcCoder.ConvertString(src)
2727
+	tagCoder := mahonia.NewDecoder(tagCode)
2728
+	_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
2729
+	result := string(cdata)
2730
+	return result
2740
 }
2731
 }