diff --git a/aes.go b/aes.go index 08b374f..4f98573 100644 --- a/aes.go +++ b/aes.go @@ -8,6 +8,7 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" + "errors" "fmt" "io" ) @@ -19,6 +20,19 @@ func PKCS7Padding(ciphertext []byte, blockSize int) []byte { return append(ciphertext, padtext...) } +// 去除PKCS7填充 +func PKCS7UnPadding(origData []byte) ([]byte, error) { + length := len(origData) + if length == 0 { + return nil, errors.New("input data error") + } + unpadding := int(origData[length-1]) + if unpadding > length { + return nil, errors.New("unpadding size is invalid") + } + return origData[:(length - unpadding)], nil +} + // AES CBC模式加密,Base64传入传出 func AesEncrypt(plainText, key []byte) (string, error) { block, err := aes.NewCipher(key) @@ -41,9 +55,39 @@ func AesEncrypt(plainText, key []byte) (string, error) { return base64.StdEncoding.EncodeToString(cipherText), nil } -type Data struct { - Name string `json:"name"` - Email string `json:"email"` +// AES CBC模式解密,Base64传入传出 +func AesDecrypt(cipherTextBase64 string, key []byte) ([]byte, error) { + cipherText, err := base64.StdEncoding.DecodeString(cipherTextBase64) + if err != nil { + return nil, err + } + + block, err := aes.NewCipher(key) + if err != nil { + return nil, err + } + + blockSize := block.BlockSize() + if len(cipherText) < blockSize { + return nil, errors.New("ciphertext too short") + } + + iv := cipherText[:blockSize] + cipherText = cipherText[blockSize:] + + if len(cipherText)%blockSize != 0 { + return nil, errors.New("ciphertext is not a multiple of the block size") + } + + mode := cipher.NewCBCDecrypter(block, iv) + mode.CryptBlocks(cipherText, cipherText) + + plainText, err := PKCS7UnPadding(cipherText) + if err != nil { + return nil, err + } + + return plainText, nil } func main() { @@ -52,25 +96,34 @@ func main() { var data interface{} - data = map[string]interface{}{ - "id_card": "45212220000827423X", - "name": "张荣宏", - } - - // 将结构体转为 JSON 字符串 - jsonData, err := json.Marshal(data) + decrypt, err := AesDecrypt("AEQHGRyEolE4o8GoZaWuEFGpGRLEvEMCNM54KzZ/HdnvfOtyFDfn1PVpD6Cb37rQpJm3CqZYLDJWmEcU0f7IeD0MG8Zh1PIvSEwJVEyI2OkZjooZNjuchARpqeG40sS8hFjQt/xVP3qBVsF6+tdnI8GNc8EdLpZ8ja4c/xVprhjr9yRmRHZOVvECFiJkqwrve8jq2vuC5CowNjc4THK8zRmJI+qWDazUL4vntdWFmqG4YmHDZm/UFecevDNMhWRfdeWE2aI9lTXZ/X/gtHEcVyzbx8cltdn+4KuR3t6VPf3edWDSDM0PTxSNbWwPgaTC1sMbBJiFJLW+cUgxJhfQqE1FF5yY+t6V7l8vfW6cUV4xRCFZ/clFvidnYev2CocvMKzf6gkbO/El2a4VA5ustRwL1G3hxMf9fd+5yGT5dEGci+cbysGHTKzNeHf75az1RgW2WEYUBUc7czNiZgkaIA==", key) if err != nil { - fmt.Println("JSON 序列化错误:", err) return } - - // 对 JSON 数据进行加密 - encryptedData, err := AesEncrypt(jsonData, key) + err = json.Unmarshal(decrypt, &data) if err != nil { - fmt.Println("加密错误:", err) return } - - // 输出加密后的结果 - fmt.Println("加密后的数据:", encryptedData) + fmt.Println(data) + //data = map[string]interface{}{ + // "id_card": "45212220000827423X", + // "name": "张荣宏", + //} + // + //// 将结构体转为 JSON 字符串 + //jsonData, err := json.Marshal(data) + //if err != nil { + // fmt.Println("JSON 序列化错误:", err) + // return + //} + // + //// 对 JSON 数据进行加密 + //encryptedData, err := AesEncrypt(jsonData, key) + //if err != nil { + // fmt.Println("加密错误:", err) + // return + //} + // + //// 输出加密后的结果 + //fmt.Println("加密后的数据:", encryptedData) } diff --git a/apps/api/internal/handler/FLXG/flxg162ahandler.go b/apps/api/internal/handler/FLXG/flxg162ahandler.go index 7cf79c9..8c33909 100644 --- a/apps/api/internal/handler/FLXG/flxg162ahandler.go +++ b/apps/api/internal/handler/FLXG/flxg162ahandler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG162AHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG162ALogic(r.Context(), svcCtx) resp, err := l.FLXG162A(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxg54f5handler.go b/apps/api/internal/handler/FLXG/flxg54f5handler.go index 1abbda6..58c179e 100644 --- a/apps/api/internal/handler/FLXG/flxg54f5handler.go +++ b/apps/api/internal/handler/FLXG/flxg54f5handler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG54F5Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG54F5Logic(r.Context(), svcCtx) resp, err := l.FLXG54F5(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxg5876handler.go b/apps/api/internal/handler/FLXG/flxg5876handler.go index 552a766..776b0b1 100644 --- a/apps/api/internal/handler/FLXG/flxg5876handler.go +++ b/apps/api/internal/handler/FLXG/flxg5876handler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG5876Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG5876Logic(r.Context(), svcCtx) resp, err := l.FLXG5876(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxg75fehandler.go b/apps/api/internal/handler/FLXG/flxg75fehandler.go index ed5f47d..c2b51c7 100644 --- a/apps/api/internal/handler/FLXG/flxg75fehandler.go +++ b/apps/api/internal/handler/FLXG/flxg75fehandler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG75FEHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG75FELogic(r.Context(), svcCtx) resp, err := l.FLXG75FE(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxg9687handler.go b/apps/api/internal/handler/FLXG/flxg9687handler.go index c44b101..0cd4839 100644 --- a/apps/api/internal/handler/FLXG/flxg9687handler.go +++ b/apps/api/internal/handler/FLXG/flxg9687handler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG9687Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG9687Logic(r.Context(), svcCtx) resp, err := l.FLXG9687(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxg970fhandler.go b/apps/api/internal/handler/FLXG/flxg970fhandler.go index 95d5c12..6a1de2c 100644 --- a/apps/api/internal/handler/FLXG/flxg970fhandler.go +++ b/apps/api/internal/handler/FLXG/flxg970fhandler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXG970FHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXG970FLogic(r.Context(), svcCtx) resp, err := l.FLXG970F(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxgc9d1handler.go b/apps/api/internal/handler/FLXG/flxgc9d1handler.go index 6092f2f..ae9b5ac 100644 --- a/apps/api/internal/handler/FLXG/flxgc9d1handler.go +++ b/apps/api/internal/handler/FLXG/flxgc9d1handler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXGC9D1Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXGC9D1Logic(r.Context(), svcCtx) resp, err := l.FLXGC9D1(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxgca3dhandler.go b/apps/api/internal/handler/FLXG/flxgca3dhandler.go index 8d8fe9f..f209358 100644 --- a/apps/api/internal/handler/FLXG/flxgca3dhandler.go +++ b/apps/api/internal/handler/FLXG/flxgca3dhandler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXGCA3DHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXGCA3DLogic(r.Context(), svcCtx) resp, err := l.FLXGCA3D(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/FLXG/flxgdec7handler.go b/apps/api/internal/handler/FLXG/flxgdec7handler.go index 1d5b83f..acab7e3 100644 --- a/apps/api/internal/handler/FLXG/flxgdec7handler.go +++ b/apps/api/internal/handler/FLXG/flxgdec7handler.go @@ -2,6 +2,7 @@ package FLXG import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/FLXG" @@ -22,9 +23,9 @@ func FLXGDEC7Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := FLXG.NewFLXGDEC7Logic(r.Context(), svcCtx) resp, err := l.FLXGDEC7(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/IVYZ/ivyz0b03handler.go b/apps/api/internal/handler/IVYZ/ivyz0b03handler.go index 503dbf2..7da3148 100644 --- a/apps/api/internal/handler/IVYZ/ivyz0b03handler.go +++ b/apps/api/internal/handler/IVYZ/ivyz0b03handler.go @@ -2,6 +2,7 @@ package IVYZ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/IVYZ" @@ -22,9 +23,9 @@ func IVYZ0B03Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := IVYZ.NewIVYZ0B03Logic(r.Context(), svcCtx) resp, err := l.IVYZ0B03(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/IVYZ/ivyz2125handler.go b/apps/api/internal/handler/IVYZ/ivyz2125handler.go index f6bc070..2f09eec 100644 --- a/apps/api/internal/handler/IVYZ/ivyz2125handler.go +++ b/apps/api/internal/handler/IVYZ/ivyz2125handler.go @@ -2,6 +2,7 @@ package IVYZ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/IVYZ" @@ -22,9 +23,9 @@ func IVYZ2125Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := IVYZ.NewIVYZ2125Logic(r.Context(), svcCtx) resp, err := l.IVYZ2125(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/IVYZ/ivyz385ehandler.go b/apps/api/internal/handler/IVYZ/ivyz385ehandler.go index 1eeca35..54cd652 100644 --- a/apps/api/internal/handler/IVYZ/ivyz385ehandler.go +++ b/apps/api/internal/handler/IVYZ/ivyz385ehandler.go @@ -2,6 +2,7 @@ package IVYZ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/IVYZ" @@ -22,9 +23,9 @@ func IVYZ385EHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := IVYZ.NewIVYZ385ELogic(r.Context(), svcCtx) resp, err := l.IVYZ385E(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/IVYZ/ivyz9363handler.go b/apps/api/internal/handler/IVYZ/ivyz9363handler.go index 5e8b08b..9d3a53f 100644 --- a/apps/api/internal/handler/IVYZ/ivyz9363handler.go +++ b/apps/api/internal/handler/IVYZ/ivyz9363handler.go @@ -2,6 +2,7 @@ package IVYZ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/IVYZ" @@ -22,9 +23,9 @@ func IVYZ9363Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := IVYZ.NewIVYZ9363Logic(r.Context(), svcCtx) resp, err := l.IVYZ9363(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/IVYZ/ivyzadeehandler.go b/apps/api/internal/handler/IVYZ/ivyzadeehandler.go index e2c507c..d2c4c40 100644 --- a/apps/api/internal/handler/IVYZ/ivyzadeehandler.go +++ b/apps/api/internal/handler/IVYZ/ivyzadeehandler.go @@ -2,6 +2,7 @@ package IVYZ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/IVYZ" @@ -22,9 +23,9 @@ func IVYZADEEHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := IVYZ.NewIVYZADEELogic(r.Context(), svcCtx) resp, err := l.IVYZADEE(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzq0a03handler.go b/apps/api/internal/handler/JRZQ/jrzq0a03handler.go index a7d4891..9927ca1 100644 --- a/apps/api/internal/handler/JRZQ/jrzq0a03handler.go +++ b/apps/api/internal/handler/JRZQ/jrzq0a03handler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQ0A03Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQ0A03Logic(r.Context(), svcCtx) resp, err := l.JRZQ0A03(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzq4aa8handler.go b/apps/api/internal/handler/JRZQ/jrzq4aa8handler.go index f8aaf19..82d5fe0 100644 --- a/apps/api/internal/handler/JRZQ/jrzq4aa8handler.go +++ b/apps/api/internal/handler/JRZQ/jrzq4aa8handler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQ4AA8Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQ4AA8Logic(r.Context(), svcCtx) resp, err := l.JRZQ4AA8(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzq8203handler.go b/apps/api/internal/handler/JRZQ/jrzq8203handler.go index 119b57c..2145a5e 100644 --- a/apps/api/internal/handler/JRZQ/jrzq8203handler.go +++ b/apps/api/internal/handler/JRZQ/jrzq8203handler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQ8203Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQ8203Logic(r.Context(), svcCtx) resp, err := l.JRZQ8203(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzqcee8handler.go b/apps/api/internal/handler/JRZQ/jrzqcee8handler.go index 045317d..a6f8a56 100644 --- a/apps/api/internal/handler/JRZQ/jrzqcee8handler.go +++ b/apps/api/internal/handler/JRZQ/jrzqcee8handler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQCEE8Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQCEE8Logic(r.Context(), svcCtx) resp, err := l.JRZQCEE8(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzqdcbehandler.go b/apps/api/internal/handler/JRZQ/jrzqdcbehandler.go index cafb36a..6624eed 100644 --- a/apps/api/internal/handler/JRZQ/jrzqdcbehandler.go +++ b/apps/api/internal/handler/JRZQ/jrzqdcbehandler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQDCBEHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQDCBELogic(r.Context(), svcCtx) resp, err := l.JRZQDCBE(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/JRZQ/jrzqfef8handler.go b/apps/api/internal/handler/JRZQ/jrzqfef8handler.go index dec78ab..9175def 100644 --- a/apps/api/internal/handler/JRZQ/jrzqfef8handler.go +++ b/apps/api/internal/handler/JRZQ/jrzqfef8handler.go @@ -2,6 +2,7 @@ package JRZQ import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/JRZQ" @@ -22,9 +23,9 @@ func JRZQFEF8Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := JRZQ.NewJRZQFEF8Logic(r.Context(), svcCtx) resp, err := l.JRZQFEF8(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qygl2acdhandler.go b/apps/api/internal/handler/QYGL/qygl2acdhandler.go index 22911fc..25ed713 100644 --- a/apps/api/internal/handler/QYGL/qygl2acdhandler.go +++ b/apps/api/internal/handler/QYGL/qygl2acdhandler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGL2ACDHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGL2ACDLogic(r.Context(), svcCtx) resp, err := l.QYGL2ACD(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qygl45bdhandler.go b/apps/api/internal/handler/QYGL/qygl45bdhandler.go index e091cc2..1308a5e 100644 --- a/apps/api/internal/handler/QYGL/qygl45bdhandler.go +++ b/apps/api/internal/handler/QYGL/qygl45bdhandler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGL45BDHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGL45BDLogic(r.Context(), svcCtx) resp, err := l.QYGL45BD(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qygl51bchandler.go b/apps/api/internal/handler/QYGL/qygl51bchandler.go index d07c2cf..c0c46b2 100644 --- a/apps/api/internal/handler/QYGL/qygl51bchandler.go +++ b/apps/api/internal/handler/QYGL/qygl51bchandler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGL51BCHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGL51BCLogic(r.Context(), svcCtx) resp, err := l.QYGL51BC(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qygl6f2dhandler.go b/apps/api/internal/handler/QYGL/qygl6f2dhandler.go index b69c909..0754a96 100644 --- a/apps/api/internal/handler/QYGL/qygl6f2dhandler.go +++ b/apps/api/internal/handler/QYGL/qygl6f2dhandler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGL6F2DHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGL6F2DLogic(r.Context(), svcCtx) resp, err := l.QYGL6F2D(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qygl8261handler.go b/apps/api/internal/handler/QYGL/qygl8261handler.go index 6372c08..987048a 100644 --- a/apps/api/internal/handler/QYGL/qygl8261handler.go +++ b/apps/api/internal/handler/QYGL/qygl8261handler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGL8261Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGL8261Logic(r.Context(), svcCtx) resp, err := l.QYGL8261(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/QYGL/qyglb4c0handler.go b/apps/api/internal/handler/QYGL/qyglb4c0handler.go index d3e2a77..7325aba 100644 --- a/apps/api/internal/handler/QYGL/qyglb4c0handler.go +++ b/apps/api/internal/handler/QYGL/qyglb4c0handler.go @@ -2,6 +2,7 @@ package QYGL import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/QYGL" @@ -22,9 +23,9 @@ func QYGLB4C0Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := QYGL.NewQYGLB4C0Logic(r.Context(), svcCtx) resp, err := l.QYGLB4C0(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysy09cdhandler.go b/apps/api/internal/handler/YYSY/yysy09cdhandler.go index acb54e4..f929436 100644 --- a/apps/api/internal/handler/YYSY/yysy09cdhandler.go +++ b/apps/api/internal/handler/YYSY/yysy09cdhandler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSY09CDHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSY09CDLogic(r.Context(), svcCtx) resp, err := l.YYSY09CD(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysy4b37handler.go b/apps/api/internal/handler/YYSY/yysy4b37handler.go index 5daa1c5..4f3a071 100644 --- a/apps/api/internal/handler/YYSY/yysy4b37handler.go +++ b/apps/api/internal/handler/YYSY/yysy4b37handler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSY4B37Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSY4B37Logic(r.Context(), svcCtx) resp, err := l.YYSY4B37(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysy6f2ehandler.go b/apps/api/internal/handler/YYSY/yysy6f2ehandler.go index 1743303..719abc2 100644 --- a/apps/api/internal/handler/YYSY/yysy6f2ehandler.go +++ b/apps/api/internal/handler/YYSY/yysy6f2ehandler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSY6F2EHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSY6F2ELogic(r.Context(), svcCtx) resp, err := l.YYSY6F2E(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysybe08handler.go b/apps/api/internal/handler/YYSY/yysybe08handler.go index 3a3e640..1662b06 100644 --- a/apps/api/internal/handler/YYSY/yysybe08handler.go +++ b/apps/api/internal/handler/YYSY/yysybe08handler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSYBE08Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSYBE08Logic(r.Context(), svcCtx) resp, err := l.YYSYBE08(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysyd50fhandler.go b/apps/api/internal/handler/YYSY/yysyd50fhandler.go index 42a631f..86c12bf 100644 --- a/apps/api/internal/handler/YYSY/yysyd50fhandler.go +++ b/apps/api/internal/handler/YYSY/yysyd50fhandler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSYD50FHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSYD50FLogic(r.Context(), svcCtx) resp, err := l.YYSYD50F(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/handler/YYSY/yysyf7dbhandler.go b/apps/api/internal/handler/YYSY/yysyf7dbhandler.go index a042ff1..4682ff1 100644 --- a/apps/api/internal/handler/YYSY/yysyf7dbhandler.go +++ b/apps/api/internal/handler/YYSY/yysyf7dbhandler.go @@ -2,6 +2,7 @@ package YYSY import ( "net/http" + "tianyuan-api/pkg/response" "github.com/zeromicro/go-zero/rest/httpx" "tianyuan-api/apps/api/internal/logic/YYSY" @@ -22,9 +23,9 @@ func YYSYF7DBHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := YYSY.NewYYSYF7DBLogic(r.Context(), svcCtx) resp, err := l.YYSYF7DB(&req) if err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) + response.Fail(r.Context(), w, err) } else { - xhttp.JsonBaseResponseCtx(r.Context(), w, resp) + response.Success(r.Context(), w, resp) } } } diff --git a/apps/api/internal/logic/FLXG/flxg162alogic.go b/apps/api/internal/logic/FLXG/flxg162alogic.go index 706aa2b..b407a91 100644 --- a/apps/api/internal/logic/FLXG/flxg162alogic.go +++ b/apps/api/internal/logic/FLXG/flxg162alogic.go @@ -79,9 +79,7 @@ func (l *FLXG162ALogic) FLXG162A(req *types.Request) (resp *types.Response, err return nil, errs.ErrSystem } - if respData.Data.Code == "00" || respData.Data.Code == "100002" { - l.ctx = context.WithValue(l.ctx, "Charges", true) - } else { + if respData.Data.Code != "00" && respData.Data.Code != "100002" { return nil, errs.ErrSystem } encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) diff --git a/apps/api/internal/logic/FLXG/flxg3d56logic.go b/apps/api/internal/logic/FLXG/flxg3d56logic.go index 01aa461..6c6524d 100644 --- a/apps/api/internal/logic/FLXG/flxg3d56logic.go +++ b/apps/api/internal/logic/FLXG/flxg3d56logic.go @@ -80,10 +80,8 @@ func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err return nil, errs.ErrSystem } - if respData.Data.Code == "00" || respData.Data.Code == "100002" { - l.ctx = context.WithValue(l.ctx, "Charges", true) - } else { - return nil, errs.ErrSystem + if respData.Data.Code != "00" && respData.Data.Code != "100002" { + return nil, errs.ErrDataSource } encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) if aesEncrypt != nil { diff --git a/apps/api/internal/logic/FLXG/flxg54f5logic.go b/apps/api/internal/logic/FLXG/flxg54f5logic.go index 6af0635..b0722c9 100644 --- a/apps/api/internal/logic/FLXG/flxg54f5logic.go +++ b/apps/api/internal/logic/FLXG/flxg54f5logic.go @@ -79,9 +79,7 @@ func (l *FLXG54F5Logic) FLXG54F5(req *types.Request) (resp *types.Response, err return nil, errs.ErrSystem } - if respData.Code == "0000" { - l.ctx = context.WithValue(l.ctx, "Charges", true) - } else { + if respData.Code != "0000" { return nil, errs.ErrSystem } encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) diff --git a/pkg/response/response.go b/pkg/response/response.go index 4ca9abf..03f47c7 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -45,6 +45,8 @@ func sendResponse(ctx context.Context, w http.ResponseWriter, code int, message // 响应成功 func Success(ctx context.Context, w http.ResponseWriter, data interface{}) { ctx = context.WithValue(ctx, "status", "success") + ctx = context.WithValue(ctx, "Charges", true) + sendResponse(ctx, w, 0, "success", data) }