Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
f4c599f3
Commit
f4c599f3
authored
Nov 10, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
d4d3eba5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
60 deletions
+69
-60
im-center/app/base/controller/impl/msg/msghistoryCtl.js
+14
-14
im-center/app/base/db/impl/msg/msgnoticeDao.js
+1
-1
im-center/app/base/db/models/msg/msghistory.js
+2
-2
im-center/app/base/db/models/msg/msgnotice.js
+2
-2
im-center/app/config/routes/api.js
+0
-27
im-center/app/config/socket.server2.js
+50
-14
No files found.
im-center/app/base/controller/impl/msg/msghistoryCtl.js
View file @
f4c599f3
...
...
@@ -5,20 +5,20 @@ class MsgHistoryCtl extends CtlBase {
constructor
()
{
super
(
"msg"
,
CtlBase
.
getServiceName
(
MsgHistoryCtl
));
}
async
chanMsg
(
msg
)
{
const
from
=
msg
.
from
;
const
to
=
msg
.
to
;
const
msgContent
=
msg
.
content
;
var
msgH
=
{
toType
:
msg
.
type
?
msg
.
type
:
"single"
,
senderId
:
msg
.
from
,
sender
:
msg
.
nickNameForm
,
fromHeadUrl
:
msg
.
headUrlFrom
,
targetId
:
msg
.
to
,
target
:
msg
.
nickNameTo
,
toHeadUrl
:
msg
.
headUrlTo
,
content
:
msg
.
content
};
/**
*
* @param {'*'} uname
* @param {*} uid
* @param {*} compid
* @param {*} msg
*/
async
notifyClient
(
p
,
q
,
req
)
{
let
uname
=
p
.
uname
let
uid
=
p
.
uid
let
compid
=
p
.
compid
let
msg
=
p
.
msg
this
.
socketserver
.
notifyClient
(
uname
,
uid
,
compid
,
msg
)
return
{}
}
}
module
.
exports
=
MsgHistoryCtl
;
im-center/app/base/db/impl/msg/msgnoticeDao.js
View file @
f4c599f3
...
...
@@ -16,7 +16,7 @@ class MsgNoticeDao extends Dao {
let
smsgid2
=
{
lastMsgId
:
msg
.
id
};
return
await
super
.
updateByWhere
(
smsgid1
,
{
where
:
{
id
:
targetLaunch
.
id
}
},
t
);
}
else
{
notice
=
{
let
notice
=
{
sender
:
msg
.
sender
,
senderId
:
msg
.
senderId
,
target
:
msg
.
target
,
...
...
im-center/app/base/db/models/msg/msghistory.js
View file @
f4c599f3
...
...
@@ -11,10 +11,10 @@ module.exports = (db, DataTypes) => {
},
ctype
:
DataTypes
.
STRING
,
sender
:
DataTypes
.
STRING
,
senderId
:
DataTypes
.
INTEGER
,
senderId
:
DataTypes
.
STRING
,
fromHeadUrl
:
DataTypes
.
STRING
,
target
:
DataTypes
.
STRING
,
targetId
:
DataTypes
.
INTEGER
,
//租户ID
targetId
:
DataTypes
.
STRING
,
//租户ID
toHeadUrl
:
DataTypes
.
STRING
,
content
:
{
type
:
DataTypes
.
TEXT
(
'long'
),
...
...
im-center/app/base/db/models/msg/msgnotice.js
View file @
f4c599f3
...
...
@@ -3,10 +3,10 @@ const settings = require("../../../../config/settings");
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"msgnotice"
,
{
sender
:
DataTypes
.
STRING
,
//需要在后台补充
senderId
:
DataTypes
.
INTEGER
,
senderId
:
DataTypes
.
STRING
,
fromHeadUrl
:
DataTypes
.
STRING
,
target
:
DataTypes
.
STRING
,
//需要在后台补充
targetId
:
DataTypes
.
INTEGER
,
targetId
:
DataTypes
.
STRING
,
toHeadUrl
:
DataTypes
.
STRING
,
isAcceptedFrom
:
DataTypes
.
BOOLEAN
,
isAcceptedTo
:
DataTypes
.
BOOLEAN
,
...
...
im-center/app/config/routes/api.js
View file @
f4c599f3
...
...
@@ -3,33 +3,6 @@ var System = require("../../base/system");
const
settings
=
require
(
"../settings.js"
)
let
channelCache
=
{};
module
.
exports
=
function
(
app
)
{
app
.
post
(
"*"
,
async
function
(
req
,
res
,
next
)
{
console
.
log
(
"---- 进来了- ----"
)
try
{
let
channel
;
// let sourceHost = req.headers["x-forwarded-host"];
let
sourceHost
=
req
.
hostname
;
if
(
sourceHost
in
channelCache
)
{
channel
=
channelCache
[
sourceHost
];
}
else
{
channel
=
await
chnelapi
.
getChannels
(
sourceHost
);
channelCache
[
sourceHost
]
=
channel
;
}
if
(
!
channel
)
{
next
()
}
else
{
let
rtn
=
await
chnelapi
.
channelHandle
(
channel
,
req
.
path
+
"/"
+
req
.
body
.
actionType
,
req
.
body
)
if
(
rtn
!=
null
)
{
res
.
end
(
JSON
.
stringify
(
rtn
));
}
else
{
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
"fail"
}));
}
}
}
catch
(
e
)
{
console
.
log
(
e
)
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
e
}));
}
})
app
.
get
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
// var classPath = req.params["qname"];
var
methodName
=
req
.
params
[
"method"
];
...
...
im-center/app/config/socket.server2.js
View file @
f4c599f3
...
...
@@ -124,14 +124,6 @@ class MsgHandler {
this
.
client
=
client
;
this
.
init
();
}
notifyClient
(
ukchannel
,
msg
)
{
var
msgH
=
{
msgType
:
"system"
,
sender
:
"s¥s¥s¥s"
,
target
:
msg
.
to
,
content
:
msg
.
content
};
msgHistoryService
.
create
(
msgH
).
then
((
m
)
=>
{
redisClient
.
publish
(
ukchannel
,
JSON
.
stringify
(
msg
));
}).
catch
(
e
=>
{
console
.
log
(
e
);
});
}
init
()
{
var
self
=
this
;
//转发通信消息
...
...
@@ -148,7 +140,8 @@ class MsgHandler {
let
headUrlTo
=
self
.
server
.
uinfos
[
to
].
headUrl
let
companyid
=
self
.
server
.
uinfos
[
msg
.
fromUser
.
id
].
companyid
var
msgH
=
{
msgType
:
msg
.
type
?
msg
.
type
:
"single"
,
toType
:
msg
.
toType
?
msg
.
toType
:
"single"
,
ctype
:
msg
.
type
?
msg
.
type
:
"text"
,
senderId
:
msg
.
fromUser
.
id
,
sender
:
msg
.
fromUser
.
nickName
,
fromHeadUrl
:
msg
.
fromUser
.
headUrlFrom
,
...
...
@@ -160,10 +153,12 @@ class MsgHandler {
isAcceptedTo
:
msg
.
isAcceptedTo
?
msg
.
isAcceptedTo
:
false
,
company_id
:
companyid
};
msg
HistoryS
ervice
.
saveMsg
(
msgH
).
then
((
m
)
=>
{
msg
historyCtl
.
s
ervice
.
saveMsg
(
msgH
).
then
((
m
)
=>
{
redisClient
.
publish
(
to
,
JSON
.
stringify
(
msg
));
fn
({
status
:
0
})
}).
catch
(
e
=>
{
console
.
log
(
e
);
fn
({
status
:
-
1
})
});
//self.server.users[to].emit("chatmsg",msg);
});
...
...
@@ -182,6 +177,7 @@ class MsgHandler {
}).
then
(()
=>
{
console
.
log
(
"call success"
)
}).
catch
(
err
=>
{
fn
({
status
:
-
1
});
console
.
log
(
err
)
})
});
...
...
@@ -204,6 +200,38 @@ class SocketServer {
this
.
socketidMap
=
{}
//缓存会话ID与房间KEY
this
.
init
()
}
/**
* 系统平台通知
* @param {*} uname
* @param {*} uid
* @param {*} comid
* @param {*} msg
*/
notifyClient
(
uname
,
uid
,
comid
,
msg
)
{
const
to
=
this
.
buildUK
(
uname
,
uid
,
comid
);
let
nickNameTo
=
this
.
uinfos
[
to
].
nickName
let
headUrlTo
=
this
.
uinfos
[
to
].
headUrl
let
companyid
=
this
.
uinfos
[
to
].
companyid
var
msgH
=
{
toType
:
"sys"
,
ctype
:
msg
.
type
?
msg
.
type
:
"text"
,
senderId
:
"-2"
,
sender
:
"system"
,
fromHeadUrl
:
""
,
targetId
:
to
,
target
:
nickNameTo
,
toHeadUrl
:
headUrlTo
,
content
:
msg
.
content
,
isAcceptedFrom
:
msg
.
isAcceptedFrom
?
msg
.
isAcceptedFrom
:
false
,
isAcceptedTo
:
msg
.
isAcceptedTo
?
msg
.
isAcceptedTo
:
false
,
company_id
:
companyid
};
msghistoryCtl
.
service
.
saveMsg
(
msgH
).
then
((
m
)
=>
{
redisClient
.
publish
(
to
,
JSON
.
stringify
(
msg
));
}).
catch
(
e
=>
{
console
.
log
(
e
);
});
}
getUUID
()
{
var
uuid
=
uuidv4
();
var
u
=
uuid
.
replace
(
/
\-
/g
,
""
);
...
...
@@ -214,6 +242,17 @@ class SocketServer {
}
|
${
this
.
uinfos
[
ukencstr
].
nickName
}
|
${
this
.
uinfos
[
ukencstr
].
headUrl
}
|
${
ukencstr
}
`
return
onlineperson
}
/**
* 构建登录用户的私有key
* @param {} uname
* @param {*} uid
* @param {*} companyid
*/
buildUK
(
uname
,
uid
,
companyid
)
{
let
uk
=
uname
+
"_"
+
uid
+
"_"
+
companyid
let
ukencstr
=
system
.
encriptByDes
(
JSON
.
stringify
(
uk
))
return
ukencstr
}
init
()
{
var
self
=
this
;
//挂载到web应用的控制器,开放消息服务器的rest接口调用
...
...
@@ -239,11 +278,8 @@ class SocketServer {
nickName
:
nickName
,
headUrl
:
headUrl
}
// let str = system.encriptByDes(JSON.stringify(encuk))
//console.log('encstr', str)
let
uk
=
uname
+
"_"
+
id
+
"_"
+
d
.
company
.
id
//作为房间key
let
ukencstr
=
s
ystem
.
encriptByDes
(
JSON
.
stringify
(
uk
)
)
let
ukencstr
=
s
elf
.
buildUK
(
uname
,
id
,
d
.
company
.
id
)
encuk
.
uid
=
ukencstr
if
(
self
.
socketidMap
[
client
.
id
]
&&
d
.
company
.
id
!=
-
1
)
{
//可能匿名登录过
let
prevukstr
=
self
.
socketidMap
[
client
.
id
]
...
...
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