Commit df606d2e authored by hujun's avatar hujun

聊天

parent 20665918
......@@ -221,11 +221,11 @@ class ChatService
if (count($info) <= 0) {
return false;
}
$target = [];
$push_id = [];
foreach ($info as $item) {
array_push($target, $item["push_id"]);
array_push($push_id, $item["push_id"]);
}
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $accessToken, [ $this, 'saveSendStatus' ]);
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $accessToken, [ $this, 'saveSendStatus' ], $push_id);
return true;
}
......
......@@ -16,9 +16,9 @@ use think\Cache;
*/
class RPush
{
/**
* 发送消息
*
* @param $user_name
* @param $target_type
* @param $target
......@@ -28,8 +28,9 @@ class RPush
* @param $type
* @param $access_token
* @param $callback
* @param $push_id
*/
public function send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $callback)
public function send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $callback, $push_id)
{
//todo
if (Cache::get('save_message_num')) {
......@@ -45,34 +46,28 @@ class RPush
Cache::set('save_message_num', 0);
}
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token);
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $push_id);
call_user_func_array([ $callback[0], $callback[1] ], [ $response, $target, $from, $msg_content ]);
}
/**
* @param $user_name
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $target_type //users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target //注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $msg_content //目前只有文本的消息
* @param $from
* @param $is_user
* @param $type
* @param $access_token
* @param $push_id
* @return array
*/
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token)
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $push_id)
{
$title = "收到一条消息";
// $arr = array(
// 'target_type' => $target_type,
// 'target' => $target,
// 'msg' => [ "type" => "txt", "msg" => $msg_content ],
// 'from' => $from,
// 'ext' => [ "msg_type" => $type, "user_name" => $user_name ]
// );
$payload = json_encode(array(
'title' => $title,
......@@ -88,17 +83,15 @@ class RPush
'from' => $from,
"user_name" => $user_name,
'body' => $msg_content,
'to_id' => '',
'from_id' => '',
'to_id' => $target,
'from_id' => $from,
'created_at' => '2018-04-02 13:19:14'
]
));
$pushMessageToIgt = new GeTuiUtils();
$push_arr = $target;
return $pushMessageToIgt->pushMessageToIgt($push_arr, $title, $payload, $is_user);
return $pushMessageToIgt->pushMessageToIgt($push_id, $title, $payload, $is_user);
/* $curl = new \app\chat\utils\CurlUtil();
$curl->headers = [
"Accept" => "application/json",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment