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