|
@@ -3,6 +3,7 @@ package proxy
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
"database/sql"
|
|
"database/sql"
|
|
|
|
+ "encoding/json"
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
@@ -11,7 +12,6 @@ import (
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
log "app.yhyue.com/moapp/jylog"
|
|
log "app.yhyue.com/moapp/jylog"
|
|
- "github.com/gogf/gf/v2/encoding/gjson"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/net/gtrace"
|
|
"github.com/gogf/gf/v2/net/gtrace"
|
|
@@ -99,19 +99,26 @@ var proxyHandler = func(r *ghttp.Request) {
|
|
result := ""
|
|
result := ""
|
|
if contentType := resp.Header.Get("content-type"); contentType == "application/json" {
|
|
if contentType := resp.Header.Get("content-type"); contentType == "application/json" {
|
|
b, e := ioutil.ReadAll(resp.Body)
|
|
b, e := ioutil.ReadAll(resp.Body)
|
|
- if e == nil {
|
|
|
|
- resp.Body = ioutil.NopCloser(bytes.NewReader(b))
|
|
|
|
- }
|
|
|
|
- jn, err := gjson.DecodeToJson(b)
|
|
|
|
- if err != nil {
|
|
|
|
- log.WithContext(r.Context()).Error("ChangeError", err)
|
|
|
|
- } else if !jn.Contains("error_code") {
|
|
|
|
- log.WithContext(r.Context()).Error("ChangeError:缺少error_code", string(b))
|
|
|
|
- } else if jn.Get("error_code").Int64() == 0 {
|
|
|
|
- isCharging = true
|
|
|
|
- result = string(b)
|
|
|
|
|
|
+ jn := make(map[string]interface{})
|
|
|
|
+ if e != nil {
|
|
|
|
+ log.WithContext(r.Context()).Error("ChangeError", e)
|
|
} else {
|
|
} else {
|
|
- status = 1
|
|
|
|
|
|
+ if err := json.Unmarshal(b, &jn); err != nil {
|
|
|
|
+ log.WithContext(r.Context()).Error("ChangeError", err)
|
|
|
|
+ } else if _, ok := jn["error_code"]; !ok {
|
|
|
|
+ log.WithContext(r.Context()).Error("ChangeError:缺少error_code", string(b))
|
|
|
|
+ } else if gconv.Int64(jn["error_code"]) == gconv.Int64(GLOBAL_SUCCESS) {
|
|
|
|
+ if error_msg, _ := jn["error_msg"].(string); error_msg == "" {
|
|
|
|
+ jn["error_msg"] = "请求成功"
|
|
|
|
+ b, _ = json.Marshal(jn)
|
|
|
|
+ resp.Header.Set("content-length", fmt.Sprint(len(b)))
|
|
|
|
+ }
|
|
|
|
+ result = string(b)
|
|
|
|
+ isCharging = true
|
|
|
|
+ } else {
|
|
|
|
+ status = 1
|
|
|
|
+ }
|
|
|
|
+ resp.Body = ioutil.NopCloser(bytes.NewReader(b))
|
|
}
|
|
}
|
|
} else if strings.Contains(resp.Header.Get("Content-Disposition"), "attachment") && resp.ContentLength > 0 { //下载文件
|
|
} else if strings.Contains(resp.Header.Get("Content-Disposition"), "attachment") && resp.ContentLength > 0 { //下载文件
|
|
isCharging = true
|
|
isCharging = true
|