|
@@ -9,6 +9,7 @@ import (
|
9
|
9
|
"gdyb/service"
|
10
|
10
|
"gdyb/utils"
|
11
|
11
|
"github.com/astaxie/beego"
|
|
12
|
+ "github.com/axgle/mahonia"
|
12
|
13
|
"math"
|
13
|
14
|
"math/rand"
|
14
|
15
|
"strconv"
|
|
@@ -1711,16 +1712,13 @@ func ReadCardGetCode(request string) (string, string) {
|
1711
|
1712
|
str3 := make([]byte, 256)
|
1712
|
1713
|
ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
|
1713
|
1714
|
fmt.Println(":", string(str3))
|
1714
|
|
-
|
1715
|
|
- fmt.Println(":", ConvertByte2String(str3, GB18030))
|
1716
|
|
-
|
|
1715
|
+ fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
|
1717
|
1716
|
if ret4 == 0 {
|
1718
|
1717
|
result := string(str3)
|
1719
|
1718
|
fmt.Println(result)
|
1720
|
1719
|
result_arr := strings.Split(result, "|")
|
1721
|
1720
|
verifyCode := result_arr[0] + "|" + result_arr[1]
|
1722
|
1721
|
versionCode := result_arr[2]
|
1723
|
|
-
|
1724
|
1722
|
return verifyCode, versionCode
|
1725
|
1723
|
|
1726
|
1724
|
}
|
|
@@ -2723,18 +2721,11 @@ const (
|
2723
|
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
|
}
|