2024-11-14 18:33:56 +08:00
|
|
|
|
package card
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Order struct {
|
|
|
|
|
Number uint32 `validate:"required" json:"number"`
|
|
|
|
|
MerchantId string `validate:"required" json:"merchantId"`
|
|
|
|
|
OutTradeNo string `validate:"required" json:"outTradeNo"`
|
|
|
|
|
ProductId string `validate:"required" json:"productId"`
|
|
|
|
|
Mobile string `json:"mobile"`
|
|
|
|
|
NotifyUrl string `validate:"required" json:"notifyUrl"`
|
|
|
|
|
Version string `validate:"required" json:"version"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OrderResp struct {
|
2024-11-15 10:34:36 +08:00
|
|
|
|
Code json.Number `json:"code"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
TradeNo string `json:"tradeNo"`
|
2024-11-14 18:33:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Query struct {
|
|
|
|
|
MerchantId string `validate:"required" json:"merchantId"`
|
|
|
|
|
OutTradeNo string `validate:"required" json:"outTradeNo"`
|
|
|
|
|
Version string `validate:"required" json:"version"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type QueryResp struct {
|
2024-11-15 10:34:36 +08:00
|
|
|
|
Code json.Number `json:"code"`
|
2024-11-14 18:33:56 +08:00
|
|
|
|
Status OrderStatus `json:"status"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
OutTradeNo string `json:"outTradeNo"`
|
|
|
|
|
CardCode string `json:"cardCode"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Notify struct {
|
|
|
|
|
MerchantId int `json:"merchantId"`
|
|
|
|
|
OutTradeNo string `json:"outTradeNo"`
|
|
|
|
|
RechargeAccount string `json:"rechargeAccount"`
|
|
|
|
|
Status OrderStatus `json:"status"`
|
|
|
|
|
CardCode string `json:"cardCode"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Order) Json() ([]byte, error) {
|
|
|
|
|
b, err := json.Marshal(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return b, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Order) Validate() error {
|
|
|
|
|
err := validator.New().Struct(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
for _, err = range err.(validator.ValidationErrors) {
|
|
|
|
|
return fmt.Errorf("参数有误:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Query) Json() ([]byte, error) {
|
|
|
|
|
b, err := json.Marshal(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return b, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Query) Validate() error {
|
|
|
|
|
err := validator.New().Struct(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
for _, err = range err.(validator.ValidationErrors) {
|
|
|
|
|
return fmt.Errorf("参数有误:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Notify) Json() ([]byte, error) {
|
|
|
|
|
b, err := json.Marshal(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return b, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Notify) Validate() error {
|
|
|
|
|
err := validator.New().Struct(o)
|
|
|
|
|
if err != nil {
|
|
|
|
|
for _, err = range err.(validator.ValidationErrors) {
|
|
|
|
|
return fmt.Errorf("参数有误:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-11-15 10:34:36 +08:00
|
|
|
|
|
|
|
|
|
func (o *OrderResp) GetCode() Code {
|
|
|
|
|
// 不能直接定义值对象,因为单独定义类型type code json.Number类型无法jsonUnmarshal
|
|
|
|
|
return Code(o.Code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *QueryResp) GetCode() Code {
|
|
|
|
|
// 不能直接定义值对象,因为单独定义类型type code json.Number类型无法jsonUnmarshal
|
|
|
|
|
return Code(o.Code)
|
|
|
|
|
}
|