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
9e9a2058
authored
Mar 10, 2020
by
keith
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
ad0a0917
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
55 additions
and
32 deletions
controllers/message_controller.go
controllers/public_controller.go
controllers/robot_controller.go
im/handler_contacts.go → kefu_go_robot/handler_contacts.go
im/handler_message.go → kefu_go_robot/handler_message.go
im/handler_status.go → kefu_go_robot/handler_status.go
im/handler_token.go → kefu_go_robot/handler_token.go
kefu_go_robot/main.go
im/message_p2p.go → kefu_go_robot/message_p2p.go
im/mimc_token.go → kefu_go_robot/mimc_token.go
im/robot.go → kefu_go_robot/robot.go
kefu_server.sql → kefu_server_backup.sql
task/app.go
controllers/message_controller.go
View file @
9e9a2058
...
...
@@ -4,16 +4,16 @@ import (
"encoding/base64"
"encoding/json"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/validation"
"kefu_server/configs"
"kefu_server/im"
"kefu_server/models"
robotlbrary
"kefu_server/robot"
"kefu_server/services"
"kefu_server/utils"
"strconv"
"time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/validation"
)
// MessageController struct
...
...
@@ -67,8 +67,8 @@ func (c *MessageController) List() {
}
// push notify update current service contacts list
if
len
(
im
.
Robots
)
>
0
{
im
.
PushNewContacts
(
auth
.
UID
,
im
.
Robots
[
0
])
if
len
(
robotlbrary
.
Robots
)
>
0
{
robotlbrary
.
PushNewContacts
(
auth
.
UID
,
robotlbrary
.
Robots
[
0
])
}
c
.
JSON
(
configs
.
ResponseSucess
,
"success"
,
&
returnMessagePaginationDto
)
...
...
@@ -126,7 +126,7 @@ func (c *MessageController) Transfer() {
}
}
robot
:=
im
.
Robots
[
0
]
robot
:=
robotlbrary
.
Robots
[
0
]
robotID
,
_
:=
strconv
.
ParseInt
(
robot
.
AppAccount
(),
10
,
64
)
type
adminData
struct
{
...
...
controllers/public_controller.go
View file @
9e9a2058
...
...
@@ -4,8 +4,8 @@ import (
"encoding/base64"
"encoding/json"
"kefu_server/configs"
"kefu_server/im"
"kefu_server/models"
robotlbrary
"kefu_server/robot"
"kefu_server/services"
"kefu_server/utils"
"os"
...
...
@@ -100,7 +100,7 @@ func (c *PublicController) Register() {
if
user
!=
nil
{
// fetchResult
fetchResult
,
fetchError
=
im
.
GetMiMcToken
(
strconv
.
FormatInt
(
user
.
ID
,
10
))
fetchResult
,
fetchError
=
robotlbrary
.
GetMiMcToken
(
strconv
.
FormatInt
(
user
.
ID
,
10
))
if
err
:=
json
.
Unmarshal
([]
byte
(
fetchResult
),
&
imTokenDto
);
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"注册失败!"
,
&
err
)
}
...
...
@@ -126,7 +126,7 @@ func (c *PublicController) Register() {
if
accountID
,
err
:=
c
.
UserRepository
.
Add
(
user
);
err
==
nil
{
fetchResult
,
fetchError
=
im
.
GetMiMcToken
(
strconv
.
FormatInt
(
accountID
,
10
))
fetchResult
,
fetchError
=
robotlbrary
.
GetMiMcToken
(
strconv
.
FormatInt
(
accountID
,
10
))
if
err
:=
json
.
Unmarshal
([]
byte
(
fetchResult
),
&
imTokenDto
);
err
!=
nil
{
c
.
JSON
(
configs
.
ResponseFail
,
"注册失败!"
,
&
err
)
}
...
...
@@ -149,7 +149,7 @@ func (c *PublicController) Register() {
admin
=
c
.
AdminRepository
.
GetAdmin
(
auth
.
UID
)
// fetchResult
fetchResult
,
fetchError
=
im
.
GetMiMcToken
(
strconv
.
FormatInt
(
admin
.
ID
,
10
))
fetchResult
,
fetchError
=
robotlbrary
.
GetMiMcToken
(
strconv
.
FormatInt
(
admin
.
ID
,
10
))
// imTokenDto
if
err
:=
json
.
Unmarshal
([]
byte
(
fetchResult
),
&
imTokenDto
);
err
!=
nil
{
...
...
controllers/robot_controller.go
View file @
9e9a2058
...
...
@@ -7,8 +7,8 @@ import (
"github.com/astaxie/beego/validation"
"kefu_server/configs"
"kefu_server/im"
"kefu_server/models"
robotlbrary
"kefu_server/robot"
"kefu_server/services"
"strconv"
"strings"
...
...
@@ -81,7 +81,7 @@ func (c *RobotController) Delete() {
}
// init robots
im
.
RobotInit
()
robotlbrary
.
RobotInit
()
c
.
JSON
(
configs
.
ResponseSucess
,
"删除成功!"
,
nil
)
}
...
...
@@ -134,7 +134,7 @@ func (c *RobotController) Post() {
c
.
JSON
(
configs
.
ResponseFail
,
"添加失败!"
,
nil
)
}
im
.
RobotInit
()
robotlbrary
.
RobotInit
()
c
.
JSON
(
configs
.
ResponseSucess
,
"添加成功!"
,
id
)
}
...
...
@@ -217,7 +217,7 @@ func (c *RobotController) Put() {
robot
.
Artificial
=
strings
.
Trim
(
robot
.
Artificial
,
"|"
)
robot
.
KeyWord
=
strings
.
Trim
(
robot
.
KeyWord
,
"|"
)
robot
.
CreateAt
=
oldRobot
.
CreateAt
im
.
RobotInit
()
robotlbrary
.
RobotInit
()
c
.
JSON
(
configs
.
ResponseSucess
,
"修改成功!"
,
&
robot
)
}
...
...
im
/handler_contacts.go
→
kefu_go_robot
/handler_contacts.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"encoding/base64"
...
...
im
/handler_message.go
→
kefu_go_robot
/handler_message.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"container/list"
...
...
@@ -26,12 +26,31 @@ func (c MsgHandler) HandleMessage(packets *list.List) {
// 收到的原始消息
p2pMsg
:=
ele
.
Value
.
(
*
msg
.
P2PMessage
)
//
取出用户发的消息内容
//
get message
var
message
models
.
Message
msgContent
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
string
(
p2pMsg
.
Payload
()))
//logs.Info("收到消息", *p2pMsg.FromAccount(), *p2pMsg.ToAccount(), *p2pMsg.Timestamp(),*p2pMsg.PacketId(),*p2pMsg.Sequence())
_
=
json
.
Unmarshal
(
msgContent
,
&
message
)
msgContentByte
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
string
(
p2pMsg
.
Payload
()))
err
=
json
.
Unmarshal
(
msgContentByte
,
&
message
)
switch
message
.
BizType
{
// 消息入库
case
"into"
:
return
// 撤销消息
case
"cancel"
:
return
// 搜索知识库
case
"search_knowledge"
:
return
// 与机器人握手
case
"handshake"
:
return
default
:
}
if
err
==
nil
{
MessageP2P
(
message
)
}
}
...
...
im
/handler_status.go
→
kefu_go_robot
/handler_status.go
View file @
9e9a2058
package
im
package
robotlbrary
import
"github.com/astaxie/beego/logs"
...
...
im
/handler_token.go
→
kefu_go_robot
/handler_token.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"bytes"
...
...
kefu_go_robot/main.go
0 → 100644
View file @
9e9a2058
package
robotlbrary
func
main
()
{
// robot run
RobotInit
()
}
im
/message_p2p.go
→
kefu_go_robot
/message_p2p.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"encoding/base64"
...
...
@@ -61,15 +61,11 @@ func MessageP2P(message models.Message) {
break
}
}
if
isFromAccountRobot
{
return
}
// 判断机器人是否在线
if
robot
.
Status
()
==
1
{
robot
.
Login
()
}
// 是否是入库消息(中转入库)
if
message
.
BizType
==
"into"
{
var
intoMessage
models
.
Message
...
...
im
/mimc_token.go
→
kefu_go_robot
/mimc_token.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"bytes"
...
...
im
/robot.go
→
kefu_go_robot
/robot.go
View file @
9e9a2058
package
im
package
robotlbrary
import
(
"kefu_server/models"
...
...
kefu_server.sql
→
kefu_server
_backup
.sql
View file @
9e9a2058
File moved
task/app.go
View file @
9e9a2058
...
...
@@ -3,7 +3,7 @@ package task
import
(
"encoding/base64"
"encoding/json"
"kefu_server/
im
"
"kefu_server/
robot
"
"kefu_server/models"
"kefu_server/utils"
"strconv"
...
...
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