Browse Source

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

csx 2 years ago
parent
commit
03ae5e3a03
1 changed files with 19 additions and 3 deletions
  1. 19 3
      service/fj_service.go

+ 19 - 3
service/fj_service.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"gdyb/models"
6 6
 	"github.com/astaxie/beego"
7 7
 	"github.com/axgle/mahonia"
8
+	"golang.org/x/text/encoding/simplifiedchinese"
8 9
 	"io/ioutil"
9 10
 	"net/http"
10 11
 	"strconv"
@@ -2451,10 +2452,9 @@ func GetFjBusinessHandleInfo(inputStr []byte) (string, string) {
2451 2452
 	outputStr := make([]byte, 4096)
2452 2453
 	errMessageStr := make([]byte, 2048)
2453 2454
 	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&inputStr[0])), uintptr(20000), (uintptr)(unsafe.Pointer(&outputStr[0])), (uintptr)(unsafe.Pointer(&errMessageStr[0])))
2454
-	enc := mahonia.NewEncoder("gbk")
2455 2455
 
2456
-	fmt.Println("错误信息1:", enc.ConvertString(string(errMessageStr)))
2457
-	fmt.Println("输出信息1:", enc.ConvertString(string(outputStr)))
2456
+	fmt.Println("错误信息1:", ConvertByte2String(errMessageStr, GB18030))
2457
+	fmt.Println("输出信息1:", ConvertByte2String(outputStr, GB18030))
2458 2458
 
2459 2459
 	if ret2 != 0 {
2460 2460
 		return "", ""
@@ -2488,3 +2488,19 @@ func Remove0000(s string) string {
2488 2488
 	}
2489 2489
 	return string(str)
2490 2490
 }
2491
+
2492
+func ConvertByte2String(byte []byte, charset Charset) string {
2493
+
2494
+	var str string
2495
+	switch charset {
2496
+	case GB18030:
2497
+		decodeBytes, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
2498
+		str = string(decodeBytes)
2499
+	case UTF8:
2500
+		fallthrough
2501
+	default:
2502
+		str = string(byte)
2503
+	}
2504
+
2505
+	return str
2506
+}