config必填
This commit is contained in:
parent
09e2355e03
commit
83a7ee8a8d
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"html"
|
||||
"plugins/alipay_cpn/internal/po"
|
||||
"plugins/alipay_cpn/internal/vo"
|
||||
|
@ -11,9 +12,19 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
Prk string `json:"prk"` // 私钥
|
||||
Npk string `json:"npk"` // 回调公钥
|
||||
AppId string `validate:"required" json:"app_id"`
|
||||
Prk string `validate:"required" json:"prk"` // 私钥
|
||||
Npk string `validate:"required" json:"npk"` // 回调公钥
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func transConfig(config []byte) (*Config, error) {
|
||||
|
@ -22,6 +33,9 @@ func transConfig(config []byte) (*Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
@ -30,7 +44,7 @@ func (c *Config) paramReq(req po.Req, method string) (*po.Param, error) {
|
|||
return nil, err
|
||||
}
|
||||
return &po.Param{
|
||||
Timestamp: time.Now().Format("2006-01-02 15:04:05"),
|
||||
Timestamp: time.Now().Format(time.DateTime),
|
||||
Version: vo.Version,
|
||||
AppId: c.AppId,
|
||||
Method: method,
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"html"
|
||||
"plugins/alipay_redpack/internal/po"
|
||||
"plugins/alipay_redpack/internal/vo"
|
||||
|
@ -13,8 +14,18 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
Prk string `json:"prk"` // 私钥
|
||||
AppId string `validate:"required" json:"app_id"`
|
||||
Prk string `validate:"required" json:"prk"`
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func transConfig(config []byte) (*Config, error) {
|
||||
|
@ -23,6 +34,9 @@ func transConfig(config []byte) (*Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ func transConfig(config []byte) (*wechat.Server, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ func transConfig(config []byte) (*wechat.Server, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||
|
@ -12,8 +13,18 @@ import (
|
|||
)
|
||||
|
||||
type Server struct {
|
||||
MchID string `json:"mch_id"`
|
||||
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"`
|
||||
MchID string `validate:"required" json:"mch_id"`
|
||||
MchCertificateSerialNumber string `validate:"required" json:"mch_certificate_serial_number"`
|
||||
}
|
||||
|
||||
func (c *Server) Validate() error {
|
||||
err := validator.New().Struct(c)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("配置有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func newClient(ctx context.Context, c *Server) (*core.Client, error) {
|
||||
|
|
Loading…
Reference in New Issue