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
b3a62841
Commit
b3a62841
authored
Jan 15, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chat
parent
abbeba2e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
76 deletions
+100
-76
AppChat.php
application/chat/controller/AppChat.php
+24
-59
ChatService.php
application/chat/service/ChatService.php
+56
-12
RPush.php
application/chat/utils/RPush.php
+20
-5
No files found.
application/chat/controller/AppChat.php
View file @
b3a62841
...
@@ -75,78 +75,43 @@ class AppChat extends Basic
...
@@ -75,78 +75,43 @@ class AppChat extends Basic
public
function
userChat
()
public
function
userChat
()
{
{
$params
=
array
(
$params
=
array
(
"user
I
d"
=>
1
,
"user
_i
d"
=>
1
,
"mobile"
=>
"13817616471"
,
"mobile"
=>
"13817616471"
,
"source"
=>
1
//1经纪人 2用户
"source"
=>
1
//1经纪人 2用户
);
);
//$params = $this->params;
//$params = $this->params;
$user
I
d
=
$params
[
'sender'
];
$user
_i
d
=
$params
[
'sender'
];
$mobile
=
$params
[
'receiver'
];
$mobile
=
$params
[
'receiver'
];
$source
=
$params
[
'msg_type'
];
$source
=
$params
[
'msg_type'
];
if
(
!
$user
I
d
||
!
$mobile
||
!
$source
)
{
if
(
!
$user
_i
d
||
!
$mobile
||
!
$source
)
{
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
"请求参数错误"
);
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
"请求参数错误"
);
}
}
$onlyId
=
$this
->
_chat
->
createOnlyId
(
$user
I
d
,
$mobile
,
$source
);
$onlyId
=
$this
->
_chat
->
createOnlyId
(
$user
_i
d
,
$mobile
,
$source
);
return
$this
->
response
(
"200"
,
array
(
"onlyId"
=>
$onlyId
));
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
))
{
public
function
pushMsg
()
throw
new
CHTTPException
(
ErrorCodeConsts
::
ERROR_CODE_NOT_FRIENDS
);
{
$params
=
$this
->
params
;
$target_type
=
$params
[
'target_type'
];
// 消息类型 users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
$target
=
$params
[
'target'
];
//发送人 if target_type 群 者表示群id
$type
=
$params
[
'type'
];
//消息类型 1文字 2图片
$msg_content
=
$params
[
'msg_content'
];
$from
=
$params
[
'from'
];
//消息发送人
if
(
!
$target_type
||
!
$target
||
!
$type
||
!
$msg_content
||
!
$from
)
{
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
"请求参数错误"
);
}
}
$result
=
$this
->
_chat
->
sendMsg
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$this
->
accessToken
);
$result
=
$this
->
_queue
->
msgSend
(
$this
->
request
->
getHttpHost
()
.
'/chat/receiveMsg'
,
[
if
(
count
(
$result
)
>
0
)
{
'sender'
=>
$sender
,
return
$this
->
response
(
"200"
,[
"msg"
=>
"消息发送成功"
]);
'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/service/ChatService.php
View file @
b3a62841
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
app\chat\service
;
namespace
app\chat\service
;
use
app\chat\utils\RPush
;
use
app\model\Agents
;
use
app\model\Agents
;
use
app\model\Users
;
use
app\model\Users
;
...
@@ -14,6 +15,10 @@ class ChatService
...
@@ -14,6 +15,10 @@ class ChatService
const
MSG_CONTENT_TYPE_VOICE
=
2
;
//语音
const
MSG_CONTENT_TYPE_VOICE
=
2
;
//语音
const
MSG_CONTENT_TYPE_VIDEO
=
3
;
//视频
const
MSG_CONTENT_TYPE_VIDEO
=
3
;
//视频
const
MSG_TYPE_USERS
=
"users"
;
//给用户发消息
const
MSG_TYPE_CHAT_GROUPS
=
"chatgroups"
;
//给群发消息
const
MSG_TYPE_CHAT_CHAT_ROOMS
=
"chatrooms"
;
//给聊天室发消息
const
SOURCE_TYPE_APP
=
'app_'
;
// 用户 c端
const
SOURCE_TYPE_APP
=
'app_'
;
// 用户 c端
const
SOURCE_TYPE_AGENT
=
'agent_'
;
//经纪人 b端
const
SOURCE_TYPE_AGENT
=
'agent_'
;
//经纪人 b端
...
@@ -49,40 +54,62 @@ class ChatService
...
@@ -49,40 +54,62 @@ class ChatService
if
(
count
(
$userResult
)
>
1
)
if
(
count
(
$userResult
)
>
1
)
$onlyId
=
self
::
SOURCE_TYPE_APP
.
$userId
;
$onlyId
=
self
::
SOURCE_TYPE_APP
.
$userId
;
break
;
break
;
default
:
}
return
array
(
"code"
=>
101
,
"msg"
=>
"没找到用户信息"
);
if
(
!
$onlyId
)
{
return
array
(
"code"
=>
101
,
"msg"
=>
"没找到用户信息"
);
}
}
return
$onlyId
;
return
$onlyId
;
}
}
/**
/**
* 发送消息
* 发送消息
* @param $
sender_id
* @param $
target_type
* @param $
receiver_ids
* @param $
target
* @param $
group_id
* @param $
type
* @param $msg_content
* @param $msg_content
* @param $
msg_type
* @param $
from
* @param $
msg_filename
* @param $
accessToken
* @
param $msg_file_ur
l
* @
return boo
l
*/
*/
public
function
sendMsg
(
$
sender_id
,
$receiver_ids
,
$group_id
,
$msg_content
,
$msg_type
,
$msg_filename
,
$msg_file_url
)
public
function
sendMsg
(
$
target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$accessToken
)
{
{
switch
(
$target_type
)
{
case
self
::
MSG_TYPE_USERS
:
//todo 判断用户是否存在
break
;
case
self
::
MSG_TYPE_CHAT_GROUPS
:
//todo 判断组群是否存在
break
;
case
self
::
MSG_TYPE_CHAT_CHAT_ROOMS
:
//todo 判断聊天室是否存在
break
;
default
:
return
[
"code"
=>
101
,
"msg"
=>
"消息类型错误"
];
}
//todo
//todo
$this
->
insertMsg
();
$this
->
insertMsg
();
$rPush
=
new
RPush
();
$rPush
->
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$accessToken
,[
$this
,
'saveSendStatus'
]);
//返回消息发送成功
return
true
;
}
}
/**
/**
* 保存推送到环信的消息状态 往msg_status中插入数据
* 保存推送到环信的消息状态 往msg_status中插入数据
* @param $response
* @param $response
* @param $t
mp
* @param $t
arget
* @param $sender
* @param $sender
* @param $msg_content
* @param $msg_content
*/
*/
public
function
saveSendStatus
(
$response
,
$t
mp
,
$sender
,
$msg_content
)
public
function
saveSendStatus
(
$response
,
$t
arget
,
$sender
,
$msg_content
)
{
{
//todo
$response
=
json_decode
(
$response
,
true
);
$response
[
'time'
]
=
date
(
'Y-m-d H:i:s'
);
$status
=
$response
[
'statusCode'
]
==
RPush
::
PUSH_STATUS_SUCCESS
?
MsgStatus
::
STATUS_SUCCESS
:
MsgStatus
::
STATUS_FAILURE
;
$this
->
insertPushLog
(
$sender
,
$target
,
$msg_content
,
$status
,
$response
[
'statusMsg'
]);
}
}
/**
/**
...
@@ -112,5 +139,21 @@ class ChatService
...
@@ -112,5 +139,21 @@ class ChatService
//todo
//todo
}
}
/**
* 往chat_msg_status中插入数据,记录推送的状态
* @param $sender
* @param $target
* @param $content
* @param $status
* @param $error_reason
* @return bool
*/
public
function
insertPushLog
(
$sender
,
$target
,
$content
,
$status
,
$error_reason
)
{
//todo
return
true
;
}
}
}
\ No newline at end of file
application/chat/utils/RPush.php
View file @
b3a62841
<?php
<?php
namespace
app\chat\utils
;
use
app\chat\consts\ConfigConst
;
/**
/**
...
@@ -11,12 +14,23 @@
...
@@ -11,12 +14,23 @@
class
RPush
class
RPush
{
{
/**
* 发送消息
* @param $target_type
* @param $target
* @param $type
* @param $msg_content
* @param $from
* @param $access_token
* @param $callback
*/
public
function
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
,
$callback
)
public
function
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
,
$callback
)
{
{
//todo 这里做算法优化,环信接口有限制,每个时间段最多能推送多少请求
$response
=
$this
->
sendRequestByCurl
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
);
$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
]);
call_user_func_array
([
$callback
[
0
],
$callback
[
1
]
],
[
$response
,
$target
,
$from
,
$msg_content
]);
}
}
...
@@ -28,7 +42,7 @@ class RPush
...
@@ -28,7 +42,7 @@ class RPush
* @param $msg_content
* @param $msg_content
* @param $from
* @param $from
* @param $access_token
* @param $access_token
* @return
$this
* @return
\app\chat\utils\CurlResponse|bool
*/
*/
public
function
sendRequestByCurl
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
)
public
function
sendRequestByCurl
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$access_token
)
{
{
...
@@ -57,11 +71,11 @@ class RPush
...
@@ -57,11 +71,11 @@ class RPush
}
}
/**
/**
* 请求api
* @return string
* @return string
*/
*/
private
function
buildSendUrl
()
private
function
buildSendUrl
()
{
{
return
$this
->
base_url
.
'/Accounts/'
.
$this
->
account_sid
.
return
ConfigConst
::
API_PATH
.
ConfigConst
::
ORG_NAME
.
"/"
.
ConfigConst
::
APP_NAME
;
'/IM/PushMsg?sig='
.
$this
->
main_sig
;
}
}
}
}
\ No newline at end of file
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