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
abbeba2e
Commit
abbeba2e
authored
Jan 11, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
聊天
parent
217213b8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
24 deletions
+74
-24
AppChat.php
application/chat/controller/AppChat.php
+56
-0
RPush.php
application/chat/utils/RPush.php
+18
-24
No files found.
application/chat/controller/AppChat.php
View file @
abbeba2e
...
...
@@ -93,4 +93,60 @@ class AppChat extends Basic
return
$this
->
response
(
"200"
,
array
(
"onlyId"
=>
$onlyId
));
}
public
function
pushMsg
(){
$params
=
$this
->
params
;
$sender
=
$params
[
'sender'
];
//发送者帐号
$receiver
=
$params
[
'receiver'
];
//接收者帐号
$msg_type
=
$params
[
'msg_type'
];
//这个用我们自己的类型不用容联的 1文本 2图片 3,系统消息 4推送消息
$msg_content
=
$params
[
'msg_content'
];
//文本内容
$msg_filename
=
$params
[
'msg_filename'
];
//文件名
$msg_file_url
=
$params
[
'msg_fileurl'
];
//文件绝对路径
$site_id
=
$params
[
'site_id'
];
$group_id
=
$params
[
'group_id'
];
//用户组id
$lng
=
$params
[
'lng'
];
//113;//经度
$lat
=
$params
[
'lat'
];
//31;//纬度
$source
=
$params
[
'source'
];
$this
->
_log
->
info
(
sprintf
(
"%s::%s,request[%s]"
,
__CLASS__
,
__FUNCTION__
,
json_encode
(
$this
->
request
->
getJsonRawBody
(
true
))));
if
(
!
$sender
||
!
$msg_type
||
!
$site_id
||
!
isset
(
$lng
)
||
!
isset
(
$lat
))
{
throw
new
HTTPException
(
ErrorCodeConsts
::
ERROR_CODE_PARAM_NOT_EXIST
);
}
if
(
!
$this
->
_chat
->
getCanChat
(
$sender
,
$receiver
,
$msg_type
))
{
throw
new
CHTTPException
(
ErrorCodeConsts
::
ERROR_CODE_NOT_FRIENDS
);
}
$result
=
$this
->
_queue
->
msgSend
(
$this
->
request
->
getHttpHost
()
.
'/chat/receiveMsg'
,
[
'sender'
=>
$sender
,
'receiver'
=>
$receiver
,
'site_id'
=>
$site_id
,
'group_id'
=>
$group_id
,
'msg_type'
=>
$msg_type
,
'msg_content'
=>
json_encode
(
$msg_content
),
'msg_filename'
=>
$msg_filename
,
'msg_file_url'
=>
$msg_file_url
,
'lng'
=>
$lng
,
'lat'
=>
$lat
,
'source'
=>
$source
,
]);
$this
->
_log
->
info
(
sprintf
(
"%s::%s,msgSend---->[%s]"
,
__CLASS__
,
__FUNCTION__
,
json_encode
(
$result
)));
if
(
$result
)
{
return
array
(
'statusMsg'
=>
"success"
,
'statusCode'
=>
"000000"
,
'time'
=>
date
(
"Y-m-d H:m:s"
,
time
()
)
);
}
else
{
return
array
(
'statusMsg'
=>
"error"
,
'statusCode'
=>
"170003"
,
'time'
=>
date
(
"Y-m-d H:m:s"
,
time
()
)
);
}
}
}
application/chat/utils/RPush.php
View file @
abbeba2e
...
...
@@ -11,37 +11,31 @@
class
RPush
{
public
function
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
,
$callback
)
{
$response
=
$this
->
sendRequestByCurl
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
);
call_user_func_array
([
$callback
[
0
],
$callback
[
1
]
],
[
$response
,
$receivers_to_send
,
$sender
,
$msg_content
]);
}
/** curl参数拼凑
* @param $target_type
* @param $target
* @param $msg
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $from
* @param $access
T
oken
* @param $access
_t
oken
* @return $this
*/
public
function
sendRequestByCurl
(
$target_type
,
$target
,
$
msg
,
$from
,
$accessT
oken
)
public
function
sendRequestByCurl
(
$target_type
,
$target
,
$
type
,
$msg_content
,
$from
,
$access_t
oken
)
{
/**
* "msg" : {
* "type" : "txt",
* "msg" : "hello from rest" //消息内容,参考[[start:100serverintegration:30chatlog|聊天记录]]里的bodies内容
* },
* "msg" : { //消息内容
* "type" : "img", // 消息类型
* "url": "https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles/55f12940-64af-11e4-8a5b-ff2336f03252", //成功上传文件返回的UUID
* "filename": "24849.jpg", // 指定一个文件名
* "secret": "VfEpSmSvEeS7yU8dwa9rAQc-DIL2HhmpujTNfSTsrDt6eNb_", // 成功上传文件后返回的secret
* "size" : {
* "width" : 480,
* "height" : 720
* }
* },
*/
$arr
=
array
(
'target_type'
=>
$target_type
,
'target'
=>
$target
,
'msg'
=>
$msg
,
'msg'
=>
[
"type"
=>
$type
,
"msg"
=>
$msg_content
]
,
'from'
=>
$from
,
);
...
...
@@ -51,7 +45,7 @@ class RPush
$curl
->
headers
=
[
"Accept"
=>
"application/json"
,
"Content-Type"
=>
"application/json;charset=utf-8"
,
'Authorization'
=>
$access
T
oken
,
'Authorization'
=>
$access
_t
oken
,
];
$curl
->
options
=
[
"CURLOPT_SSL_VERIFYPEER"
=>
0
,
...
...
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