Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
kefu_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
24286a8f
authored
Mar 11, 2020
by
chenxianqi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
3cf11d81
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
24 deletions
conf/app.conf
configs/index.go
controllers/public_controller.go
filters/index.go
routers/router.go
services/contact_service.go
services/message_service.go
utils/message_into.go
conf/app.conf
View file @
24286a8f
...
...
@@ -26,15 +26,15 @@ mimc_HttpUrl = "https://mimc.chat.xiaomi.net/api/account/token"
[
dev
]
httpaddr
=
"localhost"
# 小米mimc配置信息(小米开放平台创建)
mimc_appId
=
288230376151
7669588
mimc_appKey
=
"5
111766983588
"
mimc_appSecret
=
"
b0L3IOz/9Ob809v8H2FbVg
=="
mimc_appId
=
288230376151
8338059
mimc_appKey
=
"5
201833828059
"
mimc_appSecret
=
"
wjLFWivIORCFsi3tHr9wHQ
=="
# IM数据库信息
kf_alias_name
=
"default"
kf_driver_name
=
"mysql"
kf_mysql_host
=
"
aissz.com
"
kf_mysql_port
=
"3
63
6"
kf_mysql_host
=
"
192.168.31.72
"
kf_mysql_port
=
"3
30
6"
kf_mysql_user
=
"root"
kf_mysql_db
=
"kefu_server_dev"
kf_mysql_pwd
=
"chenxianqi"
...
...
configs/index.go
View file @
24286a8f
...
...
@@ -9,6 +9,6 @@ type ResponseStatusType int
const
(
ResponseError
ResponseStatusType
=
500
ResponseSucess
ResponseStatusType
=
200
ResponseFail
ResponseStatusType
=
40
1
ResponseFail
ResponseStatusType
=
40
0
ResponseNotFound
ResponseStatusType
=
404
)
controllers/public_controller.go
View file @
24286a8f
...
...
@@ -10,6 +10,7 @@ import (
"os"
"path"
"strconv"
"strings"
"time"
"github.com/astaxie/beego"
...
...
@@ -103,7 +104,6 @@ func (c *PublicController) Register() {
if
err
:=
json
.
Unmarshal
([]
byte
(
fetchResult
),
&
imTokenDto
);
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"注册失败!"
,
&
err
)
}
// update userinfo
c
.
UserRepository
.
Update
(
user
.
ID
,
orm
.
Params
{
"Online"
:
1
,
...
...
@@ -112,6 +112,7 @@ func (c *PublicController) Register() {
"LastActivity"
:
time
.
Now
()
.
Unix
(),
"Token"
:
imTokenDto
.
Data
.
Token
,
})
user
.
Token
=
imTokenDto
.
Data
.
Token
}
else
{
...
...
@@ -353,9 +354,14 @@ func (c *PublicController) GetCompanyInfo() {
// This Api can be connected to Xiaomi's message callback to determine whether it is an offline message to handle the push
// see https://admin.mimc.chat.xiaomi.net/docs/09-callback.html
// Or the client can manually store messages through the Api
// OFFLINE_MSG type is offline message
// NORMAL_MSG type is online message
// Notice!!!: This Api does not handle types other than NORMAL_MSG
func
(
c
*
PublicController
)
PushMessage
()
{
// PushMessage
// PushMessage.MsgType == "NORMAL_MSG" || "OFFLINE_MSG"
// PushMessage.Payload, Must be base64 of models.Message
type
PushMessage
struct
{
MsgType
string
`json:"msgType"`
Payload
string
`json:"payload"`
...
...
@@ -369,13 +375,13 @@ func (c *PublicController) PushMessage() {
// is not Single chat message And kill
if
pushMessage
.
MsgType
!=
"NORMAL_MSG"
{
c
.
JSON
(
configs
.
ResponseFail
,
"sorry
this is not Single chat message"
,
nil
)
c
.
JSON
(
configs
.
ResponseFail
,
"sorry
you send message type is not NORMAL_MSG, it is "
+
pushMessage
.
MsgType
,
nil
)
}
// push message store
var
getMessage
models
.
Message
msgContent
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
pushMessage
.
Payload
)
msgContent
,
_
=
base64
.
StdEncoding
.
DecodeString
(
string
(
msgContent
))
var
msgContent
[]
byte
msgContent
,
_
=
base64
.
StdEncoding
.
DecodeString
(
pushMessage
.
Payload
)
msgContent
,
_
=
base64
.
StdEncoding
.
DecodeString
(
strings
.
Replace
(
string
(
msgContent
),
"
\"
"
,
""
,
-
1
))
json
.
Unmarshal
(
msgContent
,
&
getMessage
)
utils
.
MessageInto
(
getMessage
,
false
)
...
...
@@ -425,6 +431,35 @@ func (c *PublicController) Upload() {
c
.
JSON
(
configs
.
ResponseSucess
,
"上传成功!"
,
&
fileName
)
}
// CancelMessage cancel a message
func
(
c
*
PublicController
)
CancelMessage
()
{
removeMessageRequestDto
:=
models
.
RemoveMessageRequestDto
{}
if
err
:=
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
removeMessageRequestDto
);
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"参数有误,请检查!"
,
nil
)
}
// validation
valid
:=
validation
.
Validation
{}
valid
.
Required
(
removeMessageRequestDto
.
Key
,
"key"
)
.
Message
(
"key不能为空!"
)
valid
.
Required
(
removeMessageRequestDto
.
FromAccount
,
"from_account"
)
.
Message
(
"from_account不能为空!"
)
valid
.
Required
(
removeMessageRequestDto
.
ToAccount
,
"to_account"
)
.
Message
(
"to_account不能为空!"
)
if
valid
.
HasErrors
()
{
for
_
,
err
:=
range
valid
.
Errors
{
c
.
JSON
(
configs
.
ResponseFail
,
err
.
Message
,
nil
)
}
}
// cancel
messageRepository
:=
services
.
GetMessageRepositoryInstance
()
_
,
err
:=
messageRepository
.
Delete
(
removeMessageRequestDto
)
if
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"撤回失败!"
,
&
err
)
}
c
.
JSON
(
configs
.
ResponseSucess
,
"撤回成功!"
,
nil
)
}
// GetMessageHistoryList get user messages
func
(
c
*
PublicController
)
GetMessageHistoryList
()
{
...
...
filters/index.go
View file @
24286a8f
...
...
@@ -9,8 +9,6 @@ import (
"strings"
"time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/orm"
)
...
...
@@ -33,7 +31,6 @@ var FilterToken = func(ctx *context.Context) {
}
oldToken
:=
ctx
.
Input
.
Header
(
"Authorization"
)
logs
.
Info
(
"oldTokenoldToken==="
,
oldToken
)
isExistInSlice
:=
utils
.
InExistInSlice
(
ctx
.
Request
.
RequestURI
,
whitelist
)
isMatch
,
_
:=
regexp
.
MatchString
(
`^Bearer\s`
,
oldToken
)
if
(
isExistInSlice
==
false
&&
oldToken
==
""
)
||
!
isMatch
{
...
...
routers/router.go
View file @
24286a8f
...
...
@@ -47,6 +47,8 @@ func init() {
beego
.
NSRouter
(
"/window/:id"
,
&
controllers
.
PublicController
{},
"put:Window"
),
beego
.
NSRouter
(
"/upload"
,
&
controllers
.
PublicController
{},
"post:Upload"
),
beego
.
NSRouter
(
"/messages"
,
&
controllers
.
PublicController
{},
"post:GetMessageHistoryList"
),
beego
.
NSRouter
(
"/message/push"
,
&
controllers
.
PublicController
{},
"post:PushMessage"
),
beego
.
NSRouter
(
"/message/cancel"
,
&
controllers
.
PublicController
{},
"post:CancelMessage"
),
),
// knowledge_base
...
...
services/contact_service.go
View file @
24286a8f
...
...
@@ -34,7 +34,7 @@ func GetContactRepositoryInstance() *ContactRepository {
// Add add a Contact
func
(
r
*
ContactRepository
)
Add
(
contact
*
models
.
Contact
)
(
int64
,
error
)
{
row
,
err
:=
r
.
o
.
Insert
(
&
contact
)
row
,
err
:=
r
.
o
.
Insert
(
contact
)
if
err
!=
nil
{
logs
.
Warn
(
"Add add a Contact------------"
,
err
)
}
...
...
@@ -53,12 +53,12 @@ func (r *ContactRepository) GetContact(id int64) *models.Contact {
// GetContactWithIds get one Contact with ids
func
(
r
*
ContactRepository
)
GetContactWithIds
(
ids
...
int64
)
(
*
models
.
Contact
,
error
)
{
var
contact
*
models
.
Contact
var
contact
models
.
Contact
err
:=
r
.
q
.
Filter
(
"from_account__in"
,
ids
)
.
Filter
(
"to_account__in"
,
ids
)
.
One
(
&
contact
)
if
err
!=
nil
{
logs
.
Warn
(
"GetContactWithIds get one Contact with ids------------"
,
err
)
}
return
contact
,
err
return
&
contact
,
err
}
// UpdateIsSessionEnd update
...
...
services/message_service.go
View file @
24286a8f
...
...
@@ -17,6 +17,7 @@ type MessageRepositoryInterface interface {
Add
(
message
*
models
.
Message
)
(
int64
,
error
)
GetReadCount
(
uid
int64
)
(
int64
,
error
)
ClearRead
(
uid
int64
)
(
int64
,
error
)
Cancel
(
fromAccount
int64
,
toAccount
int64
,
key
int64
)
error
}
// MessageRepository struct
...
...
@@ -33,7 +34,7 @@ func GetMessageRepositoryInstance() *MessageRepository {
// Add add a message
func
(
r
*
MessageRepository
)
Add
(
message
*
models
.
Message
)
(
int64
,
error
)
{
row
,
err
:=
r
.
o
.
Insert
(
&
message
)
row
,
err
:=
r
.
o
.
Insert
(
message
)
if
err
!=
nil
{
logs
.
Warn
(
"Add add a message------------"
,
err
)
}
...
...
utils/message_into.go
View file @
24286a8f
...
...
@@ -75,12 +75,13 @@ func MessageInto(message models.Message, isKF bool) {
// 处理客服聊天列表
if
contact
,
err
:=
contactRepository
.
GetContactWithIds
(
message
.
ToAccount
,
message
.
FromAccount
);
err
!=
nil
{
contact
.
ToAccount
=
message
.
ToAccount
contact
.
FromAccount
=
message
.
FromAccount
contact
.
LastMessageType
=
message
.
BizType
contact
.
CreateAt
=
time
.
Now
()
.
Unix
()
contact
.
LastMessage
=
message
.
Payload
_
,
_
=
contactRepository
.
Add
(
contact
)
newContact
:=
models
.
Contact
{}
newContact
.
ToAccount
=
message
.
ToAccount
newContact
.
FromAccount
=
message
.
FromAccount
newContact
.
LastMessageType
=
message
.
BizType
newContact
.
CreateAt
=
time
.
Now
()
.
Unix
()
newContact
.
LastMessage
=
message
.
Payload
_
,
_
=
contactRepository
.
Add
(
&
newContact
)
}
else
{
isSessionEnd
:=
0
if
message
.
BizType
==
"end"
||
message
.
BizType
==
"timeout"
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment