Commit 7aca21290e25ceb40e2fba0b17fc23f4d1d29d61
1 parent
cfee98cb
Exists in
v1.2
and in
2 other branches
增加调查和短信接口
Showing
4 changed files
with
47 additions
and
3 deletions
 
Show diff stats
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +package Api | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "github.com/aarongao/tools" | ||
| 6 | + "github.com/gin-gonic/gin" | ||
| 7 | + "letu/DB" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +// @Title 增加调查 | ||
| 11 | +// @Description 增加调查 | ||
| 12 | +// @Accept json | ||
| 13 | +// @Produce json | ||
| 14 | +// @Param UserId 1111111 string true "UserId" | ||
| 15 | +// @Param Mobile 18616619599 string true "联系电话" | ||
| 16 | +// @Param type 1 string true "类型" | ||
| 17 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | ||
| 18 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
| 19 | +// @Router /Investigation/Save? [post] | ||
| 20 | +func Save(c *gin.Context) { | ||
| 21 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
| 22 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
| 23 | + | ||
| 24 | + var Data map[string]interface{} | ||
| 25 | + json.Unmarshal([]byte(c.PostForm("Data")), &Data) | ||
| 26 | + | ||
| 27 | + DB.CInvestigation.Insert(DB.SInvestigation{ | ||
| 28 | + c.PostForm("UserId"), | ||
| 29 | + c.PostForm("Mobile"), | ||
| 30 | + Data, | ||
| 31 | + }) | ||
| 32 | + | ||
| 33 | + c.JSON(200, tools.ResponseSeccess{ | ||
| 34 | + 0, | ||
| 35 | + "ok", | ||
| 36 | + }) | ||
| 37 | + | ||
| 38 | +} | 
API/Sms.go
| @@ -65,8 +65,10 @@ func Send(c *gin.Context) { | @@ -65,8 +65,10 @@ func Send(c *gin.Context) { | ||
| 65 | println(err.Error()) | 65 | println(err.Error()) | 
| 66 | reserr = err.Error() | 66 | reserr = err.Error() | 
| 67 | } else { | 67 | } else { | 
| 68 | - reserr = "" | ||
| 69 | - DB.Redis.Set(c.PostForm("Mobile"), code, time.Second*60*3) | 68 | + reserr = response.Code | 
| 69 | + if response.Code == "OK" { | ||
| 70 | + DB.Redis.Set(c.PostForm("Mobile"), code, time.Second*60*3) | ||
| 71 | + } | ||
| 70 | } | 72 | } | 
| 71 | 73 | ||
| 72 | var Location DB.SLocation | 74 | var Location DB.SLocation | 
DB/db.go
| @@ -92,6 +92,9 @@ type SComplaint struct { | @@ -92,6 +92,9 @@ type SComplaint struct { | ||
| 92 | } | 92 | } | 
| 93 | 93 | ||
| 94 | type SInvestigation struct { | 94 | type SInvestigation struct { | 
| 95 | + UserId string `bson:"UserId" json:"UserId"` // 用户ID | ||
| 96 | + Mobile string `bson:"Mobile" json:"Mobile"` //手机号 | ||
| 97 | + Data interface{} `bson:"Data" json:"Data"` | ||
| 95 | } | 98 | } | 
| 96 | type SMember struct { | 99 | type SMember struct { | 
| 97 | Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | 100 | Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | 
main.go
| @@ -42,7 +42,6 @@ func main() { | @@ -42,7 +42,6 @@ func main() { | ||
| 42 | 0, | 42 | 0, | 
| 43 | }) | 43 | }) | 
| 44 | 44 | ||
| 45 | - | ||
| 46 | //设置模式 | 45 | //设置模式 | 
| 47 | DB.DBSession.SetMode(mgo.Monotonic, true) | 46 | DB.DBSession.SetMode(mgo.Monotonic, true) | 
| 48 | //获取文档集 | 47 | //获取文档集 | 
| @@ -57,6 +56,7 @@ func main() { | @@ -57,6 +56,7 @@ func main() { | ||
| 57 | DB.CLine = DB.DB.C("Line") | 56 | DB.CLine = DB.DB.C("Line") | 
| 58 | DB.CAccessLog = DB.DB.C("AccessLog") | 57 | DB.CAccessLog = DB.DB.C("AccessLog") | 
| 59 | DB.CActionLog = DB.DB.C("ActionLog") | 58 | DB.CActionLog = DB.DB.C("ActionLog") | 
| 59 | + DB.CInvestigation = DB.DB.C("Investigation") | ||
| 60 | 60 | ||
| 61 | r := gin.Default() | 61 | r := gin.Default() | 
| 62 | //r.Static("/.well-known", "./.well-known/") | 62 | //r.Static("/.well-known", "./.well-known/") | 
| @@ -84,6 +84,7 @@ func main() { | @@ -84,6 +84,7 @@ func main() { | ||
| 84 | r.POST("/AccessLog", Api.AccessLog) | 84 | r.POST("/AccessLog", Api.AccessLog) | 
| 85 | r.GET("/AccessLog", Api.AccessLog) | 85 | r.GET("/AccessLog", Api.AccessLog) | 
| 86 | r.POST("/Sms/Send", Api.Send) | 86 | r.POST("/Sms/Send", Api.Send) | 
| 87 | + r.POST("/Investigation/Save", Api.Save) | ||
| 87 | //r.GET("/ws", Api.WsPage) | 88 | //r.GET("/ws", Api.WsPage) | 
| 88 | 89 | ||
| 89 | r.Static("/Upload", "./Upload") | 90 | r.Static("/Upload", "./Upload") |