42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package request
|
|
|
|
import (
|
|
"sort"
|
|
"strconv"
|
|
)
|
|
|
|
type CreatedOrder struct {
|
|
PayKey string `json:"payKey" description:"用户key" valid:"AlphaNumeric;"`
|
|
OrderNo string `json:"orderNo" description:"订单号" valid:"AlphaNumeric;"`
|
|
OrderPrice float64 `json:"orderPrice" description:"订单金额" valid:"Required;"`
|
|
OrderPeriod string `json:"orderPeriod" description:"订单周期" valid:"Required;"`
|
|
NotifyUrl string `json:"notifyUrl" description:"回调地址" valid:"Required;"`
|
|
Sign string `json:"sign" description:"签名" valid:"Required;"`
|
|
ProductCode string `json:"productCode" description:"产品编码" valid:"Required;"`
|
|
IP string `json:"ip" description:"ip地址"`
|
|
}
|
|
|
|
// ToMap 转换为map类型
|
|
func (c *CreatedOrder) ToMap() map[string]string {
|
|
data := map[string]string{
|
|
"payKey": c.PayKey,
|
|
"orderNo": c.OrderNo,
|
|
"orderPrice": strconv.FormatFloat(c.OrderPrice, 'g', -1, 64),
|
|
"orderPeriod": c.OrderPeriod,
|
|
"notifyUrl": c.NotifyUrl,
|
|
"productCode": c.ProductCode,
|
|
"sign": c.Sign,
|
|
}
|
|
// 按照键的字母顺序排序
|
|
keyList := make([]string, 0)
|
|
for key := range data {
|
|
keyList = append(keyList, key)
|
|
}
|
|
sort.Strings(keyList)
|
|
sortedData := map[string]string{}
|
|
for _, key := range keyList {
|
|
sortedData[key] = data[key]
|
|
}
|
|
return data
|
|
}
|