From 5bd8aa9046b8c69094be9a787f50745b1b4a6517 Mon Sep 17 00:00:00 2001 From: aarongao Date: Wed, 18 Mar 2020 15:22:59 +0800 Subject: [PATCH] V1.0 --- .gitignore | 1 + API/Operator.go | 40 ++++++++++++++++++---------------------- API/User.go | 31 ++++++++++++++++--------------- Config/config.go | 1 + Config/config.json | 3 ++- DB/db.go | 24 ++++++++++++------------ Lib/DelayMessage/delaymessage.go | 10 +++++----- Version.md | 18 ++++++++++++++++++ main.go | 4 ++-- 9 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 Version.md diff --git a/.gitignore b/.gitignore index 8f07515..8fc19e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ main +main2 tiles Upload Console diff --git a/API/Operator.go b/API/Operator.go index 670ae86..5ec3b24 100644 --- a/API/Operator.go +++ b/API/Operator.go @@ -89,8 +89,8 @@ func UpdateOperator(c *gin.Context) { var _auth []string json.Unmarshal([]byte(c.PostForm("Auth")), &_auth) - objID, err := primitive.ObjectIDFromHex(c.PostForm("id")) - if err == nil { + objID, errForObjectID := primitive.ObjectIDFromHex(c.PostForm("id")) + if errForObjectID == nil { _, err = DB.CMember.UpdateOne(tools.GetContext(), bson.M{"_id": objID}, @@ -98,35 +98,31 @@ func UpdateOperator(c *gin.Context) { "Auth": _auth, "Username": c.PostForm("Username"), "Password": c.PostForm("Password"), - "Remarks": c.PostForm("Remarks"), + "Remarks": c.PostForm("Remarks"), }}, ) } else { objectID := primitive.NewObjectID() User := &DB.SMember{ - &objectID, - "operator", - c.PostForm("ScenicId"), - c.PostForm("Username"), - c.PostForm("Password"), - "", - "", - "", - "", - "", - "", - &DB.SDevice{}, - _auth, - c.PostForm("Remarks"), + Id: &objectID, + UserType: "operator", + ScenicId: c.PostForm("ScenicId"), + Username: c.PostForm("Username"), + Password: c.PostForm("Password"), + Auth: _auth, + Remarks: c.PostForm("Remarks"), } - // 生成token - var dd time.Duration - dd, err = time.ParseDuration("20m") - User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix()) + _, err := DB.CMember.InsertOne(tools.GetContext(), User) + if err != nil { - DB.CMember.InsertOne(tools.GetContext(), User) + c.JSON(200, tools.ResponseError{ + 1, + "用户名重复", + }) + return + } } diff --git a/API/User.go b/API/User.go index 37fc96d..9830773 100644 --- a/API/User.go +++ b/API/User.go @@ -2,6 +2,7 @@ package Api import ( "github.com/aarongao/tools" + "github.com/davecgh/go-spew/spew" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" @@ -65,18 +66,10 @@ func LoginUser(c *gin.Context) { var auth = []string{"用户管理", "通知管理"} objectID := primitive.NewObjectID() User = &DB.SMember{ - &objectID, - "visitor", - "", - "", - "", - "", - "", - c.PostForm("Mobile"), - "", - "", - "", - &DB.SDevice{ + Id: &objectID, + UserType: "visitor", + Mobile: c.PostForm("Mobile"), + Device: &DB.SDevice{ c.Request.Header.Get("DeviceId"), c.Request.Header.Get("Mac"), c.Request.Header.Get("UDID"), @@ -86,10 +79,18 @@ func LoginUser(c *gin.Context) { c.Request.Header.Get("AppVersion"), c.Request.Header.Get("DeviceToken"), }, - auth, - "", + Auth: auth, + } + _, err := DB.CMember.InsertOne(tools.GetContext(), User) + if err != nil { + + spew.Dump(err) + c.JSON(200, tools.ResponseError{ + 1, + "登陆失败(数据创建错误)", + }) + return } - DB.CMember.InsertOne(tools.GetContext(), User) } } else { diff --git a/Config/config.go b/Config/config.go index dc2058a..659cb61 100644 --- a/Config/config.go +++ b/Config/config.go @@ -9,6 +9,7 @@ type Config struct { RedisPath string Env string TokenSecret string + ServerPort string } var Info = Config{} diff --git a/Config/config.json b/Config/config.json index c831719..4a1efed 100644 --- a/Config/config.json +++ b/Config/config.json @@ -6,5 +6,6 @@ "dbPassword": "leyoutu123456", "redisPath": "127.0.0.1:6379", "Env": "DEV", - "tokenSecret": "token.secret" + "tokenSecret": "token.secret", + "ServerPort": ":8080" } diff --git a/DB/db.go b/DB/db.go index b8ea890..3ff30d3 100644 --- a/DB/db.go +++ b/DB/db.go @@ -150,18 +150,18 @@ type SInvestigation struct { type SMember struct { Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"` UserType string `bson:"UserType" json:"UserType"` // "root" or "operator" or "visitor" - ScenicId string `bson:"ScenicId" json:"ScenicId"` - Username string `bson:"Username" json:"Username"` - Password string `bson:"Password" json:"Password"` - Birthday string `bson:"Birthday" json:"Birthday"` - FullName string `bson:"FullName" json:"FullName"` - Mobile string `bson:"Mobile" json:"Mobile"` - Openid string `bson:"Openid" json:"Openid"` - Token string `bson:"Token" json:"Token"` - Sex string `bson:"Sex" json:"Sex"` - Device *SDevice `bson:"Device" json:"Device"` //设备信息 - Auth []string `bson:"Auth" json:"Auth"` //权限信息 - Remarks string `bson:"Remarks" json:"Remarks"` //说明 + ScenicId string `bson:"ScenicId,omitempty" json:"ScenicId,omitempty"` + Username string `bson:"Username,omitempty" json:"Username,omitempty"` + Password string `bson:"Password,omitempty" json:"Password,omitempty"` + Birthday string `bson:"Birthday,omitempty" json:"Birthday"` + FullName string `bson:"FullName,omitempty" json:"FullName"` + Mobile string `bson:"Mobile,omitempty" json:"Mobile"` + Openid string `bson:"Openid,omitempty" json:"Openid"` + Token string `bson:"Token,omitempty" json:"Token,omitempty"` + Sex string `bson:"Sex,omitempty" json:"Sex"` + Device *SDevice `bson:"Device,omitempty" json:"Device"` //设备信息 + Auth []string `bson:"Auth,omitempty" json:"Auth"` //权限信息 + Remarks string `bson:"Remarks,omitempty" json:"Remarks"` //说明 } type STag struct { diff --git a/Lib/DelayMessage/delaymessage.go b/Lib/DelayMessage/delaymessage.go index 0930dc6..d9096e5 100644 --- a/Lib/DelayMessage/delaymessage.go +++ b/Lib/DelayMessage/delaymessage.go @@ -78,19 +78,19 @@ func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, deviceToken strin iDelayTIme := i64Time - nowTimeU if i64Time <= nowTimeU { - return errors.New("delayTime error...") + return errors.New("设定时间小于当前时间") } if deviceToken == "" { - return errors.New("deviceToken error...") + return errors.New("缺少设备ID号") } if title == "" { - return errors.New("title error...") + return errors.New("缺少标题") } if content == "" { - return errors.New("content error...") + return errors.New("缺少内容") } if userid == "" { - return errors.New("userid error...") + return errors.New("缺少用户ID") } objectID := primitive.NewObjectID() diff --git a/Version.md b/Version.md new file mode 100644 index 0000000..2e342f5 --- /dev/null +++ b/Version.md @@ -0,0 +1,18 @@ +## 版本号:v1.1 + +##### 生产环境地址:http://leyoutu.st-i.com.cn/api/v1.1/ + +##### 测试环境地址:http://leyoutu.sti-uat.com/api/v1.1/ + +##### 变更说明: + +1. /UserInfo接口增加权限验证(需要携带Token),游客和操作员看到的信息内容不一样 +2. + +##### 开发&发布流程: + +1. 提交代码到git(v1.1分支) +2. 编译为内测版本至TestFlight,并附带升级明细 +3. 合并master分支 +4. 修改正式接口地址并编译为公测版本至TestFlight +5. 发布至商店 \ No newline at end of file diff --git a/main.go b/main.go index c7b03cc..d3d9145 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( // @APIVersion 1.0.0 // @APITitle 乐游图后端接口文档 -// @BasePath 正式 leyoutu.st-i.com.cn; 测试 letu.api.imagchina.com +// @BasePath 正式 leyoutu.st-i.com.cn; 测试 leyoutu.sti-uat.com var Gin *gin.Engine func main() { @@ -195,7 +195,7 @@ func main() { spew.Dump(err) } - Gin.Run(":8080") + Gin.Run(Config.Info.ServerPort) } func InitController(method string, uri string, handFunc func(c *gin.Context), auth *DB.SModel) { -- libgit2 0.21.0