Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
fa4b714b
Commit
fa4b714b
authored
Jul 07, 2018
by
zw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
liaotian
parent
51874410
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
21 deletions
+35
-21
ChatService.php
application/chat/service/ChatService.php
+10
-2
RPush.php
application/chat/utils/RPush.php
+22
-19
ChatRelation.php
application/model/ChatRelation.php
+3
-0
No files found.
application/chat/service/ChatService.php
View file @
fa4b714b
...
...
@@ -172,16 +172,19 @@ class ChatService
* @param $from
* @param $accessToken
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
sendMsg
(
$user_name
,
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
,
$accessToken
)
{
//
todo
判断是否创建关系没有则保存
// 判断是否创建关系没有则保存
$this
->
verifyRelation
(
$target
,
$from
);
$this
->
insertMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
);
$rPush
=
new
RPush
();
//
todo 消息接收人必须是数据
//
消息接收人必须是数组
$rPush
->
send
(
$user_name
,
$target_type
,
[
$target
],
$msg_content
,
$from
,
$type
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
return
true
;
}
...
...
@@ -321,9 +324,14 @@ class ChatService
}
/**
* 建立聊天关系
* @param $target
* @param $from
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private
function
verifyRelation
(
$target
,
$from
)
{
...
...
application/chat/utils/RPush.php
View file @
fa4b714b
...
...
@@ -28,23 +28,23 @@ class RPush
* @param $access_token
* @param $callback
*/
public
function
send
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
,
$callback
)
public
function
send
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
,
$callback
)
{
//todo
if
(
Cache
::
get
(
'save_message_num'
))
{
$save_message_num
=
Cache
::
get
(
'save_message_num'
);
if
(
$save_message_num
>
10
)
{
if
(
Cache
::
get
(
'save_message_num'
))
{
$save_message_num
=
Cache
::
get
(
'save_message_num'
);
if
(
$save_message_num
>
10
)
{
sleep
(
1
);
Cache
::
set
(
'save_message_num'
,
0
);
}
else
{
$save_message_num
=
$save_message_num
+
1
;
}
else
{
$save_message_num
=
$save_message_num
+
1
;
Cache
::
set
(
'save_message_num'
,
$save_message_num
);
}
}
else
{
}
else
{
Cache
::
set
(
'save_message_num'
,
0
);
}
$response
=
$this
->
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
);
$response
=
$this
->
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
);
call_user_func_array
([
$callback
[
0
],
$callback
[
1
]
],
[
$response
,
$target
,
$from
,
$msg_content
]);
...
...
@@ -55,27 +55,30 @@ class RPush
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $from
* @param $type
* @param $type
//目前只有文本的消息
* @param $access_token
* @return \app\chat\utils\CurlResponse|bool
*/
public
function
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
)
public
function
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
)
{
$arr
=
array
(
'target_type'
=>
$target_type
,
'target'
=>
$target
,
//[1,2,3]
'msg'
=>
[
"type"
=>
"txt"
,
"msg"
=>
$msg_content
],
'from'
=>
$from
,
'ext'
=>
[
"msg_type"
=>
$type
,
"user_name"
=>
$user_name
]
'target'
=>
$target
,
//[1,2,3]
'msg'
=>
[
"type"
=>
"txt"
,
"msg"
=>
$msg_content
],
'from'
=>
$from
,
'ext'
=>
[
"msg_type"
=>
$type
,
"user_name"
=>
$user_name
]
);
$data
=
json_encode
(
$arr
);
$response_
=
new
GeTuiUtils
();
$response_
->
pushMessageToIgt
();
/* $data = json_encode($arr);
$curl = new \app\chat\utils\CurlUtil();
$curl->headers = [
"Accept"
=>
"application/json"
,
"Content-Type"
=>
"application/json;charset=utf-8"
,
"Accept" => "application/json",
"Content-Type" => "application/json;charset=utf-8",
'Authorization' => "Bearer " . $access_token,
];
$curl->options = [
...
...
@@ -84,7 +87,7 @@ class RPush
];
$url = $this->buildSendUrl();
$response = $curl->post($url, $data);
Log
::
record
(
'info -------------'
.
json_encode
(
$response
),
"info"
);
Log::record('info -------------' . json_encode($response), "info");
*/
return
$response
;
}
...
...
application/model/ChatRelation.php
View file @
fa4b714b
...
...
@@ -29,6 +29,9 @@ class ChatRelation extends Model
* @param $params
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getChatRelation
(
$params
,
$field
=
"id,to_id,from_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