126 lines
4.3 KiB
Go
126 lines
4.3 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
)
|
|
|
|
// MpConfig 微信配置表
|
|
type MpConfig struct {
|
|
global.GVA_MODEL
|
|
ConfigType string `json:"configType" gorm:"type:varchar(32);not null;index;comment:配置类型 mp公众号 mini小程序"`
|
|
AppID string `json:"appId" gorm:"type:varchar(128);not null;comment:应用ID"`
|
|
AppSecret string `json:"appSecret" gorm:"type:varchar(256);not null;comment:应用密钥"`
|
|
Token *string `json:"token" gorm:"type:varchar(128);comment:Token"`
|
|
EncodingAESKey *string `json:"encodingAESKey" gorm:"type:varchar(256);comment:消息加解密密钥"`
|
|
|
|
// 公众号特有配置
|
|
ServerURL *string `json:"serverUrl" gorm:"type:varchar(512);comment:服务器地址"`
|
|
WebhookURL *string `json:"webhookUrl" gorm:"type:varchar(512);comment:Webhook地址"`
|
|
|
|
// 小程序特有配置
|
|
MiniAppName *string `json:"miniAppName" gorm:"type:varchar(128);comment:小程序名称"`
|
|
MiniAppDesc *string `json:"miniAppDesc" gorm:"type:varchar(512);comment:小程序描述"`
|
|
|
|
// 状态信息
|
|
Status string `json:"status" gorm:"type:varchar(32);default:'inactive';comment:状态 active激活 inactive未激活"`
|
|
LastTestTime *time.Time `json:"lastTestTime" gorm:"comment:最后测试时间"`
|
|
TestResult *string `json:"testResult" gorm:"type:varchar(512);comment:测试结果"`
|
|
|
|
// 扩展配置
|
|
ExtraConfig *string `json:"extraConfig" gorm:"type:text;comment:扩展配置JSON"`
|
|
Remark *string `json:"remark" gorm:"type:varchar(512);comment:备注"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (MpConfig) TableName() string {
|
|
return "mp_config"
|
|
}
|
|
|
|
// ConfigType 配置类型常量
|
|
const (
|
|
ConfigTypeMP = "mp" // 公众号
|
|
ConfigTypeMini = "mini" // 小程序
|
|
)
|
|
|
|
// Status 状态常量
|
|
const (
|
|
ConfigStatusActive = "active" // 激活
|
|
ConfigStatusInactive = "inactive" // 未激活
|
|
ConfigStatusError = "error" // 错误
|
|
)
|
|
|
|
// IsMP 是否为公众号配置
|
|
func (c *MpConfig) IsMP() bool {
|
|
return c.ConfigType == ConfigTypeMP
|
|
}
|
|
|
|
// IsMini 是否为小程序配置
|
|
func (c *MpConfig) IsMini() bool {
|
|
return c.ConfigType == ConfigTypeMini
|
|
}
|
|
|
|
// IsActive 是否激活状态
|
|
func (c *MpConfig) IsActive() bool {
|
|
return c.Status == ConfigStatusActive
|
|
}
|
|
|
|
// IsInactive 是否未激活状态
|
|
func (c *MpConfig) IsInactive() bool {
|
|
return c.Status == ConfigStatusInactive
|
|
}
|
|
|
|
// IsError 是否错误状态
|
|
func (c *MpConfig) IsError() bool {
|
|
return c.Status == ConfigStatusError
|
|
}
|
|
|
|
// GetDisplayName 获取显示名称
|
|
func (c *MpConfig) GetDisplayName() string {
|
|
if c.IsMP() {
|
|
return "微信公众号"
|
|
} else if c.IsMini() {
|
|
if c.MiniAppName != nil && *c.MiniAppName != "" {
|
|
return *c.MiniAppName
|
|
}
|
|
return "微信小程序"
|
|
}
|
|
return "未知类型"
|
|
}
|
|
|
|
// MpWebhookLog 微信Webhook日志表
|
|
type MpWebhookLog struct {
|
|
global.GVA_MODEL
|
|
ConfigID uint `json:"configId" gorm:"not null;index;comment:配置ID"`
|
|
RequestURL string `json:"requestUrl" gorm:"type:varchar(512);not null;comment:请求URL"`
|
|
RequestMethod string `json:"requestMethod" gorm:"type:varchar(16);not null;comment:请求方法"`
|
|
RequestHeaders *string `json:"requestHeaders" gorm:"type:text;comment:请求头"`
|
|
RequestBody *string `json:"requestBody" gorm:"type:text;comment:请求体"`
|
|
ResponseStatus int `json:"responseStatus" gorm:"not null;comment:响应状态码"`
|
|
ResponseBody *string `json:"responseBody" gorm:"type:text;comment:响应体"`
|
|
ProcessTime int `json:"processTime" gorm:"not null;comment:处理时间(毫秒)"`
|
|
ErrorMessage *string `json:"errorMessage" gorm:"type:varchar(512);comment:错误信息"`
|
|
|
|
// 微信相关字段
|
|
Signature *string `json:"signature" gorm:"type:varchar(128);comment:微信签名"`
|
|
Timestamp *string `json:"timestamp" gorm:"type:varchar(32);comment:时间戳"`
|
|
Nonce *string `json:"nonce" gorm:"type:varchar(32);comment:随机数"`
|
|
Echostr *string `json:"echostr" gorm:"type:varchar(128);comment:随机字符串"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (MpWebhookLog) TableName() string {
|
|
return "mp_webhook_log"
|
|
}
|
|
|
|
// IsSuccess 是否成功
|
|
func (l *MpWebhookLog) IsSuccess() bool {
|
|
return l.ResponseStatus >= 200 && l.ResponseStatus < 300
|
|
}
|
|
|
|
// IsError 是否错误
|
|
func (l *MpWebhookLog) IsError() bool {
|
|
return l.ResponseStatus >= 400 || l.ErrorMessage != nil
|
|
}
|