feat: 更新bugly token
parent
7c5da611b7
commit
f6ac0a62fb
@ -0,0 +1,59 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"autogo/dbsql"
|
||||
"autogo/models"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 设置相关 /api/setting/v2/
|
||||
// @Summary 新建设备
|
||||
// @Description 新建设备,UDID唯一
|
||||
// @accept x-www-form-urlencoded
|
||||
// @Param xtoken formData string true "bugly请求header:XToken"
|
||||
// @Param session formData string true "bugly请求cookies:bugly-session"
|
||||
// @Success 200 {object} models.Response "返回创建后的设备信息"
|
||||
// @Router /api/setting/v2/update_bugly_token [post]
|
||||
func UpdateBuglyToken(c *gin.Context) {
|
||||
rsp := NewResponse()
|
||||
|
||||
xtoken := c.PostForm("xtoken")
|
||||
if xtoken == "" {
|
||||
c.JSON(http.StatusOK, rsp.Error("xtoken为空"))
|
||||
return
|
||||
}
|
||||
|
||||
session := c.PostForm("session")
|
||||
if session == "" {
|
||||
c.JSON(http.StatusOK, rsp.Error("session为空"))
|
||||
return
|
||||
}
|
||||
|
||||
db, err := dbsql.GetConn(dbsql.DSN)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, rsp.Error(err.Error()))
|
||||
return
|
||||
}
|
||||
defer dbsql.Close(db)
|
||||
|
||||
db.Model(models.SysMap{}).Where("name = ? AND `key` = ?", "bugly-login", "xtoken").Update("value", xtoken)
|
||||
if db.Error != nil {
|
||||
c.JSON(http.StatusOK, rsp.Error(db.Error.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
db.Model(models.SysMap{}).Where("name = ? AND `key` = ?", "bugly-login", "session").Update("value", session)
|
||||
if db.Error != nil {
|
||||
c.JSON(http.StatusOK, rsp.Error(db.Error.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
m := make(map[string]string)
|
||||
m["xtoken"] = xtoken
|
||||
m["session"] = session
|
||||
rsp.Data = m
|
||||
c.JSON(http.StatusOK, rsp.Success())
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type SysMap struct {
|
||||
Id int `json:"id" gorm:"column:id;type:int(11);primary_key;not null;autoIncrement;comment:主键"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
Key string `json:"key" gorm:"column:key"`
|
||||
Value string `json:"value" gorm:"column:value"`
|
||||
CreateTime time.Time `json:"create_time" gorm:"column:create_time;not null;autoCreateTime;comment:创建时间"`
|
||||
UpdateTime time.Time `json:"update_time" gorm:"column:update_time;not null;autoUpdateTime;comment:更新时间"`
|
||||
IsDel int `json:"is_del" gorm:"column:is_del;type:int(1);not null;comment:是否已删除"`
|
||||
}
|
||||
|
||||
func (t *SysMap) TableName() string {
|
||||
return "sys_mapping"
|
||||
}
|
||||
Loading…
Reference in New Issue