122 lines
2.5 KiB
Go
122 lines
2.5 KiB
Go
package vo
|
|
|
|
import (
|
|
"fmt"
|
|
"xiawan/wx/srv/srvconfig"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type DTO struct {
|
|
|
|
//自定义提示状态码
|
|
Code interface{}
|
|
|
|
//数据展示
|
|
Data interface{}
|
|
|
|
//提示文本
|
|
Text interface{}
|
|
|
|
//是否成功
|
|
Success bool
|
|
|
|
//62数据
|
|
Data62 string
|
|
|
|
//票据
|
|
Ticket string
|
|
|
|
//微信验证URL(当Ticket不为空时提供)
|
|
WechatVerifyUrl string `json:"wechat_verify_url,omitempty"`
|
|
|
|
//用户操作指引(当Ticket不为空时提供)
|
|
VerifyInstructions string `json:"verify_instructions,omitempty"`
|
|
}
|
|
|
|
func NewFail(errMsg string) DTO {
|
|
return DTO{
|
|
Code: FAIL,
|
|
Data: nil,
|
|
Text: errMsg,
|
|
}
|
|
}
|
|
func NewFailOffline(errMsg string) DTO {
|
|
return DTO{
|
|
Code: FAIL_Offline,
|
|
Data: nil,
|
|
Text: errMsg,
|
|
}
|
|
}
|
|
|
|
func NewSuccess(h gin.H, msg string) DTO {
|
|
return DTO{
|
|
Code: SUCCESS,
|
|
Data: h,
|
|
Text: msg,
|
|
}
|
|
}
|
|
|
|
func NewSuccessObj(h interface{}, msg string) DTO {
|
|
return DTO{
|
|
Code: SUCCESS,
|
|
Data: h,
|
|
Text: msg,
|
|
}
|
|
}
|
|
|
|
// NewSuccessWithTicket 创建包含ticket和微信验证信息的成功响应
|
|
func NewSuccessWithTicket(data interface{}, msg, data62, ticket string) DTO {
|
|
dto := DTO{
|
|
Code: SUCCESS,
|
|
Data: data,
|
|
Text: msg,
|
|
Success: true,
|
|
Data62: data62,
|
|
Ticket: ticket,
|
|
}
|
|
|
|
// 如果有ticket,添加微信验证相关信息
|
|
if ticket != "" {
|
|
dto.WechatVerifyUrl = fmt.Sprintf("https://weixin110.qq.com/security/acct/newreadtemplate?t=extdevsignin/slaveverify&ticket=%s&lang=zh_CN", ticket)
|
|
dto.VerifyInstructions = "请按照以下步骤完成微信验证:\n1. 复制上面的 wechat_verify_url 链接\n2. 打开微信客户端\n3. 在微信聊天窗口中粘贴并发送该链接\n4. 点击链接完成验证(8.30又被和谐咯, 现在只能走网页版滑块, 哎~)"
|
|
}
|
|
|
|
return dto
|
|
}
|
|
|
|
func NewFailObj(h interface{}, msg string) DTO {
|
|
return DTO{
|
|
Code: FAIL,
|
|
Data: h,
|
|
Text: msg,
|
|
}
|
|
}
|
|
|
|
func NewFailUUId(uuid string) DTO {
|
|
return DTO{
|
|
Code: FAIL_UUID,
|
|
Data: nil,
|
|
Text: fmt.Sprintf("%s 该链接不存在!", uuid),
|
|
}
|
|
}
|
|
|
|
func NewFAILDoesNotBelongToServer(uuid string) DTO {
|
|
return DTO{
|
|
Code: FAIL_DoesNotBelongToServer,
|
|
Data: nil,
|
|
Text: fmt.Sprintf("%s 不属于[%s]该服务器实例", uuid, srvconfig.GlobalSetting.TargetIp),
|
|
}
|
|
}
|
|
|
|
const (
|
|
FAIL_DATA = -1 //数据格式错误
|
|
FAIL_UUID = -2 //UUID 不存在
|
|
FAIL_Bound = -3 //账号被绑定
|
|
FAIL_Offline = -4 //账号掉线
|
|
FAIL_DoesNotBelongToServer = -5 //UUId不需要该服务器实例
|
|
|
|
SUCCESS = 200 // 执行成功
|
|
FAIL = 300 // 执行失败
|
|
)
|