diff --git a/apps/api/internal/handler/JRZQ/jrzqcee8handler.go b/apps/api/internal/handler/JRZQ/jrzqcee8handler.go deleted file mode 100644 index a6f8a56..0000000 --- a/apps/api/internal/handler/JRZQ/jrzqcee8handler.go +++ /dev/null @@ -1,31 +0,0 @@ -package JRZQ - -import ( - "net/http" - "tianyuan-api/pkg/response" - - "github.com/zeromicro/go-zero/rest/httpx" - "tianyuan-api/apps/api/internal/logic/JRZQ" - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - xhttp "github.com/zeromicro/x/http" -) - -func JRZQCEE8Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) - return - } - - l := JRZQ.NewJRZQCEE8Logic(r.Context(), svcCtx) - resp, err := l.JRZQCEE8(&req) - if err != nil { - response.Fail(r.Context(), w, err) - } else { - response.Success(r.Context(), w, resp) - } - } -} diff --git a/apps/api/internal/handler/JRZQ/jrzqfef8handler.go b/apps/api/internal/handler/JRZQ/jrzqfef8handler.go deleted file mode 100644 index 9175def..0000000 --- a/apps/api/internal/handler/JRZQ/jrzqfef8handler.go +++ /dev/null @@ -1,31 +0,0 @@ -package JRZQ - -import ( - "net/http" - "tianyuan-api/pkg/response" - - "github.com/zeromicro/go-zero/rest/httpx" - "tianyuan-api/apps/api/internal/logic/JRZQ" - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - xhttp "github.com/zeromicro/x/http" -) - -func JRZQFEF8Handler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) - return - } - - l := JRZQ.NewJRZQFEF8Logic(r.Context(), svcCtx) - resp, err := l.JRZQFEF8(&req) - if err != nil { - response.Fail(r.Context(), w, err) - } else { - response.Success(r.Context(), w, resp) - } - } -} diff --git a/apps/api/internal/handler/QYGL/qygl51bchandler.go b/apps/api/internal/handler/QYGL/qygl51bchandler.go deleted file mode 100644 index c0c46b2..0000000 --- a/apps/api/internal/handler/QYGL/qygl51bchandler.go +++ /dev/null @@ -1,31 +0,0 @@ -package QYGL - -import ( - "net/http" - "tianyuan-api/pkg/response" - - "github.com/zeromicro/go-zero/rest/httpx" - "tianyuan-api/apps/api/internal/logic/QYGL" - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - xhttp "github.com/zeromicro/x/http" -) - -func QYGL51BCHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - xhttp.JsonBaseResponseCtx(r.Context(), w, err) - return - } - - l := QYGL.NewQYGL51BCLogic(r.Context(), svcCtx) - resp, err := l.QYGL51BC(&req) - if err != nil { - response.Fail(r.Context(), w, err) - } else { - 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 b407a91..d152a2d 100644 --- a/apps/api/internal/logic/FLXG/flxg162alogic.go +++ b/apps/api/internal/logic/FLXG/flxg162alogic.go @@ -31,6 +31,9 @@ func NewFLXG162ALogic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG162A } func (l *FLXG162ALogic) FLXG162A(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -39,6 +42,27 @@ func (l *FLXG162ALogic) FLXG162A(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxg3d56logic.go b/apps/api/internal/logic/FLXG/flxg3d56logic.go index 3900a9e..51f216e 100644 --- a/apps/api/internal/logic/FLXG/flxg3d56logic.go +++ b/apps/api/internal/logic/FLXG/flxg3d56logic.go @@ -2,7 +2,12 @@ package FLXG import ( "context" - "fmt" + "encoding/hex" + "encoding/json" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -48,7 +53,6 @@ func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err } defer func() { - fmt.Println(secretKey) if err != nil { status = "failed" charges = false @@ -61,58 +65,55 @@ func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err logx.Errorf("发送 API 请求消息失败: %v", err) } }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } + + // 2、校验 + var data validator.FLXG3D56Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG3D56FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G26BJ05", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + var respData westmodel.G26BJ05Response + unmarshalErr := json.Unmarshal(westResp, &respData) + if unmarshalErr != nil { + 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 { + return nil, errs.ErrSystem + } + return &types.Response{ - Data: "asdasdasdasd", + Data: encryptData, }, nil - //// 1、解密 - //key, decodeErr := hex.DecodeString(secretKey) - //if decodeErr != nil { - // return nil, errs.ErrSystem - //} - //decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) - //if aesDecryptErr != nil || len(decryptData) == 0 { - // return nil, errs.ErrParamDecryption - //} - // - //// 2、校验 - //var data validator.FLXG3D56Request - //if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { - // return nil, errs.ErrParamValidation - //} - // - //// 3、西部加密 - //westConfig := l.svcCtx.Config.WestConfig - //encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) - //if encryptStructFieldsErr != nil { - // logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) - // return nil, errs.ErrSystem - //} - // - //// 4、发送请求到西部 - //logx.Infof("交易号:%s", transactionID) - //apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG3D56FieldMapping, "data") - // - //westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G26BJ05", apiRequest) - //if callAPIErr != nil { - // return nil, errs.ErrSystem - //} - // - //// 5、响应解析 - //var respData westmodel.G26BJ05Response - //unmarshalErr := json.Unmarshal(westResp, &respData) - //if unmarshalErr != nil { - // 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 { - // return nil, errs.ErrSystem - //} - // - //return &types.Response{ - // Data: encryptData, - //}, nil } diff --git a/apps/api/internal/logic/FLXG/flxg54f5logic.go b/apps/api/internal/logic/FLXG/flxg54f5logic.go index b0722c9..e80f630 100644 --- a/apps/api/internal/logic/FLXG/flxg54f5logic.go +++ b/apps/api/internal/logic/FLXG/flxg54f5logic.go @@ -31,6 +31,9 @@ func NewFLXG54F5Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG54F5 } func (l *FLXG54F5Logic) FLXG54F5(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -39,6 +42,27 @@ func (l *FLXG54F5Logic) FLXG54F5(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxg5876logic.go b/apps/api/internal/logic/FLXG/flxg5876logic.go index a36a482..9281c4e 100644 --- a/apps/api/internal/logic/FLXG/flxg5876logic.go +++ b/apps/api/internal/logic/FLXG/flxg5876logic.go @@ -30,6 +30,9 @@ func NewFLXG5876Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG5876 } func (l *FLXG5876Logic) FLXG5876(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXG5876Logic) FLXG5876(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxg9687logic.go b/apps/api/internal/logic/FLXG/flxg9687logic.go index 9e029be..dcd069e 100644 --- a/apps/api/internal/logic/FLXG/flxg9687logic.go +++ b/apps/api/internal/logic/FLXG/flxg9687logic.go @@ -30,6 +30,9 @@ func NewFLXG9687Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG9687 } func (l *FLXG9687Logic) FLXG9687(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXG9687Logic) FLXG9687(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxg970flogic.go b/apps/api/internal/logic/FLXG/flxg970flogic.go index 491c68f..990410f 100644 --- a/apps/api/internal/logic/FLXG/flxg970flogic.go +++ b/apps/api/internal/logic/FLXG/flxg970flogic.go @@ -30,6 +30,9 @@ func NewFLXG970FLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG970F } func (l *FLXG970FLogic) FLXG970F(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXG970FLogic) FLXG970F(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxgc9d1logic.go b/apps/api/internal/logic/FLXG/flxgc9d1logic.go index 15569a7..ecca7ed 100644 --- a/apps/api/internal/logic/FLXG/flxgc9d1logic.go +++ b/apps/api/internal/logic/FLXG/flxgc9d1logic.go @@ -30,6 +30,9 @@ func NewFLXGC9D1Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXGC9D1 } func (l *FLXGC9D1Logic) FLXGC9D1(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXGC9D1Logic) FLXGC9D1(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { @@ -66,7 +90,7 @@ func (l *FLXGC9D1Logic) FLXGC9D1(req *types.Request) (resp *types.Response, err logx.Infof("交易号:%s", transactionID) apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGC9D1FieldMapping, "data") - westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G31BJ05", apiRequest) + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G30BJ05", apiRequest) if callAPIErr != nil { return nil, errs.ErrSystem } diff --git a/apps/api/internal/logic/FLXG/flxgca3dlogic.go b/apps/api/internal/logic/FLXG/flxgca3dlogic.go index efc5098..2407200 100644 --- a/apps/api/internal/logic/FLXG/flxgca3dlogic.go +++ b/apps/api/internal/logic/FLXG/flxgca3dlogic.go @@ -30,6 +30,9 @@ func NewFLXGCA3DLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXGCA3D } func (l *FLXGCA3DLogic) FLXGCA3D(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXGCA3DLogic) FLXGCA3D(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/FLXG/flxgdec7logic.go b/apps/api/internal/logic/FLXG/flxgdec7logic.go index 7e8d211..e8bdb4f 100644 --- a/apps/api/internal/logic/FLXG/flxgdec7logic.go +++ b/apps/api/internal/logic/FLXG/flxgdec7logic.go @@ -30,6 +30,9 @@ func NewFLXGDEC7Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXGDEC7 } func (l *FLXGDEC7Logic) FLXGDEC7(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem @@ -38,6 +41,27 @@ func (l *FLXGDEC7Logic) FLXGDEC7(req *types.Request) (resp *types.Response, err if !ok { return &types.Response{}, errs.ErrSystem } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { diff --git a/apps/api/internal/logic/IVYZ/ivyz0b03logic.go b/apps/api/internal/logic/IVYZ/ivyz0b03logic.go index e38b3d7..e603c60 100644 --- a/apps/api/internal/logic/IVYZ/ivyz0b03logic.go +++ b/apps/api/internal/logic/IVYZ/ivyz0b03logic.go @@ -25,7 +25,89 @@ func NewIVYZ0B03Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ0B03 } func (l *IVYZ0B03Logic) IVYZ0B03(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - return + //var status string + //var charges bool + //var remark = "" + //secretKey, ok := l.ctx.Value("secretKey").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //transactionID, ok := l.ctx.Value("transactionID").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //userId, userIdOk := l.ctx.Value("userId").(int64) + //if !userIdOk { + // return &types.Response{}, errs.ErrSystem + //} + //productCode, productCodeOk := l.ctx.Value("productCode").(string) + //if !productCodeOk || productCode == "" { + // return &types.Response{}, errs.ErrSystem + //} + //defer func() { + // if err != nil { + // status = "failed" + // charges = false + // } else { + // status = "success" + // charges = true + // } + // sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + // if sendApiRequestMessageErr != nil { + // logx.Errorf("发送 API 请求消息失败: %v", err) + // } + //}() + //// 1、解密 + //key, decodeErr := hex.DecodeString(secretKey) + //if decodeErr != nil { + // return nil, errs.ErrSystem + //} + //decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + //if aesDecryptErr != nil || len(decryptData) == 0 { + // return nil, errs.ErrParamDecryption + //} + // + //// 2、校验 + //var data validator.FLXGDEC7Request + //if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + // return nil, errs.ErrParamValidation + //} + // + //// 3、西部加密 + //westConfig := l.svcCtx.Config.WestConfig + //encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + //if encryptStructFieldsErr != nil { + // logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + // return nil, errs.ErrSystem + //} + // + //// 4、发送请求到西部 + //logx.Infof("交易号:%s", transactionID) + //apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGDEC7FieldMapping, "data") + // + //westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G23BJ03", apiRequest) + //if callAPIErr != nil { + // return nil, errs.ErrSystem + //} + // + //// 5、响应解析 + ////var respData westmodel.G32BJ05Response + ////unmarshalErr := json.Unmarshal(westResp, &respData) + ////if unmarshalErr != nil { + //// 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 + ////} + ////encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + ////if aesEncrypt != nil { + //// return nil, errs.ErrSystem + ////} + //return &types.Response{ + // Data: string(westResp), + //}, nil } diff --git a/apps/api/internal/logic/IVYZ/ivyz2125logic.go b/apps/api/internal/logic/IVYZ/ivyz2125logic.go index 39b8780..5ef7991 100644 --- a/apps/api/internal/logic/IVYZ/ivyz2125logic.go +++ b/apps/api/internal/logic/IVYZ/ivyz2125logic.go @@ -24,8 +24,91 @@ func NewIVYZ2125Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ2125 } } +// IVYZ2125 活体+人像核验组件 func (l *IVYZ2125Logic) IVYZ2125(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - return + //var status string + //var charges bool + //var remark = "" + //secretKey, ok := l.ctx.Value("secretKey").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //transactionID, ok := l.ctx.Value("transactionID").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //userId, userIdOk := l.ctx.Value("userId").(int64) + //if !userIdOk { + // return &types.Response{}, errs.ErrSystem + //} + //productCode, productCodeOk := l.ctx.Value("productCode").(string) + //if !productCodeOk || productCode == "" { + // return &types.Response{}, errs.ErrSystem + //} + //defer func() { + // if err != nil { + // status = "failed" + // charges = false + // } else { + // status = "success" + // charges = true + // } + // sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + // if sendApiRequestMessageErr != nil { + // logx.Errorf("发送 API 请求消息失败: %v", err) + // } + //}() + //// 1、解密 + //key, decodeErr := hex.DecodeString(secretKey) + //if decodeErr != nil { + // return nil, errs.ErrSystem + //} + //decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + //if aesDecryptErr != nil || len(decryptData) == 0 { + // return nil, errs.ErrParamDecryption + //} + // + //// 2、校验 + //var data validator.FLXGDEC7Request + //if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + // return nil, errs.ErrParamValidation + //} + // + //// 3、西部加密 + //westConfig := l.svcCtx.Config.WestConfig + //encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + //if encryptStructFieldsErr != nil { + // logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + // return nil, errs.ErrSystem + //} + // + //// 4、发送请求到西部 + //logx.Infof("交易号:%s", transactionID) + //apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGDEC7FieldMapping, "data") + // + //westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G23BJ03", apiRequest) + //if callAPIErr != nil { + // return nil, errs.ErrSystem + //} + // + //// 5、响应解析 + ////var respData westmodel.G32BJ05Response + ////unmarshalErr := json.Unmarshal(westResp, &respData) + ////if unmarshalErr != nil { + //// 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 + ////} + ////encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + ////if aesEncrypt != nil { + //// return nil, errs.ErrSystem + ////} + //return &types.Response{ + // Data: string(westResp), + //}, nil } diff --git a/apps/api/internal/logic/IVYZ/ivyz385elogic.go b/apps/api/internal/logic/IVYZ/ivyz385elogic.go index 998a533..00c5b3b 100644 --- a/apps/api/internal/logic/IVYZ/ivyz385elogic.go +++ b/apps/api/internal/logic/IVYZ/ivyz385elogic.go @@ -2,6 +2,11 @@ package IVYZ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewIVYZ385ELogic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ385E } func (l *IVYZ385ELogic) IVYZ385E(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.IVYZ385ERequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.IVYZ385EFieldMapping, "") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00020", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/IVYZ/ivyz5733logic.go b/apps/api/internal/logic/IVYZ/ivyz5733logic.go index 42d3578..3dac631 100644 --- a/apps/api/internal/logic/IVYZ/ivyz5733logic.go +++ b/apps/api/internal/logic/IVYZ/ivyz5733logic.go @@ -30,16 +30,38 @@ func NewIVYZ5733Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ5733 } func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" secretKey, ok := l.ctx.Value("secretKey").(string) if !ok { return &types.Response{}, errs.ErrSystem } - transactionID, ok := l.ctx.Value("transactionID").(string) if !ok { return &types.Response{}, errs.ErrSystem } - + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() // 1、解密 key, decodeErr := hex.DecodeString(secretKey) if decodeErr != nil { @@ -60,16 +82,19 @@ func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err westConfig := l.svcCtx.Config.WestConfig encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) if encryptStructFieldsErr != nil { - logx.Errorf("西部加密错误:%v", err) + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) return nil, errs.ErrSystem } + // 4、发送请求到西部 logx.Infof("交易号:%s", transactionID) apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.IVYZ5733FieldMapping, "data") + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G09GX01", apiRequest) if callAPIErr != nil { return nil, errs.ErrSystem } + // 5、响应解析 var respData westmodel.G09GX01Response unmarshalErr := json.Unmarshal(westResp, &respData) diff --git a/apps/api/internal/logic/IVYZ/ivyz9363logic.go b/apps/api/internal/logic/IVYZ/ivyz9363logic.go index bbd6012..680870b 100644 --- a/apps/api/internal/logic/IVYZ/ivyz9363logic.go +++ b/apps/api/internal/logic/IVYZ/ivyz9363logic.go @@ -2,6 +2,11 @@ package IVYZ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewIVYZ9363Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ9363 } func (l *IVYZ9363Logic) IVYZ9363(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.IVYZ9363Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.IVYZ9363FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G10GX01", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/IVYZ/ivyzadeelogic.go b/apps/api/internal/logic/IVYZ/ivyzadeelogic.go index f5a7b3a..5bd4ef6 100644 --- a/apps/api/internal/logic/IVYZ/ivyzadeelogic.go +++ b/apps/api/internal/logic/IVYZ/ivyzadeelogic.go @@ -25,7 +25,89 @@ func NewIVYZADEELogic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZADEE } func (l *IVYZADEELogic) IVYZADEE(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - return + //var status string + //var charges bool + //var remark = "" + //secretKey, ok := l.ctx.Value("secretKey").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //transactionID, ok := l.ctx.Value("transactionID").(string) + //if !ok { + // return &types.Response{}, errs.ErrSystem + //} + //userId, userIdOk := l.ctx.Value("userId").(int64) + //if !userIdOk { + // return &types.Response{}, errs.ErrSystem + //} + //productCode, productCodeOk := l.ctx.Value("productCode").(string) + //if !productCodeOk || productCode == "" { + // return &types.Response{}, errs.ErrSystem + //} + //defer func() { + // if err != nil { + // status = "failed" + // charges = false + // } else { + // status = "success" + // charges = true + // } + // sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + // if sendApiRequestMessageErr != nil { + // logx.Errorf("发送 API 请求消息失败: %v", err) + // } + //}() + //// 1、解密 + //key, decodeErr := hex.DecodeString(secretKey) + //if decodeErr != nil { + // return nil, errs.ErrSystem + //} + //decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + //if aesDecryptErr != nil || len(decryptData) == 0 { + // return nil, errs.ErrParamDecryption + //} + // + //// 2、校验 + //var data validator.FLXGDEC7Request + //if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + // return nil, errs.ErrParamValidation + //} + // + //// 3、西部加密 + //westConfig := l.svcCtx.Config.WestConfig + //encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + //if encryptStructFieldsErr != nil { + // logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + // return nil, errs.ErrSystem + //} + // + //// 4、发送请求到西部 + //logx.Infof("交易号:%s", transactionID) + //apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGDEC7FieldMapping, "data") + // + //westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("idCardThreeElements", apiRequest) + //if callAPIErr != nil { + // return nil, errs.ErrSystem + //} + // + //// 5、响应解析 + ////var respData westmodel.G32BJ05Response + ////unmarshalErr := json.Unmarshal(westResp, &respData) + ////if unmarshalErr != nil { + //// 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 + ////} + ////encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + ////if aesEncrypt != nil { + //// return nil, errs.ErrSystem + ////} + //return &types.Response{ + // Data: string(westResp), + //}, nil } diff --git a/apps/api/internal/logic/JRZQ/jrzq0a03logic.go b/apps/api/internal/logic/JRZQ/jrzq0a03logic.go index 9d9bcbe..1a3f8f3 100644 --- a/apps/api/internal/logic/JRZQ/jrzq0a03logic.go +++ b/apps/api/internal/logic/JRZQ/jrzq0a03logic.go @@ -2,6 +2,11 @@ package JRZQ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewJRZQ0A03Logic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQ0A03 } func (l *JRZQ0A03Logic) JRZQ0A03(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.JRZQ0A03Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.JRZQ0A03FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G27BJ05", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/JRZQ/jrzq4aa8logic.go b/apps/api/internal/logic/JRZQ/jrzq4aa8logic.go index ce03dce..42c4f55 100644 --- a/apps/api/internal/logic/JRZQ/jrzq4aa8logic.go +++ b/apps/api/internal/logic/JRZQ/jrzq4aa8logic.go @@ -2,6 +2,11 @@ package JRZQ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewJRZQ4AA8Logic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQ4AA8 } func (l *JRZQ4AA8Logic) JRZQ4AA8(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.JRZQ4AA8Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.JRZQ4AA8FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G29BJ05", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/JRZQ/jrzq8203logic.go b/apps/api/internal/logic/JRZQ/jrzq8203logic.go index 42b3a1f..cd19e2b 100644 --- a/apps/api/internal/logic/JRZQ/jrzq8203logic.go +++ b/apps/api/internal/logic/JRZQ/jrzq8203logic.go @@ -2,6 +2,11 @@ package JRZQ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewJRZQ8203Logic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQ8203 } func (l *JRZQ8203Logic) JRZQ8203(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.JRZQ8203Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.JRZQ8203FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G28BJ05", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/JRZQ/jrzqcee8logic.go b/apps/api/internal/logic/JRZQ/jrzqcee8logic.go deleted file mode 100644 index 12a6c9f..0000000 --- a/apps/api/internal/logic/JRZQ/jrzqcee8logic.go +++ /dev/null @@ -1,31 +0,0 @@ -package JRZQ - -import ( - "context" - "tianyuan-api/pkg/errs" - - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type JRZQCEE8Logic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewJRZQCEE8Logic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQCEE8Logic { - return &JRZQCEE8Logic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *JRZQCEE8Logic) JRZQCEE8(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - - return -} diff --git a/apps/api/internal/logic/JRZQ/jrzqdcbelogic.go b/apps/api/internal/logic/JRZQ/jrzqdcbelogic.go index 5d829ca..be7aeea 100644 --- a/apps/api/internal/logic/JRZQ/jrzqdcbelogic.go +++ b/apps/api/internal/logic/JRZQ/jrzqdcbelogic.go @@ -2,6 +2,11 @@ package JRZQ import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewJRZQDCBELogic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQDCBE } func (l *JRZQDCBELogic) JRZQDCBE(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.JRZQDBCERequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.JRZQDBCEFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G20GZ01", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/JRZQ/jrzqfef8logic.go b/apps/api/internal/logic/JRZQ/jrzqfef8logic.go deleted file mode 100644 index ade4d2b..0000000 --- a/apps/api/internal/logic/JRZQ/jrzqfef8logic.go +++ /dev/null @@ -1,31 +0,0 @@ -package JRZQ - -import ( - "context" - "tianyuan-api/pkg/errs" - - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type JRZQFEF8Logic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewJRZQFEF8Logic(ctx context.Context, svcCtx *svc.ServiceContext) *JRZQFEF8Logic { - return &JRZQFEF8Logic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *JRZQFEF8Logic) JRZQFEF8(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - - return -} diff --git a/apps/api/internal/logic/QYGL/qygl2acdlogic.go b/apps/api/internal/logic/QYGL/qygl2acdlogic.go index 8ed2847..899df19 100644 --- a/apps/api/internal/logic/QYGL/qygl2acdlogic.go +++ b/apps/api/internal/logic/QYGL/qygl2acdlogic.go @@ -2,6 +2,11 @@ package QYGL import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewQYGL2ACDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGL2ACD } func (l *QYGL2ACDLogic) QYGL2ACD(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } + + // 2、校验 + var data validator.QYGL2ACDRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL2ACDFieldMapping, "") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00022", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} return &types.Response{ - Data: "三要素合演", + Data: string(westResp), }, nil } diff --git a/apps/api/internal/logic/QYGL/qygl45bdlogic.go b/apps/api/internal/logic/QYGL/qygl45bdlogic.go index e229cdf..079e36c 100644 --- a/apps/api/internal/logic/QYGL/qygl45bdlogic.go +++ b/apps/api/internal/logic/QYGL/qygl45bdlogic.go @@ -2,6 +2,11 @@ package QYGL import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewQYGL45BDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGL45BD } func (l *QYGL45BDLogic) QYGL45BD(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.QYGL45BDRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL45BDFieldMapping, "") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00021", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/QYGL/qygl51bclogic.go b/apps/api/internal/logic/QYGL/qygl51bclogic.go deleted file mode 100644 index 6a79b3d..0000000 --- a/apps/api/internal/logic/QYGL/qygl51bclogic.go +++ /dev/null @@ -1,31 +0,0 @@ -package QYGL - -import ( - "context" - "tianyuan-api/pkg/errs" - - "tianyuan-api/apps/api/internal/svc" - "tianyuan-api/apps/api/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type QYGL51BCLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewQYGL51BCLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGL51BCLogic { - return &QYGL51BCLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *QYGL51BCLogic) QYGL51BC(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line - - return -} diff --git a/apps/api/internal/logic/QYGL/qygl6f2dlogic.go b/apps/api/internal/logic/QYGL/qygl6f2dlogic.go index 27c9164..4eef038 100644 --- a/apps/api/internal/logic/QYGL/qygl6f2dlogic.go +++ b/apps/api/internal/logic/QYGL/qygl6f2dlogic.go @@ -2,6 +2,11 @@ package QYGL import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewQYGL6F2DLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGL6F2D } func (l *QYGL6F2DLogic) QYGL6F2D(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.QYGL6F2DRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL6F2DFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G05XM02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/QYGL/qygl8261logic.go b/apps/api/internal/logic/QYGL/qygl8261logic.go index 09d59f4..cc32fa7 100644 --- a/apps/api/internal/logic/QYGL/qygl8261logic.go +++ b/apps/api/internal/logic/QYGL/qygl8261logic.go @@ -2,6 +2,11 @@ package QYGL import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewQYGL8261Logic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGL8261 } func (l *QYGL8261Logic) QYGL8261(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.QYGL8261Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGL8261FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("Q03BJ03", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/QYGL/qyglb4c0logic.go b/apps/api/internal/logic/QYGL/qyglb4c0logic.go index d6f4b99..4baada6 100644 --- a/apps/api/internal/logic/QYGL/qyglb4c0logic.go +++ b/apps/api/internal/logic/QYGL/qyglb4c0logic.go @@ -2,6 +2,11 @@ package QYGL import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewQYGLB4C0Logic(ctx context.Context, svcCtx *svc.ServiceContext) *QYGLB4C0 } func (l *QYGLB4C0Logic) QYGLB4C0(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.QYGLB4C0Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.QYGLB4C0FieldMapping, "") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G05HZ01", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysy09cdlogic.go b/apps/api/internal/logic/YYSY/yysy09cdlogic.go index ad590cc..a6ce0f1 100644 --- a/apps/api/internal/logic/YYSY/yysy09cdlogic.go +++ b/apps/api/internal/logic/YYSY/yysy09cdlogic.go @@ -2,6 +2,11 @@ package YYSY import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -24,8 +29,90 @@ func NewYYSY09CDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSY09CD } } +// YYSY09CD 三要素简版 func (l *YYSY09CDLogic) YYSY09CD(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.YYSY09CDRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSY09CDFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G16BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysy4b37logic.go b/apps/api/internal/logic/YYSY/yysy4b37logic.go index 7a95509..189ceb5 100644 --- a/apps/api/internal/logic/YYSY/yysy4b37logic.go +++ b/apps/api/internal/logic/YYSY/yysy4b37logic.go @@ -2,6 +2,11 @@ package YYSY import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewYYSY4B37Logic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSY4B37 } func (l *YYSY4B37Logic) YYSY4B37(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.YYSY4B37Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSY4B37FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G02BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysy6f2elogic.go b/apps/api/internal/logic/YYSY/yysy6f2elogic.go index 05e898f..aa0efce 100644 --- a/apps/api/internal/logic/YYSY/yysy6f2elogic.go +++ b/apps/api/internal/logic/YYSY/yysy6f2elogic.go @@ -2,6 +2,11 @@ package YYSY import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -24,8 +29,90 @@ func NewYYSY6F2ELogic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSY6F2E } } +// YYSY6F2E 三要素详版 func (l *YYSY6F2ELogic) YYSY6F2E(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.YYSY6F2ERequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSY6F2EFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G15BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysybe08logic.go b/apps/api/internal/logic/YYSY/yysybe08logic.go index fd67dfa..e18aeca 100644 --- a/apps/api/internal/logic/YYSY/yysybe08logic.go +++ b/apps/api/internal/logic/YYSY/yysybe08logic.go @@ -2,6 +2,11 @@ package YYSY import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewYYSYBE08Logic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSYBE08 } func (l *YYSYBE08Logic) YYSYBE08(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.YYSYBE08Request + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSYBE08FieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G17BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysyd50flogic.go b/apps/api/internal/logic/YYSY/yysyd50flogic.go index 08c6dd7..8d7dbbe 100644 --- a/apps/api/internal/logic/YYSY/yysyd50flogic.go +++ b/apps/api/internal/logic/YYSY/yysyd50flogic.go @@ -2,6 +2,11 @@ package YYSY import ( "context" + "encoding/hex" + "tianyuan-api/apps/api/internal/common" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" "tianyuan-api/apps/api/internal/svc" @@ -25,7 +30,88 @@ func NewYYSYD50FLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSYD50F } func (l *YYSYD50FLogic) YYSYD50F(req *types.Request) (resp *types.Response, err *errs.AppError) { - // todo: add your logic here and delete this line + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return + // 2、校验 + var data validator.YYSYD50FRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSYD50FFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G18BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/logic/YYSY/yysyf7dblogic.go b/apps/api/internal/logic/YYSY/yysyf7dblogic.go index 47be70a..1c087e2 100644 --- a/apps/api/internal/logic/YYSY/yysyf7dblogic.go +++ b/apps/api/internal/logic/YYSY/yysyf7dblogic.go @@ -2,9 +2,14 @@ package YYSY import ( "context" + "encoding/hex" "github.com/zeromicro/go-zero/core/logx" + "tianyuan-api/apps/api/internal/common" "tianyuan-api/apps/api/internal/svc" "tianyuan-api/apps/api/internal/types" + "tianyuan-api/apps/api/internal/validator" + "tianyuan-api/apps/api/internal/westmodel" + "tianyuan-api/pkg/crypto" "tianyuan-api/pkg/errs" ) @@ -22,7 +27,89 @@ func NewYYSYF7DBLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YYSYF7DB } } -func (l *YYSYF7DBLogic) YYSYF7DB(req *types.Request) (*types.Response, *errs.AppError) { +func (l *YYSYF7DBLogic) YYSYF7DB(req *types.Request) (resp *types.Response, err *errs.AppError) { + var status string + var charges bool + var remark = "" + secretKey, ok := l.ctx.Value("secretKey").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + transactionID, ok := l.ctx.Value("transactionID").(string) + if !ok { + return &types.Response{}, errs.ErrSystem + } + userId, userIdOk := l.ctx.Value("userId").(int64) + if !userIdOk { + return &types.Response{}, errs.ErrSystem + } + productCode, productCodeOk := l.ctx.Value("productCode").(string) + if !productCodeOk || productCode == "" { + return &types.Response{}, errs.ErrSystem + } + defer func() { + if err != nil { + status = "failed" + charges = false + } else { + status = "success" + charges = true + } + sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) + if sendApiRequestMessageErr != nil { + logx.Errorf("发送 API 请求消息失败: %v", err) + } + }() + // 1、解密 + key, decodeErr := hex.DecodeString(secretKey) + if decodeErr != nil { + return nil, errs.ErrSystem + } + decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) + if aesDecryptErr != nil || len(decryptData) == 0 { + return nil, errs.ErrParamDecryption + } - return &types.Response{}, nil + // 2、校验 + var data validator.YYSYF7DBRequest + if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { + return nil, errs.ErrParamValidation + } + + // 3、西部加密 + westConfig := l.svcCtx.Config.WestConfig + encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) + if encryptStructFieldsErr != nil { + logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) + return nil, errs.ErrSystem + } + + // 4、发送请求到西部 + logx.Infof("交易号:%s", transactionID) + apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSYF7DBFieldMapping, "data") + + westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G19BJ02", apiRequest) + if callAPIErr != nil { + return nil, errs.ErrSystem + } + + // 5、响应解析 + //var respData westmodel.G32BJ05Response + //unmarshalErr := json.Unmarshal(westResp, &respData) + //if unmarshalErr != nil { + // 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 + //} + //encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) + //if aesEncrypt != nil { + // return nil, errs.ErrSystem + //} + return &types.Response{ + Data: string(westResp), + }, nil } diff --git a/apps/api/internal/validator/structs.go b/apps/api/internal/validator/structs.go index e3b3392..2b85d5f 100644 --- a/apps/api/internal/validator/structs.go +++ b/apps/api/internal/validator/structs.go @@ -54,7 +54,90 @@ type FLXGDEC7Request struct { IDCard string `json:"id_card" validate:"required,validIDCard"` Name string `json:"name" validate:"required,min=1,validName"` } + +type IVYZ0B03Request struct { +} +type IVYZ385ERequest struct { + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} type IVYZ5733Request struct { Name string `json:"name" validate:"required,min=1,validName"` IDCard string `json:"id_card" validate:"required,validIDCard"` } +type IVYZ9363Request struct { + ManName string `json:"man_name" validate:"required,min=1,validName"` + ManIDCard string `json:"man_id_card" validate:"required,validIDCard"` + WomanName string `json:"woman_name" validate:"required,min=1,validName"` + WomanIDCard string `json:"woman_id_card" validate:"required,validIDCard"` +} + +type JRZQ0A03Request struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type JRZQ4AA8Request struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type JRZQ8203Request struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type JRZQDBCERequest struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + BankCard string `json:"bank_card" validate:"required,validBankCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type QYGL2ACDRequest struct { + EntName string `json:"ent_name" validate:"required,min=1,validName"` + LegalPerson string `json:"legal_person" validate:"required,min=1,validName"` + EntCode string `json:"ent_code" validate:"required,validUSCI"` +} +type QYGL6F2DRequest struct { + IDCard string `json:"id_card" validate:"required,validIDCard"` +} +type QYGL45BDRequest struct { + EntName string `json:"ent_name" validate:"required,min=1,validName"` + LegalPerson string `json:"legal_person" validate:"required,min=1,validName"` + EntCode string `json:"ent_code" validate:"required,validUSCI"` + IDCard string `json:"id_card" validate:"required,validIDCard"` +} +type QYGL8261Request struct { + EntName string `json:"ent_name" validate:"required,min=1,validName"` +} +type QYGLB4C0Request struct { + IDCard string `json:"id_card" validate:"required,validIDCard"` +} + +type YYSY4B37Request struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` +} +type YYSY6F2ERequest struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + MobileType string `json:"mobile_type" validate:"omitempty,validMobileType"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type YYSY09CDRequest struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + MobileType string `json:"mobile_type" validate:"omitempty,validMobileType"` + IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type YYSYBE08Request struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + Name string `json:"name" validate:"required,min=1,validName"` +} +type YYSYD50FRequest struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + IDCard string `json:"id_card" validate:"required,validIDCard"` +} +type YYSYF7DBRequest struct { + MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` + StartDate string `json:"start_date" validate:"required,validDate"` +} diff --git a/apps/api/internal/validator/validator.go b/apps/api/internal/validator/validator.go index 8fb24be..142e61c 100644 --- a/apps/api/internal/validator/validator.go +++ b/apps/api/internal/validator/validator.go @@ -38,6 +38,18 @@ func init() { if err := validate.RegisterValidation("validTimeRange", validTimeRange); err != nil { panic(fmt.Sprintf("注册 validTimeRange 验证器时发生错误: %v", err)) } + + if err := validate.RegisterValidation("validBankCard", validBankCard); err != nil { + panic(fmt.Sprintf("注册 validBankCard 验证器时发生错误: %v", err)) + } + + if err := validate.RegisterValidation("validUSCI", validUSCI); err != nil { + panic(fmt.Sprintf("注册 validUSCI 验证器时发生错误: %v", err)) + } + + if err := validate.RegisterValidation("validMobileType", validMobileType); err != nil { + panic(fmt.Sprintf("注册 validMobileType 验证器时发生错误: %v", err)) + } } // ValidateAndParse 封装了解密、解析和校验逻辑 @@ -110,3 +122,35 @@ func validTimeRange(fl validator.FieldLevel) bool { } return true } +func validBankCard(fl validator.FieldLevel) bool { + bankCard := fl.Field().String() + // 银行卡号一般是13到19位的数字 + validBankCardPattern := `^\d{13,19}$` + matched, _ := regexp.MatchString(validBankCardPattern, bankCard) + return matched +} + +func validUSCI(fl validator.FieldLevel) bool { + usci := fl.Field().String() + // 社会信用代码为18位数字和大写字母的组合,最后一位为校验码 + validUSCIPattern := `^[1-9A-Z]{2}[0-9]{6}[0-9A-Z]{9}[0-9A-Z]$` + matched, _ := regexp.MatchString(validUSCIPattern, usci) + return matched +} + +// 自定义的手机号类型验证(可以为空) +func validMobileType(fl validator.FieldLevel) bool { + mobileType := fl.Field().String() + if mobileType == "" { + return true // 如果为空,认为是有效的 + } + + // 校验是否是 CTCC, CMCC, CUCC 之一 + validTypes := map[string]bool{ + "CTCC": true, // 中国电信 + "CMCC": true, // 中国移动 + "CUCC": true, // 中国联通 + } + + return validTypes[mobileType] +} diff --git a/apps/api/internal/westmodel/fieldMapping.go b/apps/api/internal/westmodel/fieldMapping.go index 294a97c..f8265c8 100644 --- a/apps/api/internal/westmodel/fieldMapping.go +++ b/apps/api/internal/westmodel/fieldMapping.go @@ -1,9 +1,5 @@ package westmodel -var IVYZ5733FieldMapping = map[string]string{ - "IDCard": "id", - "Name": "name", -} var FLXG3D56FieldMapping = map[string]string{ "IDCard": "id", "Name": "name", @@ -13,6 +9,10 @@ var FLXG3D56FieldMapping = map[string]string{ var FLXG54F5FieldMapping = map[string]string{ "MobileNo": "mobile", } +var FLXG5876FieldMapping = map[string]string{ + "MobileNo": "phone", +} + var FLXG162AFieldMapping = map[string]string{ "IDCard": "id", "Name": "name", @@ -20,7 +20,7 @@ var FLXG162AFieldMapping = map[string]string{ } var FLXG970FFieldMapping = map[string]string{ - "IDCard": "id", + "IDCard": "cardNo", "Name": "name", } var FLXG9687FieldMapping = map[string]string{ @@ -34,13 +34,94 @@ var FLXGC9D1FieldMapping = map[string]string{ "MobileNo": "cell", } var FLXGCA3DFieldMapping = map[string]string{ - "IDCard": "id", + "IDCard": "id_card", "Name": "name", } var FLXGDEC7FieldMapping = map[string]string{ + "IDCard": "id_card", + "Name": "name", +} +var IVYZ385EFieldMapping = map[string]string{ + "IDCard": "gmsfzhm", + "Name": "xm", +} + +var IVYZ5733FieldMapping = map[string]string{ "IDCard": "id", "Name": "name", } -var FLXG5876FieldMapping = map[string]string{ - "MobileNo": "mobile", +var IVYZ9363FieldMapping = map[string]string{ + "ManName": "nameMan", + "ManIDCard": "certNumMan", + "WomanName": "nameWoman", + "WomanIDCard": "certNumWoman", +} +var JRZQ0A03FieldMapping = map[string]string{ + "IDCard": "id", + "Name": "name", + "MobileNo": "cell", +} +var JRZQ4AA8FieldMapping = map[string]string{ + "IDCard": "id", + "Name": "name", + "MobileNo": "cell", +} +var JRZQ8203FieldMapping = map[string]string{ + "IDCard": "id", + "Name": "name", + "MobileNo": "cell", +} +var JRZQDBCEFieldMapping = map[string]string{ + "IDCard": "idcard", + "Name": "name", + "MobileNo": "mobile", + "BankCard": "acc_no", +} + +var QYGL2ACDFieldMapping = map[string]string{ + "EntName": "entname", + "LegalPerson": "realname", + "EntCode": "idcard", +} +var QYGL6F2DFieldMapping = map[string]string{ + "IDCard": "idno", +} +var QYGL45BDFieldMapping = map[string]string{ + "EntName": "entname", + "LegalPerson": "realname", + "EntCode": "entmark", + "IDCard": "idcard", +} +var QYGL8261FieldMapping = map[string]string{ + "EntName": "ent_name", +} +var QYGLB4C0FieldMapping = map[string]string{ + "IDCard": "pid", +} +var YYSY4B37FieldMapping = map[string]string{ + "MobileNo": "phone", +} +var YYSY6F2EFieldMapping = map[string]string{ + "IDCard": "idNo", + "Name": "name", + "MobileNo": "phone", + "MobileType": "phoneType", +} +var YYSY09CDFieldMapping = map[string]string{ + "IDCard": "idNo", + "Name": "name", + "MobileNo": "phone", + "MobileType": "phoneType", +} +var YYSYBE08FieldMapping = map[string]string{ + "Name": "name", + "MobileNo": "phone", +} +var YYSYD50FFieldMapping = map[string]string{ + "MobileNo": "phone", + "IDCard": "idNo", +} +var YYSYF7DBFieldMapping = map[string]string{ + "MobileNo": "phone", + "StartDate": "startDate", }