正在显示
7 个修改的文件
包含
70 行增加
和
1 行删除
@@ -98,6 +98,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | @@ -98,6 +98,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | ||
98 | h.Sign = ctx.Input.Header("x-mmm-sign") | 98 | h.Sign = ctx.Input.Header("x-mmm-sign") |
99 | h.Uuid = ctx.Input.Header("x-mmm-uuid") | 99 | h.Uuid = ctx.Input.Header("x-mmm-uuid") |
100 | h.TimeStamp = ctx.Input.Header("x-mmm-timestamp") | 100 | h.TimeStamp = ctx.Input.Header("x-mmm-timestamp") |
101 | + h.Version = ctx.Input.Header("x-mmm-version") | ||
101 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面 | 102 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面 |
102 | if h.Uid == 0 { | 103 | if h.Uid == 0 { |
103 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) | 104 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "fmt" | 8 | "fmt" |
9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
10 | "reflect" | 10 | "reflect" |
11 | + "strconv" | ||
11 | "strings" | 12 | "strings" |
12 | ) | 13 | ) |
13 | 14 | ||
@@ -96,3 +97,27 @@ func DeepCopy(dst, src interface{}) error { | @@ -96,3 +97,27 @@ func DeepCopy(dst, src interface{}) error { | ||
96 | } | 97 | } |
97 | return gob.NewDecoder(&buf).Decode(dst) | 98 | return gob.NewDecoder(&buf).Decode(dst) |
98 | } | 99 | } |
100 | + | ||
101 | +//检查版本信息 | ||
102 | +func ValidVersion(current, compare string) bool { | ||
103 | + curVersions := strings.Split(current, ".") | ||
104 | + comVersions := strings.Split(compare, ".") | ||
105 | + for i := range curVersions { | ||
106 | + //v1,v2:=strings.TrimSpace(curVersions[i]),"" | ||
107 | + v1, _ := strconv.ParseInt(strings.TrimSpace(curVersions[i]), 10, 64) | ||
108 | + var v2 int64 | ||
109 | + if i < len(comVersions) { | ||
110 | + v2, _ = strconv.ParseInt(strings.TrimSpace(comVersions[i]), 10, 64) | ||
111 | + } | ||
112 | + if v1 == 0 && v2 == 0 { | ||
113 | + continue | ||
114 | + } | ||
115 | + if v1 >= v2 { | ||
116 | + return true | ||
117 | + } | ||
118 | + if v1 < v2 { | ||
119 | + return false | ||
120 | + } | ||
121 | + } | ||
122 | + return false | ||
123 | +} |
1 | package utils | 1 | package utils |
2 | 2 | ||
3 | -import "testing" | 3 | +import ( |
4 | + "fmt" | ||
5 | + "testing" | ||
6 | +) | ||
4 | 7 | ||
5 | func Test_DeepCopy(t *testing.T) { | 8 | func Test_DeepCopy(t *testing.T) { |
6 | type User1 struct { | 9 | type User1 struct { |
@@ -23,3 +26,27 @@ func Test_DeepCopy(t *testing.T) { | @@ -23,3 +26,27 @@ func Test_DeepCopy(t *testing.T) { | ||
23 | } | 26 | } |
24 | //t.Log(src,"\n",dst) | 27 | //t.Log(src,"\n",dst) |
25 | } | 28 | } |
29 | + | ||
30 | +func TestValidVersion(t *testing.T) { | ||
31 | + inputs := []struct { | ||
32 | + In string | ||
33 | + Compare string | ||
34 | + Out bool | ||
35 | + }{ | ||
36 | + {In: "0.9.0", Compare: "0.8.0", Out: true}, | ||
37 | + {In: "0.8.11", Compare: "0.8.0", Out: true}, | ||
38 | + {In: "0.7.0", Compare: "0.8.0", Out: false}, | ||
39 | + {In: "0.8.0", Compare: "0.8.0", Out: true}, | ||
40 | + {In: "0.9", Compare: "0.8.0", Out: true}, | ||
41 | + {In: "0.10", Compare: "0.8.0", Out: true}, | ||
42 | + {In: "1.8.0", Compare: "0.8.0", Out: true}, | ||
43 | + {In: "0.99.0", Compare: "0.8.0", Out: true}, | ||
44 | + {In: "01.0.0", Compare: "0.8.0", Out: true}, | ||
45 | + } | ||
46 | + for i := range inputs { | ||
47 | + input := inputs[i] | ||
48 | + if ValidVersion(input.In, input.Compare) != input.Out { | ||
49 | + t.Fatal(fmt.Sprintf("valid version fail. input :%v compare:%v want:%v", input.In, input.Compare, input.Out)) | ||
50 | + } | ||
51 | + } | ||
52 | +} |
@@ -23,6 +23,7 @@ var Nums = []byte("0123456789") | @@ -23,6 +23,7 @@ var Nums = []byte("0123456789") | ||
23 | 23 | ||
24 | type RequestHeader struct { | 24 | type RequestHeader struct { |
25 | TimeStamp string | 25 | TimeStamp string |
26 | + Version string | ||
26 | Uuid string | 27 | Uuid string |
27 | Sign string | 28 | Sign string |
28 | DeviceType int | 29 | DeviceType int |
@@ -289,6 +289,14 @@ func init() { | @@ -289,6 +289,14 @@ func init() { | ||
289 | 289 | ||
290 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], | 290 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], |
291 | beego.ControllerComments{ | 291 | beego.ControllerComments{ |
292 | + Method: "GetPlayInfo", | ||
293 | + Router: `/getPlayInfo`, | ||
294 | + AllowHTTPMethods: []string{"post"}, | ||
295 | + MethodParams: param.Make(), | ||
296 | + Params: nil}) | ||
297 | + | ||
298 | + beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], | ||
299 | + beego.ControllerComments{ | ||
292 | Method: "DownLoad", | 300 | Method: "DownLoad", |
293 | Router: `/opp/file`, | 301 | Router: `/opp/file`, |
294 | AllowHTTPMethods: []string{"post"}, | 302 | AllowHTTPMethods: []string{"post"}, |
@@ -51,6 +51,11 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -51,6 +51,11 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
51 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 | 51 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 |
52 | return | 52 | return |
53 | } | 53 | } |
54 | + if !utils.ValidVersion(header.Version, protocol.RequireVersion) { | ||
55 | + log.Warn(fmt.Sprintf("版本不足 当前手机版本:%v 需要版本大于:%v", header.Version, protocol.RequireVersion)) | ||
56 | + err = protocol.NewCustomMessage(2002, "版本不足,请升级app") //账号不存在 | ||
57 | + return | ||
58 | + } | ||
54 | //获取最后一次公司编号给统一用户中心 | 59 | //获取最后一次公司编号给统一用户中心 |
55 | if u, e := models.GetUserAuthByUserId(user.Id, protocol.DeviceType); e == nil && user.UserCenterId == id { | 60 | if u, e := models.GetUserAuthByUserId(user.Id, protocol.DeviceType); e == nil && user.UserCenterId == id { |
56 | if company, e = models.GetCompanyById(u.CurrentCompanyId); e == nil { | 61 | if company, e = models.GetCompanyById(u.CurrentCompanyId); e == nil { |
-
请 注册 或 登录 后发表评论