正在显示
18 个修改的文件
包含
362 行增加
和
51 行删除
@@ -30,4 +30,6 @@ net_im_app_secret ="a8d231f5c13a" | @@ -30,4 +30,6 @@ net_im_app_secret ="a8d231f5c13a" | ||
30 | net_im_app_key ="9c5410602597a7fe367aeeebd8210262" | 30 | net_im_app_key ="9c5410602597a7fe367aeeebd8210262" |
31 | 31 | ||
32 | #统一用户中心 | 32 | #统一用户中心 |
33 | -user_center_url ="http://user.fjmaimaimai.com" | ||
33 | +user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com" | ||
34 | +user_center_salt ="rsF0pL!6DwjBO735" | ||
35 | +user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b" |
@@ -2,12 +2,20 @@ package controllers | @@ -2,12 +2,20 @@ package controllers | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + redigo "github.com/gomodule/redigo/redis" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" | ||
5 | "log" | 7 | "log" |
6 | "opp/protocol" | 8 | "opp/protocol" |
9 | + "opp/tests" | ||
7 | "reflect" | 10 | "reflect" |
8 | "testing" | 11 | "testing" |
12 | + "time" | ||
9 | ) | 13 | ) |
10 | 14 | ||
15 | +func init() { | ||
16 | + tests.Init() | ||
17 | +} | ||
18 | + | ||
11 | func Test_GenMessage(t *testing.T) { | 19 | func Test_GenMessage(t *testing.T) { |
12 | input := []struct { | 20 | input := []struct { |
13 | Rsp interface{} | 21 | Rsp interface{} |
@@ -52,3 +60,69 @@ func Test_Valid(t *testing.T) { | @@ -52,3 +60,69 @@ func Test_Valid(t *testing.T) { | ||
52 | } | 60 | } |
53 | DefaultController.Valid(req) | 61 | DefaultController.Valid(req) |
54 | } | 62 | } |
63 | + | ||
64 | +func Test_RedisSubPub(t *testing.T) { | ||
65 | + c := redis.NewClient() | ||
66 | + defer c.Close() | ||
67 | + /*redis 订阅*/ | ||
68 | + go subscribe() | ||
69 | + go subscribe() | ||
70 | + go subscribe() | ||
71 | + | ||
72 | + for { | ||
73 | + var s string | ||
74 | + s = time.Now().String() | ||
75 | + _, err := c.Do("PUBLISH", "chat", s) | ||
76 | + if err != nil { | ||
77 | + fmt.Println("pub err: ", err) | ||
78 | + return | ||
79 | + } | ||
80 | + time.Sleep(time.Second * 5) | ||
81 | + } | ||
82 | +} | ||
83 | + | ||
84 | +func subscribe() { | ||
85 | + psc := redis.NewPubsubClient() | ||
86 | + defer func() { | ||
87 | + psc.Conn.Close() | ||
88 | + psc.Unsubscribe("chat") | ||
89 | + }() | ||
90 | + | ||
91 | + psc.Subscribe("chat") | ||
92 | + | ||
93 | + for { | ||
94 | + switch v := psc.Receive().(type) { | ||
95 | + case redigo.Message: | ||
96 | + log.Println(fmt.Printf("%s: message: %s\n", v.Channel, v.Data)) | ||
97 | + case redigo.Subscription: | ||
98 | + log.Println(fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)) | ||
99 | + case error: | ||
100 | + log.Println("error:", v) | ||
101 | + return | ||
102 | + } | ||
103 | + } | ||
104 | +} | ||
105 | + | ||
106 | +//redis lock | ||
107 | +func Test_RedisLock(t *testing.T) { | ||
108 | + //key :="opp:chance:1456872" | ||
109 | + //go func(){ | ||
110 | + // mutext :=redis.NewMutex(key) | ||
111 | + // mutext.Lock() | ||
112 | + // defer mutext.UnLock() | ||
113 | + // time.Sleep(time.Second*10) | ||
114 | + //}() | ||
115 | + //time.Sleep(time.Second*1) | ||
116 | + //go func(){ | ||
117 | + // mutext :=redis.NewMutex(key) | ||
118 | + // defer mutext.UnLock() | ||
119 | + // if !mutext.TryLock(3){ | ||
120 | + // t.Log("fail to get lock",key) | ||
121 | + // return | ||
122 | + // } | ||
123 | + // t.Log("get lock...") | ||
124 | + // time.Sleep(time.Second*3) | ||
125 | + // t.Log("release lock...") | ||
126 | + //}() | ||
127 | + //time.Sleep(11*time.Second) | ||
128 | +} |
@@ -5,6 +5,7 @@ go 1.12 | @@ -5,6 +5,7 @@ go 1.12 | ||
5 | require ( | 5 | require ( |
6 | github.com/astaxie/beego v1.10.0 | 6 | github.com/astaxie/beego v1.10.0 |
7 | github.com/go-sql-driver/mysql v1.4.1 | 7 | github.com/go-sql-driver/mysql v1.4.1 |
8 | + github.com/gomodule/redigo v1.7.0 | ||
8 | github.com/gorilla/websocket v1.4.1 | 9 | github.com/gorilla/websocket v1.4.1 |
9 | github.com/klauspost/cpuid v1.2.1 // indirect | 10 | github.com/klauspost/cpuid v1.2.1 // indirect |
10 | github.com/prometheus/client_golang v1.1.0 | 11 | github.com/prometheus/client_golang v1.1.0 |
@@ -76,7 +76,7 @@ func DeleteUserDepartment(id int64) (err error) { | @@ -76,7 +76,7 @@ func DeleteUserDepartment(id int64) (err error) { | ||
76 | func GetUserDepartments(userId int64, companyId int64, v interface{}) (err error) { | 76 | func GetUserDepartments(userId int64, companyId int64, v interface{}) (err error) { |
77 | o := orm.NewOrm() | 77 | o := orm.NewOrm() |
78 | sql := ` | 78 | sql := ` |
79 | -select a.department_id,b.name,b.parent_id,b.managers | 79 | +select a.department_id,b.name,b.parent_id,b.managers,b.relation,a.create_time |
80 | from user_department a INNER JOIN department b on a.department_id = b.id | 80 | from user_department a INNER JOIN department b on a.department_id = b.id |
81 | where a.user_id =? and a.company_id =? and enable_status =1 and b.delete_at =0` | 81 | where a.user_id =? and a.company_id =? and enable_status =1 and b.delete_at =0` |
82 | if _, err = o.Raw(sql, userId, companyId).QueryRows(v); err == nil { | 82 | if _, err = o.Raw(sql, userId, companyId).QueryRows(v); err == nil { |
@@ -73,15 +73,14 @@ func DeleteUserPosition(id int) (err error) { | @@ -73,15 +73,14 @@ func DeleteUserPosition(id int) (err error) { | ||
73 | return | 73 | return |
74 | } | 74 | } |
75 | 75 | ||
76 | - | ||
77 | func GetUserPositions(userId int64, companyId int64, v interface{}) (err error) { | 76 | func GetUserPositions(userId int64, companyId int64, v interface{}) (err error) { |
78 | o := orm.NewOrm() | 77 | o := orm.NewOrm() |
79 | sql := ` | 78 | sql := ` |
80 | -select a.position_id,b.name | 79 | +select a.position_id,b.name,b.relation,a.create_at |
81 | from user_position a INNER JOIN position b on a.position_id = b.id | 80 | from user_position a INNER JOIN position b on a.position_id = b.id |
82 | where a.user_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1` | 81 | where a.user_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1` |
83 | - if _, err = o.Raw(sql,userId, companyId).QueryRows(v); err == nil { | 82 | + if _, err = o.Raw(sql, userId, companyId).QueryRows(v); err == nil { |
84 | return | 83 | return |
85 | } | 84 | } |
86 | return | 85 | return |
87 | -} | ||
86 | +} |
@@ -22,6 +22,8 @@ type User struct { | @@ -22,6 +22,8 @@ type User struct { | ||
22 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp);auto_now_add" description:"最后一次登录时间"` | 22 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp);auto_now_add" description:"最后一次登录时间"` |
23 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` | 23 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` |
24 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` | 24 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` |
25 | + Accid int64 `orm:"column(accid)" description:"网易云id"` | ||
26 | + UserCenterId int64 `orm:"column(user_center_id)" description:"统一用户中心用户id"` | ||
25 | } | 27 | } |
26 | 28 | ||
27 | func (t *User) TableName() string { | 29 | func (t *User) TableName() string { |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | -import "opp/models" | 3 | +import ( |
4 | + "opp/models" | ||
5 | + "time" | ||
6 | +) | ||
4 | 7 | ||
5 | //聚合数据 | 8 | //聚合数据 |
6 | 9 | ||
@@ -14,6 +17,8 @@ type UserBaseInfoAggregation struct { | @@ -14,6 +17,8 @@ type UserBaseInfoAggregation struct { | ||
14 | } | 17 | } |
15 | 18 | ||
16 | type Position struct { | 19 | type Position struct { |
17 | - PositionId int `orm:"column(position_id)` | ||
18 | - Name string `orm:"column(name)` | 20 | + PositionId int `orm:"column(position_id)` |
21 | + Name string `orm:"column(name)` | ||
22 | + Relation string `orm:"column(relation)" json:"-"` | ||
23 | + CreateTime time.Time `orm:"column(create_time)" json:"-"` | ||
19 | } | 24 | } |
@@ -37,18 +37,19 @@ type LoginResponse struct { | @@ -37,18 +37,19 @@ type LoginResponse struct { | ||
37 | } | 37 | } |
38 | 38 | ||
39 | /*统一用户中心登录*/ | 39 | /*统一用户中心登录*/ |
40 | -type LoginUserCenterRequest struct { | 40 | +type UserCenterLoginRequest struct { |
41 | Phone string `json:"phone"` | 41 | Phone string `json:"phone"` |
42 | PassWord string `json:"password"` | 42 | PassWord string `json:"password"` |
43 | } | 43 | } |
44 | 44 | ||
45 | -type LoginUserCenterResponse struct { | ||
46 | - Id int64 `json:"id"` | ||
47 | - Phone string `json:"phone"` | ||
48 | - NickName string `json:"nickname"` | ||
49 | - Avatar string `json:"avatar"` | ||
50 | - Token string `json:"token"` | ||
51 | - Accid string `json:"accid"` | 45 | +type UserCenterLoginResponse struct { |
46 | + Id int64 `json:"id"` | ||
47 | + Phone string `json:"phone"` | ||
48 | + NickName string `json:"nickname"` | ||
49 | + Avatar string `json:"avatar"` | ||
50 | + Token string `json:"token"` | ||
51 | + Accid string `json:"accid"` | ||
52 | + CustomerAccount string `json:"customerAccount"` | ||
52 | } | 53 | } |
53 | 54 | ||
54 | /*SmsCode*/ | 55 | /*SmsCode*/ |
protocol/const.go
0 → 100644
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | +import "time" | ||
4 | + | ||
3 | const ( | 5 | const ( |
4 | DepartmentAll = iota + 1 //公司所有部门 | 6 | DepartmentAll = iota + 1 //公司所有部门 |
5 | DepartmentUser //用户所有部门 | 7 | DepartmentUser //用户所有部门 |
@@ -18,6 +20,8 @@ type Department struct { | @@ -18,6 +20,8 @@ type Department struct { | ||
18 | Name string `orm:"column(name)" json:"name"` | 20 | Name string `orm:"column(name)" json:"name"` |
19 | PId int `orm:"column(parent_id)" json:"-"` | 21 | PId int `orm:"column(parent_id)" json:"-"` |
20 | ManagerString string `orm:"column(managers)" json:"-"` | 22 | ManagerString string `orm:"column(managers)" json:"-"` |
23 | + Relation string `orm:"column(relation)" json:"-"` | ||
24 | + CreateTime time.Time `orm:"column(create_time)" json:"-"` | ||
21 | Managers []int `json:"-"` | 25 | Managers []int `json:"-"` |
22 | Departments []*Department `json:"departments,omitempty"` | 26 | Departments []*Department `json:"departments,omitempty"` |
23 | } | 27 | } |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | +) | ||
6 | + | ||
3 | var errmessge ErrorMap = map[int]string{ | 7 | var errmessge ErrorMap = map[int]string{ |
4 | 0: "成功", | 8 | 0: "成功", |
5 | 1: "系统异常", | 9 | 1: "系统异常", |
@@ -22,6 +26,8 @@ var errmessge ErrorMap = map[int]string{ | @@ -22,6 +26,8 @@ var errmessge ErrorMap = map[int]string{ | ||
22 | 4140: "refreshToken过期,需要重新登录授权", | 26 | 4140: "refreshToken过期,需要重新登录授权", |
23 | 4141: "accessToken过期或无效,需要进行重新获取令牌", | 27 | 4141: "accessToken过期或无效,需要进行重新获取令牌", |
24 | 4142: "Uuid已存在,请求失败", | 28 | 4142: "Uuid已存在,请求失败", |
29 | + | ||
30 | + 5000: "繁忙,请稍后再试", | ||
25 | } | 31 | } |
26 | 32 | ||
27 | /*MessageCenter */ | 33 | /*MessageCenter */ |
@@ -72,3 +78,15 @@ type UserMsg struct { | @@ -72,3 +78,15 @@ type UserMsg struct { | ||
72 | IsRead int `json:"isRead"` | 78 | IsRead int `json:"isRead"` |
73 | //机会 //评论 | 79 | //机会 //评论 |
74 | } | 80 | } |
81 | + | ||
82 | +type Message struct { | ||
83 | + ErrorCode | ||
84 | + Data json.RawMessage `json:"data"` | ||
85 | +} | ||
86 | + | ||
87 | +func (m Message) Unmarshal(v interface{}) error { | ||
88 | + if len(m.Data) == 0 { | ||
89 | + m.Data = []byte("{}") | ||
90 | + } | ||
91 | + return json.Unmarshal(m.Data, v) | ||
92 | +} |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "opp/internal/utils" | 8 | "opp/internal/utils" |
9 | "opp/models" | 9 | "opp/models" |
10 | "opp/protocol" | 10 | "opp/protocol" |
11 | + "strings" | ||
11 | "sync" | 12 | "sync" |
12 | ) | 13 | ) |
13 | 14 | ||
@@ -60,13 +61,67 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err | @@ -60,13 +61,67 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err | ||
60 | v = &protocol.BaseUserInfo{ | 61 | v = &protocol.BaseUserInfo{ |
61 | UserId: agg.User.Id, | 62 | UserId: agg.User.Id, |
62 | NickName: agg.User.NickName, | 63 | NickName: agg.User.NickName, |
63 | - Department: agg.Department[0].Name, | ||
64 | - Position: agg.Position[0].Name, | 64 | + Department: GetTopDepartment(agg.Department).Name, |
65 | + Position: GetTopPosition(agg.Position).Name, | ||
65 | CompanyName: agg.Company.Name, | 66 | CompanyName: agg.Company.Name, |
66 | } | 67 | } |
67 | return | 68 | return |
68 | } | 69 | } |
69 | 70 | ||
71 | +//获取最高层级部门 | ||
72 | +func GetTopDepartment(departments []*protocol.Department) *protocol.Department { | ||
73 | + var top *protocol.Department | ||
74 | + var countTop, countTmp = 0, 0 | ||
75 | + for i := range departments { | ||
76 | + tmp := departments[i] | ||
77 | + if i == 0 { | ||
78 | + top = tmp | ||
79 | + continue | ||
80 | + } | ||
81 | + countTop = strings.Count(top.Relation, protocol.RelateSplit) | ||
82 | + countTmp = strings.Count(tmp.Relation, protocol.RelateSplit) | ||
83 | + //层级越高 关系越少 | ||
84 | + if countTmp > countTop { | ||
85 | + continue | ||
86 | + } | ||
87 | + if countTmp < countTop { | ||
88 | + top = tmp | ||
89 | + continue | ||
90 | + } | ||
91 | + if tmp.CreateTime.Unix() < top.CreateTime.Unix() { | ||
92 | + top = tmp | ||
93 | + } | ||
94 | + } | ||
95 | + return top | ||
96 | +} | ||
97 | + | ||
98 | +//获取最高层级职位 | ||
99 | +func GetTopPosition(positions []*protocol.Position) *protocol.Position { | ||
100 | + var top *protocol.Position | ||
101 | + var countTop, countTmp = 0, 0 | ||
102 | + for i := range positions { | ||
103 | + tmp := positions[i] | ||
104 | + if i == 0 { | ||
105 | + top = tmp | ||
106 | + continue | ||
107 | + } | ||
108 | + countTop = strings.Count(top.Relation, protocol.RelateSplit) | ||
109 | + countTmp = strings.Count(tmp.Relation, protocol.RelateSplit) | ||
110 | + //层级越高 关系越少 | ||
111 | + if countTmp > countTop { | ||
112 | + continue | ||
113 | + } | ||
114 | + if countTmp < countTop { | ||
115 | + top = tmp | ||
116 | + continue | ||
117 | + } | ||
118 | + if tmp.CreateTime.Unix() < top.CreateTime.Unix() { | ||
119 | + top = tmp | ||
120 | + } | ||
121 | + } | ||
122 | + return top | ||
123 | +} | ||
124 | + | ||
70 | func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) { | 125 | func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) { |
71 | var ( | 126 | var ( |
72 | c *models.Chance | 127 | c *models.Chance |
services/agg/aggregation_test.go
0 → 100644
1 | +package agg | ||
2 | + | ||
3 | +import ( | ||
4 | + "opp/protocol" | ||
5 | + "testing" | ||
6 | + "time" | ||
7 | +) | ||
8 | + | ||
9 | +func Test_GetTopDepartment(t *testing.T) { | ||
10 | + input := []*protocol.Department{ | ||
11 | + &protocol.Department{ | ||
12 | + DepartmentId: 1, | ||
13 | + Relation: "1", | ||
14 | + CreateTime: time.Unix(1575968581, 0), | ||
15 | + }, | ||
16 | + &protocol.Department{ | ||
17 | + DepartmentId: 4, | ||
18 | + Relation: "2/3/4", | ||
19 | + CreateTime: time.Unix(1575968581, 0), | ||
20 | + }, | ||
21 | + &protocol.Department{ | ||
22 | + DepartmentId: 5, | ||
23 | + Relation: "2/3/5", | ||
24 | + CreateTime: time.Unix(1575968580, 0), | ||
25 | + }, | ||
26 | + } | ||
27 | + out := GetTopDepartment(input) | ||
28 | + if out.DepartmentId != 1 { | ||
29 | + t.Fatal("top department error") | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | +func Test_GetTopPosition(t *testing.T) { | ||
34 | + input := []*protocol.Position{ | ||
35 | + &protocol.Position{ | ||
36 | + PositionId: 1, | ||
37 | + Relation: "1/2/3/4", | ||
38 | + CreateTime: time.Unix(1575968581, 0), | ||
39 | + }, | ||
40 | + &protocol.Position{ | ||
41 | + PositionId: 4, | ||
42 | + Relation: "2/3/4", | ||
43 | + CreateTime: time.Unix(1575968581, 0), | ||
44 | + }, | ||
45 | + &protocol.Position{ | ||
46 | + PositionId: 5, | ||
47 | + Relation: "2/3/5", | ||
48 | + CreateTime: time.Unix(1575968580, 0), | ||
49 | + }, | ||
50 | + } | ||
51 | + out := GetTopPosition(input) | ||
52 | + if out.PositionId != 5 { | ||
53 | + t.Fatal("top department error") | ||
54 | + } | ||
55 | +} |
@@ -2,13 +2,18 @@ package auth | @@ -2,13 +2,18 @@ package auth | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "bytes" | 4 | "bytes" |
5 | + "crypto/sha1" | ||
6 | + "encoding/hex" | ||
5 | "encoding/json" | 7 | "encoding/json" |
6 | "fmt" | 8 | "fmt" |
9 | + "github.com/astaxie/beego/httplib" | ||
7 | "github.com/astaxie/beego/orm" | 10 | "github.com/astaxie/beego/orm" |
8 | "html/template" | 11 | "html/template" |
12 | + "io/ioutil" | ||
9 | "math/rand" | 13 | "math/rand" |
14 | + "net/http" | ||
10 | "opp/internal/utils" | 15 | "opp/internal/utils" |
11 | - "strings" | 16 | + "strconv" |
12 | "time" | 17 | "time" |
13 | 18 | ||
14 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" | 19 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" |
@@ -35,10 +40,11 @@ var ( | @@ -35,10 +40,11 @@ var ( | ||
35 | //登录 | 40 | //登录 |
36 | func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) { | 41 | func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) { |
37 | var ( | 42 | var ( |
38 | - user *models.User | ||
39 | - userAuth *models.UserAuth | ||
40 | - result bool | ||
41 | - checkImResponse *protocol.CheckImResponse | 43 | + user *models.User |
44 | + userAuth *models.UserAuth | ||
45 | + result bool | ||
46 | + //checkImResponse *protocol.CheckImResponse | ||
47 | + userCenterLogin *protocol.UserCenterLoginResponse | ||
42 | ) | 48 | ) |
43 | user, err = repository.User.GetUsersByMobile(request.Phone) | 49 | user, err = repository.User.GetUsersByMobile(request.Phone) |
44 | if err != nil { | 50 | if err != nil { |
@@ -48,16 +54,24 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -48,16 +54,24 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
48 | } | 54 | } |
49 | switch request.GrantType { | 55 | switch request.GrantType { |
50 | case protocol.LoginTypePassPord: | 56 | case protocol.LoginTypePassPord: |
51 | - if beego.BConfig.RunMode != "dev" { | ||
52 | - | ||
53 | - } | ||
54 | - if strings.Compare(user.Passwd, request.PassWord) == 0 { | ||
55 | - goto Success | ||
56 | - } else { | ||
57 | - err = protocol.NewErrWithMessage(2021, err) //登录密码错误 | 57 | + //if beego.BConfig.RunMode == "prod" { |
58 | + // | ||
59 | + //} | ||
60 | + if userCenterLogin, err = userCenterAuthLogin(&protocol.UserCenterLoginRequest{ | ||
61 | + Phone: request.Phone, | ||
62 | + PassWord: request.PassWord, | ||
63 | + }); err != nil { | ||
64 | + log.Error(err) | ||
58 | return | 65 | return |
59 | } | 66 | } |
60 | - break | 67 | + goto Success |
68 | + //if strings.Compare(user.Passwd, request.PassWord) == 0 { | ||
69 | + // goto Success | ||
70 | + //} else { | ||
71 | + // err = protocol.NewErrWithMessage(2021, err) //登录密码错误 | ||
72 | + // return | ||
73 | + //} | ||
74 | + //break | ||
61 | case protocol.LoginTypeSmdcode: | 75 | case protocol.LoginTypeSmdcode: |
62 | //if beego.BConfig.RunMode =="dev"{ | 76 | //if beego.BConfig.RunMode =="dev"{ |
63 | // goto Success | 77 | // goto Success |
@@ -93,20 +107,32 @@ Success: | @@ -93,20 +107,32 @@ Success: | ||
93 | } | 107 | } |
94 | } | 108 | } |
95 | userAuth.AuthCode = uid.NewV1().StringNoDash() | 109 | userAuth.AuthCode = uid.NewV1().StringNoDash() |
96 | - if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ | ||
97 | - Uid: fmt.Sprintf("%v", user.Id), | ||
98 | - Uname: user.NickName, | ||
99 | - Icon: user.Icon, | ||
100 | - IsCreated: user.ImToken != "", | ||
101 | - }); err != nil { | 110 | + //if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ |
111 | + // Uid: fmt.Sprintf("%v", user.Id), | ||
112 | + // Uname: user.NickName, | ||
113 | + // Icon: user.Icon, | ||
114 | + // IsCreated: user.ImToken != "", | ||
115 | + //}); err != nil { | ||
116 | + // return | ||
117 | + //} | ||
118 | + //if checkImResponse != nil && checkImResponse.ImToken != "" { | ||
119 | + // user.ImToken = checkImResponse.ImToken | ||
120 | + //} | ||
121 | + //if user.CsAccount == 0 { | ||
122 | + // user.CsAccount = imGetRandomCSAccount() | ||
123 | + //} | ||
124 | + | ||
125 | + /*更新用户信息*/ | ||
126 | + user.CsAccount, _ = strconv.ParseInt(userCenterLogin.CustomerAccount, 10, 64) | ||
127 | + user.ImToken = userCenterLogin.Token | ||
128 | + user.Icon = userCenterLogin.Avatar | ||
129 | + user.NickName = userCenterLogin.NickName | ||
130 | + user.Accid, _ = strconv.ParseInt(userCenterLogin.Accid, 10, 64) | ||
131 | + user.UserCenterId = userCenterLogin.Id | ||
132 | + if err = repository.User.UpdateUserInfo(user); err != nil { | ||
133 | + log.Error(err) | ||
102 | return | 134 | return |
103 | } | 135 | } |
104 | - if checkImResponse != nil && checkImResponse.ImToken != "" { | ||
105 | - user.ImToken = checkImResponse.ImToken | ||
106 | - } | ||
107 | - if user.CsAccount == 0 { | ||
108 | - user.CsAccount = imGetRandomCSAccount() | ||
109 | - } | ||
110 | userAuth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire) | 136 | userAuth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire) |
111 | if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil { | 137 | if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil { |
112 | return | 138 | return |
@@ -489,3 +515,56 @@ func imGetRandomCSAccount() (acid int64) { | @@ -489,3 +515,56 @@ func imGetRandomCSAccount() (acid int64) { | ||
489 | acid = kefus[index].Id //Accid | 515 | acid = kefus[index].Id //Accid |
490 | return acid | 516 | return acid |
491 | } | 517 | } |
518 | + | ||
519 | +//用户中心密码登录 | ||
520 | +func userCenterAuthLogin(request *protocol.UserCenterLoginRequest) (rsp *protocol.UserCenterLoginResponse, err error) { | ||
521 | + var ( | ||
522 | + loginMethod = "/auth/login" | ||
523 | + httpRsp *http.Response | ||
524 | + data []byte | ||
525 | + curTime = fmt.Sprintf("%v", time.Now().Unix()) | ||
526 | + appKey = beego.AppConfig.String("user_center_app_key") | ||
527 | + salt = beego.AppConfig.String("user_center_salt") | ||
528 | + ) | ||
529 | + rsp = &protocol.UserCenterLoginResponse{} | ||
530 | + httpReq := httplib.Post(beego.AppConfig.String("user_center_url") + loginMethod) | ||
531 | + httpReq.JSONBody(request) | ||
532 | + httpReq.Header("appKey", appKey) | ||
533 | + httpReq.Header("curTime", curTime) | ||
534 | + httpReq.Header("checkSum", getUserCenterCheckSum(curTime, "", appKey, salt)) | ||
535 | + if httpRsp, err = httpReq.DoRequest(); err != nil { | ||
536 | + log.Error(err) | ||
537 | + return | ||
538 | + } | ||
539 | + data, err = ioutil.ReadAll(httpRsp.Body) | ||
540 | + defer httpRsp.Body.Close() | ||
541 | + if err != nil { | ||
542 | + log.Error(err) | ||
543 | + return | ||
544 | + } | ||
545 | + log.Info(fmt.Sprintf("simnum:%v login user-center response:%v", request.Phone, string(data))) | ||
546 | + type msg struct { | ||
547 | + protocol.ErrorCode | ||
548 | + Data *protocol.UserCenterLoginResponse `json:"data"` | ||
549 | + } | ||
550 | + var message protocol.Message | ||
551 | + if err = json.Unmarshal(data, &message); err != nil { | ||
552 | + log.Error(err) | ||
553 | + return | ||
554 | + } | ||
555 | + if message.Errno == 0 && message.Errmsg == "ok" { | ||
556 | + if err = message.Unmarshal(&rsp); err != nil { | ||
557 | + log.Error(err) | ||
558 | + return | ||
559 | + } | ||
560 | + } else { | ||
561 | + err = fmt.Errorf("error_no:%v msg:%v", message.Errno, message.Errmsg) | ||
562 | + } | ||
563 | + return | ||
564 | +} | ||
565 | + | ||
566 | +func getUserCenterCheckSum(curTime, nonce, appKey, salt string) string { | ||
567 | + sha1 := sha1.New() | ||
568 | + sum := sha1.Sum([]byte(fmt.Sprintf("%s%s%s%s", curTime, nonce, appKey, salt))) | ||
569 | + return hex.EncodeToString(sum) | ||
570 | +} |
1 | package auth | 1 | package auth |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" | ||
4 | "opp/internal/repository" | 5 | "opp/internal/repository" |
5 | "testing" | 6 | "testing" |
6 | 7 | ||
@@ -66,3 +67,16 @@ func Test_RefreshToken(t *testing.T) { | @@ -66,3 +67,16 @@ func Test_RefreshToken(t *testing.T) { | ||
66 | t.Fatal(err, rsp) | 67 | t.Fatal(err, rsp) |
67 | } | 68 | } |
68 | } | 69 | } |
70 | + | ||
71 | +//测试用户中心登录 | ||
72 | +func Test_UserCenterAuthLogin(t *testing.T) { | ||
73 | + if rsp, err := userCenterAuthLogin(&protocol.UserCenterLoginRequest{ | ||
74 | + Phone: "18065048301", | ||
75 | + PassWord: "123456", | ||
76 | + }); err != nil { | ||
77 | + t.Log(err) | ||
78 | + return | ||
79 | + } else { | ||
80 | + t.Log(common.AssertJson(rsp)) | ||
81 | + } | ||
82 | +} |
@@ -211,7 +211,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit | @@ -211,7 +211,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit | ||
211 | ) | 211 | ) |
212 | //1.模板是否存在 | 212 | //1.模板是否存在 |
213 | if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil { | 213 | if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil { |
214 | - log.Error(err) | 214 | + log.Error("模板不存在:", request.AuditTemplateId, err) |
215 | return | 215 | return |
216 | } | 216 | } |
217 | auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} | 217 | auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} |
@@ -35,11 +35,10 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) ( | @@ -35,11 +35,10 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) ( | ||
35 | Company: userBaseInfo.Company.Name, | 35 | Company: userBaseInfo.Company.Name, |
36 | CommendAt: time.GetUnixTimeByNDayUnix(c.CommendAt.Unix(), 0), | 36 | CommendAt: time.GetUnixTimeByNDayUnix(c.CommendAt.Unix(), 0), |
37 | Honored: protocol.BaseUserInfo{ | 37 | Honored: protocol.BaseUserInfo{ |
38 | - UserId: c.UserId, | ||
39 | - NickName: user.NickName, | ||
40 | - //TODO:out index | ||
41 | - Department: userBaseInfo.Department[0].Name, | ||
42 | - Position: userBaseInfo.Position[0].Name, | 38 | + UserId: c.UserId, |
39 | + NickName: user.NickName, | ||
40 | + Department: agg.GetTopDepartment(userBaseInfo.Department).Name, | ||
41 | + Position: agg.GetTopPosition(userBaseInfo.Position).Name, | ||
43 | }, | 42 | }, |
44 | } | 43 | } |
45 | rsp.Lists = append(rsp.Lists, cInfo) | 44 | rsp.Lists = append(rsp.Lists, cInfo) |
@@ -27,7 +27,7 @@ func Init() { | @@ -27,7 +27,7 @@ func Init() { | ||
27 | beego.LoadAppConfig("ini", filepath.Join(path, "conf", filename)) | 27 | beego.LoadAppConfig("ini", filepath.Join(path, "conf", filename)) |
28 | log.InitLog(config.Logger{ | 28 | log.InitLog(config.Logger{ |
29 | Filename: "app.log", | 29 | Filename: "app.log", |
30 | - Level: "3", //7 | 30 | + Level: "7", //7 单元test时 可以把级别设置低一点 减少日志 |
31 | }) | 31 | }) |
32 | err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0") | 32 | err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0") |
33 | if err != nil { | 33 | if err != nil { |
-
请 注册 或 登录 后发表评论