package backend import ( "PaymentCenter/app/constants/pojo" "PaymentCenter/app/http/entities" "PaymentCenter/app/models/appmodel" "errors" "strings" ) type AppListRequest struct { Id int64 `json:"id" form:"id"` MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"` entities.PageRequest } type AppResponse struct { Id int64 `json:"id"` MerchantId int64 `json:"merchant_id"` AppName string `json:"app_name"` AppRemark string `json:"app_remark"` Status int32 `json:"status"` KeyType int32 `json:"key_type"` PublicKey string `json:"public_key"` PrivateKey string `json:"private_key"` MerchantPublicKey string `json:"merchant_public_key"` CreateTime string `json:"create_time"` UpdateTime string `json:"update_time"` WhiteIp string `json:"white_ip"` NotifyUrl string `json:"notify_url"` } func (a *AppResponse) ResponseFromDb(db appmodel.App) { a.Id = db.Id a.MerchantId = db.MerchantId a.AppName = db.AppName a.AppRemark = db.AppRemark a.Status = db.Status a.KeyType = db.KeyType a.PublicKey = db.PublicKey a.PrivateKey = db.PrivateKey a.MerchantPublicKey = db.MerchantPublicKey if !db.CreateTime.IsZero() { a.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") } if !db.UpdateTime.IsZero() { a.UpdateTime = db.UpdateTime.Format("2006-01-02 15:04:05") } a.WhiteIp = db.WhiteIp a.NotifyUrl = db.NotifyUrl } type AppCreateRequest struct { MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"` AppName string `json:"app_name" validate:"required" label:"应用名称"` AppRemark string `json:"app_remark" label:"应用备注"` Status int32 `json:"status" validate:"oneof=0 1 2" label:"应用状态"` KeyType int32 `json:"key_type" label:"应用密钥类型"` PublicKey string `json:"public_key" label:"应用公钥"` PrivateKey string `json:"private_key" label:"应用私钥"` MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"` WhiteIp string `json:"white_ip"` NotifyUrl string `json:"notify_url" label:"通知地址"` } func (a *AppCreateRequest) RequestToDb() (db appmodel.App, err error) { // 判断通知地址url是否合法 if a.NotifyUrl == "" || strings.HasPrefix(a.NotifyUrl, "http://") || strings.HasPrefix(a.NotifyUrl, "https://") { db.MerchantId = a.MerchantId db.AppName = a.AppName db.AppRemark = a.AppRemark db.Status = a.Status db.KeyType = a.KeyType if a.KeyType != pojo.NO_CRYPT && (a.PublicKey == "" || a.PrivateKey == "") { err = errors.New("请填写密钥") return } db.PublicKey = a.PublicKey db.PrivateKey = a.PrivateKey db.MerchantPublicKey = a.MerchantPublicKey db.WhiteIp = a.WhiteIp db.NotifyUrl = a.NotifyUrl } else { err = errors.New("通知地址格式不正确") return } return } type AppUpdateRequest struct { Id int64 `json:"id" validate:"required" label:"应用ID"` AppName string `json:"app_name" label:"应用名称"` AppRemark string `json:"app_remark" label:"应用备注"` Status int32 `json:"status" label:"应用状态"` KeyType int32 `json:"key_type" label:"应用密钥类型"` PublicKey string `json:"public_key" label:"应用公钥"` PrivateKey string `json:"private_key" label:"应用私钥"` MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"` WhiteIp string `json:"white_ip"` NotifyUrl string `json:"notify_url"` } func (a *AppUpdateRequest) RequestToDb() (db appmodel.App, err error) { // 判断通知地址url是否合法 if a.NotifyUrl == "" || strings.HasPrefix(a.NotifyUrl, "http://") || strings.HasPrefix(a.NotifyUrl, "https://") { db.Id = a.Id db.AppName = a.AppName db.AppRemark = a.AppRemark db.Status = a.Status db.KeyType = a.KeyType db.PublicKey = a.PublicKey db.PrivateKey = a.PrivateKey db.MerchantPublicKey = a.MerchantPublicKey db.WhiteIp = a.WhiteIp db.NotifyUrl = a.NotifyUrl } else { err = errors.New("通知地址格式不正确") return } return } type GenerateDecryptKeyRequest struct { KeyType int32 `json:"key_type" form:"key_type" label:"密钥类型"` }