插件调试

This commit is contained in:
李子铭 2025-01-07 11:23:55 +08:00
parent 507e120fc3
commit 2ac9ccba43
1 changed files with 24 additions and 5 deletions

View File

@ -30,8 +30,7 @@ func (c *Card) ToJson() []byte {
}
func (c *Config) validate() error {
err := validator.New().Struct(c)
if err != nil {
if err := validator.New().Struct(c); err != nil {
for _, err = range err.(validator.ValidationErrors) {
return proto.ErrorConfigFail(fmt.Sprintf("配置参数有误:%s", err.Error()))
}
@ -41,26 +40,31 @@ func (c *Config) validate() error {
func transConfig(config []byte) (*Config, error) {
var c Config
err := json.Unmarshal(config, &c)
if err != nil {
if err := json.Unmarshal(config, &c); err != nil {
return nil, proto.ErrorConfigFail(err.Error())
}
if err = c.validate(); err != nil {
if err := c.validate(); err != nil {
return nil, err
}
return &c, nil
}
func (c *Config) client() (*sdk.Client, error) {
scheme := getScheme(c.BaseUri)
domain, err := getDomain(c.BaseUri, scheme)
if err != nil {
return nil, proto.ErrorConfigFail(err.Error())
}
cl, err := sdk.NewClientWithAccessKey(c.AppKey, scheme, domain)
if err != nil {
return nil, proto.ErrorConfigFail(err.Error())
}
return cl, nil
}
@ -103,6 +107,7 @@ func queryResp(appKey string, request *proto.QueryRequest, resp *api.OrderQueryR
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
status := vo.OrderStatus(resp.TradeStatus)
pb := &proto.QueryResponse{
Result: &proto.Result{
@ -114,6 +119,7 @@ func queryResp(appKey string, request *proto.QueryRequest, resp *api.OrderQueryR
Extra: nil,
},
}
if len(resp.Cards) > 0 {
c, err := getQueryCard(appKey, &resp.Cards[0])
if err != nil {
@ -121,6 +127,7 @@ func queryResp(appKey string, request *proto.QueryRequest, resp *api.OrderQueryR
}
pb.Result.Extra = c.ToJson()
}
return pb, nil
}
@ -132,10 +139,12 @@ func getQueryCard(appKey string, card *api.Cards) (*Card, error) {
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
no, err := decryptAES(card.No, appKey)
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
car.Password = pwd
car.Number = no
} else if t.IsPwd() {
@ -143,6 +152,7 @@ func getQueryCard(appKey string, card *api.Cards) (*Card, error) {
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
car.Password = pwd
} else if t.IsUrl() {
// 无
@ -155,6 +165,7 @@ func notifyResp(appKey string, resp *notify.OrderReq) (*proto.NotifyResponse, er
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
status := vo.OrderStatus(resp.TradeStatus)
pb := &proto.NotifyResponse{
Result: &proto.Result{
@ -175,13 +186,16 @@ func notifyResp(appKey string, resp *notify.OrderReq) (*proto.NotifyResponse, er
if err != nil {
return nil, err
}
pb.Headers = string(responseHeadersBytes)
b, err := getNotifyCard(appKey, resp.Cards)
if err != nil {
return nil, err
}
pb.Result.Extra = b
return pb, nil
}
@ -189,18 +203,22 @@ func getNotifyCard(appKey string, cards []notify.Cards) ([]byte, error) {
if len(cards) == 0 {
return nil, nil
}
card := cards[0]
car := &Card{}
t := vo.CardType(card.CardType)
if t.IsPwdNo() {
pwd, err := decryptAES(card.Pwd, appKey)
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
no, err := decryptAES(card.No, appKey)
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
car.Password = pwd
car.Number = no
} else if t.IsPwd() {
@ -208,6 +226,7 @@ func getNotifyCard(appKey string, cards []notify.Cards) ([]byte, error) {
if err != nil {
return nil, proto.ErrorResponseFail(err.Error())
}
car.Password = pwd
} else if t.IsUrl() {
// 无