|
@@ -4,18 +4,19 @@ import ( |
|
@@ -4,18 +4,19 @@ import ( |
4
|
"bytes"
|
4
|
"bytes"
|
5
|
"encoding/json"
|
5
|
"encoding/json"
|
6
|
"fmt"
|
6
|
"fmt"
|
7
|
- "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
8
|
"html/template"
|
7
|
"html/template"
|
9
|
"math/rand"
|
8
|
"math/rand"
|
10
|
"strconv"
|
9
|
"strconv"
|
11
|
"strings"
|
10
|
"strings"
|
12
|
"time"
|
11
|
"time"
|
13
|
|
12
|
|
|
|
13
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
14
|
+
|
14
|
"ability/internal/repository"
|
15
|
"ability/internal/repository"
|
15
|
"ability/models"
|
16
|
"ability/models"
|
16
|
"ability/protocol"
|
17
|
"ability/protocol"
|
17
|
- s_sms "ability/services/sms"
|
|
|
18
|
s_im "ability/services/im"
|
18
|
s_im "ability/services/im"
|
|
|
19
|
+ s_sms "ability/services/sms"
|
19
|
|
20
|
|
20
|
"github.com/astaxie/beego"
|
21
|
"github.com/astaxie/beego"
|
21
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
22
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
@@ -105,7 +106,7 @@ Success: |
|
@@ -105,7 +106,7 @@ Success: |
105
|
if userInfo.CsAccount==0{
|
106
|
if userInfo.CsAccount==0{
|
106
|
userInfo.CsAccount = imGetRandomCSAccount()
|
107
|
userInfo.CsAccount = imGetRandomCSAccount()
|
107
|
}
|
108
|
}
|
108
|
- userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
109
|
+ userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
109
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
110
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
110
|
return
|
111
|
return
|
111
|
}
|
112
|
}
|
|
@@ -330,94 +331,96 @@ Fail: |
|
@@ -330,94 +331,96 @@ Fail: |
330
|
return
|
331
|
return
|
331
|
}
|
332
|
}
|
332
|
|
333
|
|
333
|
-func CheckIm(request *protocol.CheckImRequest)(rsp *protocol.CheckImResponse,err error){
|
|
|
334
|
- var (
|
|
|
335
|
-
|
|
|
336
|
- )
|
334
|
+func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) {
|
|
|
335
|
+ var ()
|
337
|
if beego.BConfig.RunMode != "prod" {
|
336
|
if beego.BConfig.RunMode != "prod" {
|
338
|
return
|
337
|
return
|
339
|
}
|
338
|
}
|
340
|
- rsp =&protocol.CheckImResponse{}
|
|
|
341
|
- if !request.IsCreated{
|
|
|
342
|
- if err = imUserCreate(request,rsp);err!=nil{
|
339
|
+ rsp = &protocol.CheckImResponse{}
|
|
|
340
|
+ if !request.IsCreated {
|
|
|
341
|
+ if err = imUserCreate(request, rsp); err != nil {
|
343
|
return
|
342
|
return
|
344
|
}
|
343
|
}
|
345
|
- }else{
|
|
|
346
|
- if err = imUserInfoUpdate(request,rsp);err!=nil{
|
344
|
+ } else {
|
|
|
345
|
+ if err = imUserInfoUpdate(request, rsp); err != nil {
|
347
|
return
|
346
|
return
|
348
|
}
|
347
|
}
|
349
|
}
|
348
|
}
|
350
|
- if err = imUserRefreshToken(request,rsp);err!=nil{
|
349
|
+ if err = imUserRefreshToken(request, rsp); err != nil {
|
351
|
return
|
350
|
return
|
352
|
}
|
351
|
}
|
353
|
return
|
352
|
return
|
354
|
}
|
353
|
}
|
|
|
354
|
+
|
355
|
//create
|
355
|
//create
|
356
|
-func imUserCreate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
357
|
- var(
|
|
|
358
|
- param s_im.UserCreate=s_im.UserCreate{
|
|
|
359
|
- Accid:request.Uid,
|
|
|
360
|
- Name:request.Uname,
|
|
|
361
|
- Icon:request.Icon,
|
356
|
+func imUserCreate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
357
|
+ var (
|
|
|
358
|
+ param s_im.UserCreate = s_im.UserCreate{
|
|
|
359
|
+ Accid: request.Uid,
|
|
|
360
|
+ Name: request.Uname,
|
|
|
361
|
+ Icon: request.Icon,
|
362
|
}
|
362
|
}
|
363
|
resp []byte
|
363
|
resp []byte
|
364
|
out s_im.UserCreateResult
|
364
|
out s_im.UserCreateResult
|
365
|
)
|
365
|
)
|
366
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
366
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
367
|
return
|
367
|
return
|
368
|
}
|
368
|
}
|
369
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
369
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
370
|
return
|
370
|
return
|
371
|
}
|
371
|
}
|
372
|
- if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
372
|
+ if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
373
|
return s_im.ErrorFailCall
|
373
|
return s_im.ErrorFailCall
|
374
|
}
|
374
|
}
|
375
|
rsp.ImToken = out.Info.Token
|
375
|
rsp.ImToken = out.Info.Token
|
376
|
return
|
376
|
return
|
377
|
}
|
377
|
}
|
|
|
378
|
+
|
378
|
//update user info
|
379
|
//update user info
|
379
|
-func imUserInfoUpdate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
380
|
- var(
|
|
|
381
|
- param s_im.UserUpdateUinfo=s_im.UserUpdateUinfo{
|
|
|
382
|
- Accid:request.Uid,
|
|
|
383
|
- Name:request.Uname,
|
|
|
384
|
- Icon:request.Icon,
|
380
|
+func imUserInfoUpdate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
381
|
+ var (
|
|
|
382
|
+ param s_im.UserUpdateUinfo = s_im.UserUpdateUinfo{
|
|
|
383
|
+ Accid: request.Uid,
|
|
|
384
|
+ Name: request.Uname,
|
|
|
385
|
+ Icon: request.Icon,
|
385
|
}
|
386
|
}
|
386
|
resp []byte
|
387
|
resp []byte
|
387
|
out s_im.BaseResp
|
388
|
out s_im.BaseResp
|
388
|
)
|
389
|
)
|
389
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
390
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
390
|
return
|
391
|
return
|
391
|
}
|
392
|
}
|
392
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
393
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
393
|
return
|
394
|
return
|
394
|
}
|
395
|
}
|
395
|
- if out.Code!=200{
|
396
|
+ if out.Code != 200 {
|
396
|
return s_im.ErrorFailCall
|
397
|
return s_im.ErrorFailCall
|
397
|
}
|
398
|
}
|
398
|
return
|
399
|
return
|
399
|
}
|
400
|
}
|
|
|
401
|
+
|
400
|
//refresh token
|
402
|
//refresh token
|
401
|
-func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
402
|
- var(
|
|
|
403
|
- param s_im.UserRefreshToken=s_im.UserRefreshToken{
|
|
|
404
|
- Accid:request.Uid,
|
403
|
+func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
404
|
+ var (
|
|
|
405
|
+ param s_im.UserRefreshToken = s_im.UserRefreshToken{
|
|
|
406
|
+ Accid: request.Uid,
|
405
|
}
|
407
|
}
|
406
|
resp []byte
|
408
|
resp []byte
|
407
|
out s_im.UserCreateResult
|
409
|
out s_im.UserCreateResult
|
408
|
)
|
410
|
)
|
409
|
- if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
411
|
+ if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
410
|
return
|
412
|
return
|
411
|
}
|
413
|
}
|
412
|
- if err = json.Unmarshal(resp,&out);err!=nil{
|
414
|
+ if err = json.Unmarshal(resp, &out); err != nil {
|
413
|
return
|
415
|
return
|
414
|
}
|
416
|
}
|
415
|
- if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
417
|
+ if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
416
|
return s_im.ErrorFailCall
|
418
|
return s_im.ErrorFailCall
|
417
|
}
|
419
|
}
|
418
|
rsp.ImToken = out.Info.Token
|
420
|
rsp.ImToken = out.Info.Token
|
419
|
return
|
421
|
return
|
420
|
}
|
422
|
}
|
|
|
423
|
+
|
421
|
// 获取客服id
|
424
|
// 获取客服id
|
422
|
func imGetRandomCSAccount()( acid int64){
|
425
|
func imGetRandomCSAccount()( acid int64){
|
423
|
kefus,err :=models.GetUsersKefu()
|
426
|
kefus,err :=models.GetUsersKefu()
|
|
@@ -436,4 +439,3 @@ func imGetRandomCSAccount()( acid int64){ |
|
@@ -436,4 +439,3 @@ func imGetRandomCSAccount()( acid int64){ |
436
|
return acid
|
439
|
return acid
|
437
|
}
|
440
|
}
|
438
|
|
441
|
|
439
|
- |
|
|