package alipay import ( "fmt" "gitea.cdlsxd.cn/sdk/plugin/alipay/vo" "github.com/go-playground/validator/v10" ) const BaseUri = "https://openapi.alipay.com/gateway.do" const ( Version = "1.0" Format = "json" SignType = "RSA2" Charset = "UTF-8" ) type Client struct { AppId string // 应用ID Prk string // 私钥 PukPath string // 验签公钥 MchCertPath string // 商户证书路径 RootCertPath string // 根证书路径 NotifyUrl string // 回调地址 } type Req interface { Validate() error } var _ Req = (*Param)(nil) type Param struct { AlipayRootCertSn string `json:"alipay_root_cert_sn"` AppCertSn string `json:"app_cert_sn"` AppId string `json:"app_id" validate:"required"` Method string `json:"method" validate:"required"` Format string `json:"format" validate:"required"` Charset string `json:"charset" validate:"required"` SignType string `json:"sign_type" validate:"required"` Timestamp string `json:"timestamp" validate:"required"` Version string `json:"version" validate:"required"` BizContent string `json:"biz_content"` Sign string `json:"sign"` } type ErrorResponse struct { Code vo.Code `json:"code"` Msg string `json:"msg"` SubCode string `json:"sub_code"` SubMsg string `json:"sub_msg"` } type Notify struct { Charset string `json:"charset"` UtcTimestamp string `json:"utc_timestamp"` AppId string `json:"app_id"` Version string `json:"version"` SignType string `json:"sign_type"` NotifyId string `json:"notify_id"` MsgMethod string `json:"msg_method"` Sign string `json:"sign"` BizContent string `json:"biz_content"` } func (req *Param) Validate() error { err := validator.New().Struct(req) if err != nil { for _, err = range err.(validator.ValidationErrors) { return fmt.Errorf("参数有误:" + err.Error()) } } return nil }