作者 yangfu

版本控制 客户端版本大于等于0.9.0

... ... @@ -98,6 +98,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
h.Sign = ctx.Input.Header("x-mmm-sign")
h.Uuid = ctx.Input.Header("x-mmm-uuid")
h.TimeStamp = ctx.Input.Header("x-mmm-timestamp")
h.Version = ctx.Input.Header("x-mmm-version")
h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面
if h.Uid == 0 {
h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64)
... ...
... ... @@ -8,6 +8,7 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"reflect"
"strconv"
"strings"
)
... ... @@ -96,3 +97,27 @@ func DeepCopy(dst, src interface{}) error {
}
return gob.NewDecoder(&buf).Decode(dst)
}
//检查版本信息
func ValidVersion(current, compare string) bool {
curVersions := strings.Split(current, ".")
comVersions := strings.Split(compare, ".")
for i := range curVersions {
//v1,v2:=strings.TrimSpace(curVersions[i]),""
v1, _ := strconv.ParseInt(strings.TrimSpace(curVersions[i]), 10, 64)
var v2 int64
if i < len(comVersions) {
v2, _ = strconv.ParseInt(strings.TrimSpace(comVersions[i]), 10, 64)
}
if v1 == 0 && v2 == 0 {
continue
}
if v1 >= v2 {
return true
}
if v1 < v2 {
return false
}
}
return false
}
... ...
package utils
import "testing"
import (
"fmt"
"testing"
)
func Test_DeepCopy(t *testing.T) {
type User1 struct {
... ... @@ -23,3 +26,27 @@ func Test_DeepCopy(t *testing.T) {
}
//t.Log(src,"\n",dst)
}
func TestValidVersion(t *testing.T) {
inputs := []struct {
In string
Compare string
Out bool
}{
{In: "0.9.0", Compare: "0.8.0", Out: true},
{In: "0.8.11", Compare: "0.8.0", Out: true},
{In: "0.7.0", Compare: "0.8.0", Out: false},
{In: "0.8.0", Compare: "0.8.0", Out: true},
{In: "0.9", Compare: "0.8.0", Out: true},
{In: "0.10", Compare: "0.8.0", Out: true},
{In: "1.8.0", Compare: "0.8.0", Out: true},
{In: "0.99.0", Compare: "0.8.0", Out: true},
{In: "01.0.0", Compare: "0.8.0", Out: true},
}
for i := range inputs {
input := inputs[i]
if ValidVersion(input.In, input.Compare) != input.Out {
t.Fatal(fmt.Sprintf("valid version fail. input :%v compare:%v want:%v", input.In, input.Compare, input.Out))
}
}
}
... ...
... ... @@ -23,6 +23,7 @@ var Nums = []byte("0123456789")
type RequestHeader struct {
TimeStamp string
Version string
Uuid string
Sign string
DeviceType int
... ...
package protocol
const RequireVersion = "0.9.0"
/*
全局变量声明
*/
... ...
... ... @@ -289,6 +289,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"],
beego.ControllerComments{
Method: "GetPlayInfo",
Router: `/getPlayInfo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"],
beego.ControllerComments{
Method: "DownLoad",
Router: `/opp/file`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -51,6 +51,11 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
err = protocol.NewErrWithMessage(2002, err) //账号不存在
return
}
if !utils.ValidVersion(header.Version, protocol.RequireVersion) {
log.Warn(fmt.Sprintf("版本不足 当前手机版本:%v 需要版本大于:%v", header.Version, protocol.RequireVersion))
err = protocol.NewCustomMessage(2002, "版本不足,请升级app") //账号不存在
return
}
//获取最后一次公司编号给统一用户中心
if u, e := models.GetUserAuthByUserId(user.Id, protocol.DeviceType); e == nil && user.UserCenterId == id {
if company, e = models.GetCompanyById(u.CurrentCompanyId); e == nil {
... ...