作者 yangfu

Merge remote-tracking branch 'origin/test'

@@ -138,14 +138,14 @@ func FilterComm(ctx *context.Context) { @@ -138,14 +138,14 @@ func FilterComm(ctx *context.Context) {
138 //if !CheckSign(ctx) { 138 //if !CheckSign(ctx) {
139 // return 139 // return
140 //} 140 //}
  141 + //3.查重uuid
  142 + if !CheckUuid(ctx) {
  143 + return
  144 + }
141 //2.检查token是否有效 145 //2.检查token是否有效
142 if !CheckToken(ctx) { 146 if !CheckToken(ctx) {
143 return 147 return
144 } 148 }
145 - //3.查重uuid  
146 - //if !CheckUuid(ctx) {  
147 - // return  
148 - //}  
149 return 149 return
150 } 150 }
151 151
@@ -223,14 +223,13 @@ func CheckUuid(ctx *context.Context) (result bool) { @@ -223,14 +223,13 @@ func CheckUuid(ctx *context.Context) (result bool) {
223 ) 223 )
224 result = true 224 result = true
225 defer func() { 225 defer func() {
226 - if msg != nil {  
227 - result = false 226 + if msg.Errno != 0 {
228 ctx.Output.JSON(msg, false, false) 227 ctx.Output.JSON(msg, false, false)
229 } 228 }
230 }() 229 }()
231 uuid := ctx.Input.Header("x-mmm-uuid") 230 uuid := ctx.Input.Header("x-mmm-uuid")
232 msg = protocol.NewReturnResponse(auth.CheckUuid(&protocol.CheckUuidRequest{Uuid: uuid})) 231 msg = protocol.NewReturnResponse(auth.CheckUuid(&protocol.CheckUuidRequest{Uuid: uuid}))
233 - if msg != nil { 232 + if msg.Errno != 0 {
234 log.Error(fmt.Sprintf("%v req:%v resp:%v", ctx.Request.RequestURI, uuid, common.AssertJson(msg))) 233 log.Error(fmt.Sprintf("%v req:%v resp:%v", ctx.Request.RequestURI, uuid, common.AssertJson(msg)))
235 } 234 }
236 return 235 return
  1 +package v1
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego"
  6 + "opp/controllers"
  7 + "opp/internal/utils"
  8 + "opp/protocol"
  9 + "path/filepath"
  10 + "strings"
  11 +)
  12 +
  13 +type FileController struct {
  14 + controllers.BaseController
  15 +}
  16 +
  17 +// DownLoad
  18 +// @router /opp/file [post]
  19 +func (this *FileController) DownLoad() {
  20 + var (
  21 + msg *protocol.ResponseMessage
  22 + err error
  23 + rsp *protocol.FileResponse = &protocol.FileResponse{}
  24 + )
  25 + defer func() {
  26 + if msg.Errno != 0 {
  27 + this.Resp(msg)
  28 + }
  29 + }()
  30 + fileUrl := this.Ctx.Request.RequestURI
  31 + filePath := strings.Replace(fileUrl, "/file/opp", "", 1)
  32 + filePath = filepath.Join(beego.AppConfig.String("source_path"), filePath)
  33 + if utils.Exists(filePath) {
  34 + this.Ctx.Output.Download(filePath)
  35 + } else {
  36 + err = protocol.NewCustomMessage(0, fmt.Sprintf("文件不存在:%v", filePath))
  37 + }
  38 + msg = protocol.NewReturnResponse(rsp, err)
  39 +}
  1 +package utils
  2 +
  3 +import "os"
  4 +
  5 +// 判断所给路径文件/文件夹是否存在
  6 +func Exists(path string) bool {
  7 + _, err := os.Stat(path) //os.Stat获取文件信息
  8 + if err != nil {
  9 + if os.IsExist(err) {
  10 + return true
  11 + }
  12 + return false
  13 + }
  14 + return true
  15 +}
  16 +
  17 +// 判断所给路径是否为文件夹
  18 +func IsDir(path string) bool {
  19 + s, err := os.Stat(path)
  20 + if err != nil {
  21 + return false
  22 + }
  23 + return s.IsDir()
  24 +}
  25 +
  26 +// 判断所给路径是否为文件
  27 +func IsFile(path string) bool {
  28 + return !IsDir(path)
  29 +}
@@ -35,7 +35,7 @@ func init() { @@ -35,7 +35,7 @@ func init() {
35 log.Info(fmt.Sprintf("init redis:%v", redisSource)) 35 log.Info(fmt.Sprintf("init redis:%v", redisSource))
36 if err != nil { 36 if err != nil {
37 log.Fatal("connect to redis error address:", beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), err) 37 log.Fatal("connect to redis error address:", beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), err)
38 - //panic(err) 38 + panic(err)
39 } 39 }
40 dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai&charset=utf8mb4", 40 dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai&charset=utf8mb4",
41 beego.AppConfig.String("mysql_user"), 41 beego.AppConfig.String("mysql_user"),
@@ -287,6 +287,14 @@ func init() { @@ -287,6 +287,14 @@ func init() {
287 MethodParams: param.Make(), 287 MethodParams: param.Make(),
288 Params: nil}) 288 Params: nil})
289 289
  290 + beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"],
  291 + beego.ControllerComments{
  292 + Method: "DownLoad",
  293 + Router: `/opp/file`,
  294 + AllowHTTPMethods: []string{"post"},
  295 + MethodParams: param.Make(),
  296 + Params: nil})
  297 +
290 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], 298 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
291 beego.ControllerComments{ 299 beego.ControllerComments{
292 Method: "AnnouncementRead", 300 Method: "AnnouncementRead",
@@ -33,7 +33,9 @@ func init() { @@ -33,7 +33,9 @@ func init() {
33 33
34 nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{})) 34 nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{}))
35 beego.AddNamespace(nsH5) 35 beego.AddNamespace(nsH5)
36 - 36 + //post 下载文件
  37 + beego.Router("/file/opp/*", &v1.FileController{}, "post:DownLoad")
  38 + //get 直接获取文件
37 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path")) 39 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
38 beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access")) 40 beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
39 beego.Handler("/metrics", promhttp.Handler()) 41 beego.Handler("/metrics", promhttp.Handler())
@@ -284,18 +284,21 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe @@ -284,18 +284,21 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
284 284
285 //检查uuid 是否重复 285 //检查uuid 是否重复
286 func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) { 286 func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
287 - //var (  
288 - // logUuid *models.LogUuid  
289 - //)  
290 - //if len(request.Uuid) == 0 {  
291 - // err = common.NewErrorWithMsg(4142, "uuid not empty")  
292 - //}  
293 - //logUuid, err = models.GetLogUuidByUuid(request.Uuid)  
294 - //if err == nil && logUuid != nil {  
295 - // err = common.NewErrorWithMsg(4142, "uuid not valid")  
296 - //}  
297 - //models.AddLogUuid(&models.LogUuid{Uuid: request.Uuid})  
298 - //rsp = &protocol.CheckUuidResponse{} 287 + var ()
  288 + rsp = &protocol.CheckUuidResponse{}
  289 + if len(request.Uuid) == 0 || (request.Uuid == "123456" && beego.BConfig.RunMode != "prod") {
  290 + return
  291 + }
  292 + if redis.Hexists(protocol.RedisKey(protocol.HashUuid), request.Uuid) {
  293 + err = protocol.NewErrWithMessage(4142)
  294 + log.Error("[CheckUuid] 存在:", request.Uuid, err)
  295 + return
  296 + }
  297 + if e := redis.Hset(protocol.RedisKey(protocol.HashUuid), request.Uuid, request.Uuid, 3600); e != nil {
  298 + err = protocol.NewErrWithMessage(4142)
  299 + log.Error("[CheckUuid] 设置:", request.Uuid, e)
  300 + return
  301 + }
299 return 302 return
300 } 303 }
301 304
@@ -55,6 +55,9 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent @@ -55,6 +55,9 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent
55 var tmpTotal int 55 var tmpTotal int
56 models.GetBulletinUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &tmpTotal) 56 models.GetBulletinUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &tmpTotal)
57 item.MsgTotal = tmpTotal 57 item.MsgTotal = tmpTotal
  58 + if tmpTotal == 0 {
  59 + continue
  60 + }
58 } 61 }
59 list = append(list, item) 62 list = append(list, item)
60 } 63 }
@@ -67,7 +67,7 @@ func UploadFile(request *protocol.FileRequest) (rsp *protocol.FileResponse, err @@ -67,7 +67,7 @@ func UploadFile(request *protocol.FileRequest) (rsp *protocol.FileResponse, err
67 return 67 return
68 } 68 }
69 } 69 }
70 - virtualPath = beego.AppConfig.String("source_host") + filepath.Join(virtualPath, request.FileType, date) 70 + virtualPath = fmt.Sprintf("%v%v/%v/%v", beego.AppConfig.String("source_host"), virtualPath, request.FileType, date)
71 for i := range request.Files { 71 for i := range request.Files {
72 f := request.Files[i] 72 f := request.Files[i]
73 prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32)) 73 prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32))