Commit daf4b663 authored by hujun's avatar hujun

发送消息

parent 066176be
......@@ -187,7 +187,7 @@ class ChatService
* @param $target_type
* @param $target
* @param $source
* @param $is_user
* @param $user_type
* @param $type
* @param $msg_content
* @param $from
......@@ -197,12 +197,12 @@ class ChatService
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from)
public function sendMsg($user_name, $target_type, $target, $source, $user_type, $type, $msg_content, $from)
{
// 判断是否创建关系没有则保存
$this->verifyRelation($target, $from);
$msg_id = $this->insertMsg($target_type, $target, $source, $is_user, $type, $msg_content, $from);
$msg_id = $this->insertMsg($target_type, $target, $source, $user_type, $type, $msg_content, $from);
$rPush = new RPush();
$userExt = new ChatUserExt();
......@@ -214,19 +214,28 @@ class ChatService
$user_where['only_id'] = $from;
$user_where['only_id_or'] = $target;
$user_where['status'] = 0;
$user_arr = $m_user->getChatUserOne('user_id', $user_where);
$user_arr = $m_user->getChatUserOne('type,user_id,only_id', $user_where);
if (count($user_arr) < 2) {
return false;
}
$user_id = 0;
$where['type'] = 1;
$user_type = 1;
foreach ($user_arr as $item) {
if ($item["only_id"] == $from) {
$user_id = empty($user_arr['user_id']) ? 0 : $user_arr['user_id'];
} else {
$where['type'] = $item["type"];
}
if ($item['only_id'] == $target && $item['type'] == 1) {
$user_type = 1;
}
if ($item['only_id'] == $target && $item['type'] == 2) {
$user_type = 2;
}
}
$info = $userExt->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,b.user_id');
......@@ -237,7 +246,7 @@ class ChatService
foreach ($info as $item) {
array_push($push_id, $item["push_id"]);
}
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, [ $this, 'saveSendStatus' ], $push_id, $msg_id, $user_id);
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, [ $this, 'saveSendStatus' ], $push_id, $msg_id, $user_id);
return true;
}
......@@ -459,7 +468,7 @@ class ChatService
}
try {
$where_["id"] = array( "between", array( $relation_list[$item["id"]][0]["msg_id"], $chat_info[0]["id"] ) );
$where_["id"] = [ "between", [ $relation_list[$item["id"]][0]["msg_id"], $chat_info[0]["id"] ] ];
//计算未读消息个数
$unread_count = $msgModel->getTotalUnread($where_, "id");
//dump($unread_count);
......
......@@ -40,16 +40,16 @@ class GeTuiUtils
*/
public function setting($is)
{
if ($is) {
$this->igt_app_id = '1GnogURb3Y8cjQjmRtxXcA';
$this->igt_app_secret = 'qgCUSOcEQi52vRKQe6MYp8';
$this->igt_app_key = 'oQuYepflY8A7r0yGK9f9D4';
$this->igt_app_master_secret = 'numYAK4xpq8TEZHvaqeAT6';
} else {
if ($is == 1) {
$this->igt_app_id = 'A8raBWQxuX9bcVmk3rkWa5';
$this->igt_app_secret = 'TLNDlz8YsW6J4gexzb4AX3';
$this->igt_app_key = 'dEC3iu81ZC9XbsVLwoiHA6';
$this->igt_app_master_secret = '3NNdfsgjCJ6Rmfr9l0EeI1';
} else {
$this->igt_app_id = '1GnogURb3Y8cjQjmRtxXcA';
$this->igt_app_secret = 'qgCUSOcEQi52vRKQe6MYp8';
$this->igt_app_key = 'oQuYepflY8A7r0yGK9f9D4';
$this->igt_app_master_secret = 'numYAK4xpq8TEZHvaqeAT6';
}
}
......@@ -59,12 +59,12 @@ class GeTuiUtils
* @param $push_id
* @param $title
* @param $payload
* @param $is_user
* @param $user_type
* @return array
*/
public function pushMessageToIgt($push_id, $title, $payload, $is_user)
public function pushMessageToIgt($push_id, $title, $payload, $user_type)
{
$this->setting($is_user);
$this->setting($user_type);
$igt = new \IGeTui(self::IGT_HOST, $this->igt_app_key, $this->igt_app_master_secret);
......
......@@ -31,7 +31,7 @@ class RPush
* @param $msg_id
* @param $user_id
*/
public function send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $callback, $push_id, $msg_id, $user_id)
public function send($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, $callback, $push_id, $msg_id, $user_id)
{
//todo
if (Cache::get('save_message_num')) {
......@@ -47,7 +47,7 @@ class RPush
Cache::set('save_message_num', 0);
}
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $push_id, $msg_id, $user_id);
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, $push_id, $msg_id, $user_id);
call_user_func_array([ $callback[0], $callback[1] ], [ $response, $target, $from, $msg_content ]);
}
......@@ -59,14 +59,14 @@ class RPush
* 给群组发送时数组元素是groupid
* @param $msg_content //目前只有文本的消息
* @param $from
* @param $is_user
* @param $user_type
* @param $type
* @param $push_id
* @param $message_id
* @param $user_id
* @return array
*/
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $push_id, $message_id, $user_id)
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $user_type, $type, $push_id, $message_id, $user_id)
{
$title = "收到一条消息";
......@@ -95,7 +95,7 @@ class RPush
$pushMessageToIgt = new GeTuiUtils();
$result = $pushMessageToIgt->pushMessageToIgt($push_id, $title, $payload, $is_user);
$result = $pushMessageToIgt->pushMessageToIgt($push_id, $title, $payload, $user_type);
return $result;
}
......
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