Browse Source

Merge branch 'bugfix__8338' into debug

317699326@qq.com 5 days ago
parent
commit
cb37e849ae
3 changed files with 29 additions and 7 deletions
  1. 6 2
      controllers/chart.go
  2. 11 4
      controllers/eta_forum_chart.go
  3. 12 1
      utils/des3.go

+ 6 - 2
controllers/chart.go

@@ -66,10 +66,14 @@ func (this *ChartController) ChartDetail() {
 		return
 	}
 
-	b = utils.DesBase64Decrypt(b, utils.DesKey)
+	bodyStr := string(b)
+	bodyStr = strings.TrimLeft(bodyStr, `"`)
+	bodyStr = strings.TrimRight(bodyStr, `"`)
+
+	bodyResult := utils.DesBase64Decrypt([]byte(bodyStr), utils.DesKey)
 
 	result := new(models.BaseResponse)
-	if e = json.Unmarshal(b, &result); e != nil {
+	if e = json.Unmarshal(bodyResult, &result); e != nil {
 		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
 		br.ErrMsg = err.Error()
 		return

+ 11 - 4
controllers/eta_forum_chart.go

@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"strings"
 )
 
 // EtaForumChartController 图表详情
@@ -45,6 +46,7 @@ func (this *EtaForumChartController) ChartDetail() {
 	url := utils.ChartLibUrl + `/eta_forum/chart/common/detail?UniqueCode=%s`
 	url = fmt.Sprintf(url, req.UniqueCode)
 
+	fmt.Println("url:" + url)
 	resp, e := http.Get(url)
 	if e != nil {
 		err = fmt.Errorf("http Get err: %s", e.Error())
@@ -64,17 +66,22 @@ func (this *EtaForumChartController) ChartDetail() {
 		br.ErrMsg = err.Error()
 		return
 	}
-	utils.FileLog.Info(string(b))
-	b = utils.DesBase64Decrypt(b, utils.DesKey)
+	bodyStr := string(b)
+	bodyStr = strings.TrimLeft(bodyStr, `"`)
+	bodyStr = strings.TrimRight(bodyStr, `"`)
+
+	bodyResult := utils.DesBase64Decrypt([]byte(bodyStr), utils.DesKey)
 	result := new(models.BaseResponse)
-	if e = json.Unmarshal(b, &result); e != nil {
+	if e = json.Unmarshal(bodyResult, &result); e != nil {
 		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
 		br.ErrMsg = err.Error()
+		br.Msg = result.Msg
 		return
 	}
 	if result.Ret != 200 {
 		err = fmt.Errorf("result: %s", string(b))
-		br.ErrMsg = err.Error()
+		br.ErrMsg = result.ErrMsg + err.Error()
+		br.Msg = result.Msg
 		return
 	}
 

+ 12 - 1
utils/des3.go

@@ -8,6 +8,7 @@ import (
 	"encoding/base64"
 	"encoding/hex"
 	"errors"
+	"fmt"
 	"strings"
 )
 
@@ -21,7 +22,17 @@ func DesBase64Encrypt(origData []byte, desKey string) []byte {
 }
 
 func DesBase64Decrypt(crypted []byte, desKey string) []byte {
-	result, _ := base64.StdEncoding.DecodeString(string(crypted))
+	cryptedStr := string(crypted)
+	if len(cryptedStr)%4 != 0 {
+		cryptedStr += strings.Repeat("=", 4-(len(cryptedStr)%4))
+		crypted = []byte(cryptedStr)
+
+		fmt.Println("cryptedStr:" + cryptedStr)
+	} else {
+		fmt.Println("4 mode")
+	}
+
+	result, err := base64.StdEncoding.DecodeString(string(crypted))
 	remain := len(result) % 8
 	if remain > 0 {
 		mod := 8 - remain