增加IVYZ9a2b
This commit is contained in:
parent
004fd5782c
commit
190bd0cb0f
60
aes.go
60
aes.go
@ -92,41 +92,45 @@ func AesDecrypt(cipherTextBase64 string, key []byte) ([]byte, error) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 定义 AES 密钥
|
// 定义 AES 密钥
|
||||||
key, _ := hex.DecodeString("ff83609b2b24fc73196aac3d3dfb874f")
|
key, _ := hex.DecodeString("6e9631cbd32c1a50b9375fec1a48ff8c")
|
||||||
|
|
||||||
var data interface{}
|
var data interface{}
|
||||||
|
|
||||||
//decrypt, err := AesDecrypt("ELKXVN8ZOhxUUsLWbHVIhbvTT94rU+u69vuE9JonsQYSAcNFKn4xQXoyRKd7mJCRIQ/4rlSj5A1KqHlR7jLIcyHaCCdvbEF1pGVw4oRpw6i8sFPWSjvnUuOUgKsaniJ6lb1SYBpZRlBSzG36NiAufdEeH0gcHDu9x9IGzkmdXk8=", key)
|
decrypt, err := AesDecrypt("ZfE25g2MvNHvg4hUHbYjVisSnQ+n3zam7DIO1Po7pEP118xVuUqVqGT3JMc6CowNJmvTtXGjG8lhDH8LTp1D7tSTGVmw7AuUjQO4Olcwvsg=", key)
|
||||||
//if err != nil {
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
//err = json.Unmarshal(decrypt, &data)
|
|
||||||
//if err != nil {
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
//fmt.Println(data)
|
|
||||||
|
|
||||||
data = map[string]interface{}{
|
|
||||||
"id_card": "45212220000827423X",
|
|
||||||
"name": "张荣宏",
|
|
||||||
"time_range": "5",
|
|
||||||
"mobile_no": "18276151590",
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将结构体转为 JSON 字符串
|
|
||||||
jsonData, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("JSON 序列化错误:", err)
|
fmt.Println("解密错误:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(decrypt, &data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("JSON解析错误:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对 JSON 数据进行加密
|
// 打印解密后的数据
|
||||||
encryptedData, err := AesEncrypt(jsonData, key)
|
fmt.Println("解密后的数据:", decrypt)
|
||||||
if err != nil {
|
|
||||||
fmt.Println("加密错误:", err)
|
// data = map[string]interface{}{
|
||||||
return
|
// "id_card": "45212220000827423X",
|
||||||
}
|
// "name": "张荣宏",
|
||||||
|
// "time_range": "5",
|
||||||
|
// "mobile_no": "18276151590",
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 将结构体转为 JSON 字符串
|
||||||
|
// jsonData, err := json.Marshal(data)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println("JSON 序列化错误:", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 对 JSON 数据进行加密
|
||||||
|
// encryptedData, err := AesEncrypt(jsonData, key)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println("加密错误:", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
// 输出加密后的结果
|
// 输出加密后的结果
|
||||||
fmt.Println("加密后的数据:", encryptedData)
|
// fmt.Println("加密后的数据:", encryptedData)
|
||||||
}
|
}
|
||||||
|
12
api.json
12
api.json
@ -244,7 +244,15 @@
|
|||||||
"sourceId": "G32-BJ05",
|
"sourceId": "G32-BJ05",
|
||||||
"serviceName": "团伙欺诈排查(通用版)",
|
"serviceName": "团伙欺诈排查(通用版)",
|
||||||
"dataDescription": "团伙欺诈排查(通用版)",
|
"dataDescription": "团伙欺诈排查(通用版)",
|
||||||
"group_cn": "法律相关ddd",
|
"group_cn": "法律相关",
|
||||||
"group": "FLXG"
|
"group": "FLXG"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"serviceId": "IVYZ9A2B",
|
||||||
|
"sourceId": "G11BJ06",
|
||||||
|
"serviceName": "学历信息查询",
|
||||||
|
"dataDescription": "查询个人学历信息",
|
||||||
|
"group_cn": "身份验证",
|
||||||
|
"group": "IVYZ"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -34,6 +34,9 @@ service api-api {
|
|||||||
|
|
||||||
@handler IVYZADEE
|
@handler IVYZADEE
|
||||||
post /IVYZADEE (request) returns (string)
|
post /IVYZADEE (request) returns (string)
|
||||||
|
|
||||||
|
@handler IVYZ9A2B
|
||||||
|
post /IVYZ9A2B (request) returns (string)
|
||||||
}
|
}
|
||||||
|
|
||||||
@server (
|
@server (
|
||||||
|
28
apps/api/internal/handler/IVYZ/ivyz9a2bhandler.go
Normal file
28
apps/api/internal/handler/IVYZ/ivyz9a2bhandler.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package IVYZ
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"tianyuan-api/apps/api/internal/logic/IVYZ"
|
||||||
|
"tianyuan-api/apps/api/internal/svc"
|
||||||
|
"tianyuan-api/apps/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IVYZ9A2BHandler(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 {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := IVYZ.NewIVYZ9A2BLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.IVYZ9A2B(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -115,6 +115,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/IVYZ9363",
|
Path: "/IVYZ9363",
|
||||||
Handler: IVYZ.IVYZ9363Handler(serverCtx),
|
Handler: IVYZ.IVYZ9363Handler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/IVYZ9A2B",
|
||||||
|
Handler: IVYZ.IVYZ9A2BHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/IVYZADEE",
|
Path: "/IVYZADEE",
|
||||||
|
110
apps/api/internal/logic/IVYZ/ivyz9a2blogic.go
Normal file
110
apps/api/internal/logic/IVYZ/ivyz9a2blogic.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package IVYZ
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IVYZ9A2BLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIVYZ9A2BLogic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ9A2BLogic {
|
||||||
|
return &IVYZ9A2BLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *IVYZ9A2BLogic) IVYZ9A2B(req *types.Request) (resp string, err error) {
|
||||||
|
var status string
|
||||||
|
var charges bool
|
||||||
|
var remark = ""
|
||||||
|
secretKey, ok := l.ctx.Value("secretKey").(string)
|
||||||
|
if !ok {
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
transactionID, ok := l.ctx.Value("transactionID").(string)
|
||||||
|
if !ok {
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
userId, userIdOk := l.ctx.Value("userId").(int64)
|
||||||
|
if !userIdOk {
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
productCode, productCodeOk := l.ctx.Value("productCode").(string)
|
||||||
|
if !productCodeOk || productCode == "" {
|
||||||
|
return "", 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 "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
|
||||||
|
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||||
|
return "", errs.ErrParamDecryption
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2、校验
|
||||||
|
var data validator.IVYZ9A2BRequest
|
||||||
|
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||||
|
return "", errs.ErrParamValidation
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3、西部加密
|
||||||
|
westConfig := l.svcCtx.Config.WestConfig
|
||||||
|
encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
|
||||||
|
if encryptStructFieldsErr != nil {
|
||||||
|
logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4、发送请求到西部
|
||||||
|
logx.Infof("交易号:%s", transactionID)
|
||||||
|
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.IVYZ9A2BFieldMapping, "data")
|
||||||
|
|
||||||
|
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G11BJ06", apiRequest, l.svcCtx.Config.WestConfig.SecretId)
|
||||||
|
if callAPIErr != nil {
|
||||||
|
if callAPIErr.Code == errs.ErrDataSource.Code {
|
||||||
|
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||||
|
if aesEncrypt != nil {
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
return encryptData, callAPIErr
|
||||||
|
}
|
||||||
|
return "", callAPIErr
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||||
|
if aesEncrypt != nil {
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
return encryptData, nil
|
||||||
|
}
|
@ -158,3 +158,7 @@ type YYSYF7DBRequest struct {
|
|||||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
StartDate string `json:"start_date" validate:"required,validDate" encrypt:"false"`
|
StartDate string `json:"start_date" validate:"required,validDate" encrypt:"false"`
|
||||||
}
|
}
|
||||||
|
type IVYZ9A2BRequest struct {
|
||||||
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
|
Name string `json:"name" validate:"required,min=1,validName"`
|
||||||
|
}
|
||||||
|
@ -142,3 +142,7 @@ var YYSYF7DBFieldMapping = map[string]string{
|
|||||||
"MobileNo": "phone",
|
"MobileNo": "phone",
|
||||||
"StartDate": "startDate",
|
"StartDate": "startDate",
|
||||||
}
|
}
|
||||||
|
var IVYZ9A2BFieldMapping = map[string]string{
|
||||||
|
"IDCard": "id_card_value",
|
||||||
|
"Name": "name_value",
|
||||||
|
}
|
||||||
|
4
go.mod
4
go.mod
@ -11,6 +11,8 @@ require (
|
|||||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||||
github.com/qiniu/go-sdk/v7 v7.22.0
|
github.com/qiniu/go-sdk/v7 v7.22.0
|
||||||
github.com/smartwalle/alipay/v3 v3.2.23
|
github.com/smartwalle/alipay/v3 v3.2.23
|
||||||
|
github.com/stretchr/testify v1.9.0
|
||||||
|
github.com/tidwall/gjson v1.18.0
|
||||||
github.com/zeromicro/go-queue v1.2.2
|
github.com/zeromicro/go-queue v1.2.2
|
||||||
github.com/zeromicro/go-zero v1.7.2
|
github.com/zeromicro/go-zero v1.7.2
|
||||||
github.com/zeromicro/x v0.0.0-20240408115609-8224c482b07e
|
github.com/zeromicro/x v0.0.0-20240408115609-8224c482b07e
|
||||||
@ -72,6 +74,7 @@ require (
|
|||||||
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.20.2 // indirect
|
github.com/prometheus/client_golang v1.20.2 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.55.0 // indirect
|
github.com/prometheus/common v0.55.0 // indirect
|
||||||
@ -82,7 +85,6 @@ require (
|
|||||||
github.com/smartwalle/ngx v1.0.9 // indirect
|
github.com/smartwalle/ngx v1.0.9 // indirect
|
||||||
github.com/smartwalle/nsign v1.0.9 // indirect
|
github.com/smartwalle/nsign v1.0.9 // indirect
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/tidwall/gjson v1.18.0 // indirect
|
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/tidwall/pretty v1.2.0 // indirect
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
github.com/tjfoc/gmsm v1.3.2 // indirect
|
github.com/tjfoc/gmsm v1.3.2 // indirect
|
||||||
|
Loading…
Reference in New Issue
Block a user