Commit fa4b714b authored by zw's avatar zw

liaotian

parent 51874410
...@@ -172,16 +172,19 @@ class ChatService ...@@ -172,16 +172,19 @@ class ChatService
* @param $from * @param $from
* @param $accessToken * @param $accessToken
* @return bool * @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) public function sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from, $accessToken)
{ {
//todo 判断是否创建关系没有则保存 // 判断是否创建关系没有则保存
$this->verifyRelation($target, $from); $this->verifyRelation($target, $from);
$this->insertMsg($target_type, $target, $source, $is_user, $type, $msg_content, $from); $this->insertMsg($target_type, $target, $source, $is_user, $type, $msg_content, $from);
$rPush = new RPush(); $rPush = new RPush();
//todo 消息接收人必须是数据 // 消息接收人必须是数组
$rPush->send($user_name, $target_type, [ $target ], $msg_content, $from, $type, $accessToken, [ $this, 'saveSendStatus' ]); $rPush->send($user_name, $target_type, [ $target ], $msg_content, $from, $type, $accessToken, [ $this, 'saveSendStatus' ]);
return true; return true;
} }
...@@ -321,9 +324,14 @@ class ChatService ...@@ -321,9 +324,14 @@ class ChatService
} }
/** /**
* 建立聊天关系
* @param $target * @param $target
* @param $from * @param $from
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
private function verifyRelation($target, $from) private function verifyRelation($target, $from)
{ {
......
...@@ -28,23 +28,23 @@ class RPush ...@@ -28,23 +28,23 @@ class RPush
* @param $access_token * @param $access_token
* @param $callback * @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 //todo
if(Cache::get('save_message_num')){ if (Cache::get('save_message_num')) {
$save_message_num=Cache::get('save_message_num'); $save_message_num = Cache::get('save_message_num');
if($save_message_num>10){ if ($save_message_num > 10) {
sleep(1); sleep(1);
Cache::set('save_message_num', 0); Cache::set('save_message_num', 0);
}else{ } else {
$save_message_num=$save_message_num+1; $save_message_num = $save_message_num + 1;
Cache::set('save_message_num', $save_message_num); Cache::set('save_message_num', $save_message_num);
} }
}else{ } else {
Cache::set('save_message_num', 0); 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 ]); call_user_func_array([ $callback[0], $callback[1] ], [ $response, $target, $from, $msg_content ]);
...@@ -55,27 +55,30 @@ class RPush ...@@ -55,27 +55,30 @@ class RPush
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息 * @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名, * @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid * 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content * @param $msg_content
* @param $from * @param $from
* @param $type * @param $type //目前只有文本的消息
* @param $access_token * @param $access_token
* @return \app\chat\utils\CurlResponse|bool * @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( $arr = array(
'target_type' => $target_type, 'target_type' => $target_type,
'target' => $target,//[1,2,3] 'target' => $target,//[1,2,3]
'msg' => [ "type" => "txt", "msg" => $msg_content ], 'msg' => [ "type" => "txt", "msg" => $msg_content ],
'from' => $from, 'from' => $from,
'ext' => [ "msg_type" => $type ,"user_name"=>$user_name] '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 = new \app\chat\utils\CurlUtil();
$curl->headers = [ $curl->headers = [
"Accept" => "application/json", "Accept" => "application/json",
"Content-Type" => "application/json;charset=utf-8", "Content-Type" => "application/json;charset=utf-8",
'Authorization' => "Bearer " . $access_token, 'Authorization' => "Bearer " . $access_token,
]; ];
$curl->options = [ $curl->options = [
...@@ -84,7 +87,7 @@ class RPush ...@@ -84,7 +87,7 @@ class RPush
]; ];
$url = $this->buildSendUrl(); $url = $this->buildSendUrl();
$response = $curl->post($url, $data); $response = $curl->post($url, $data);
Log::record('info -------------' . json_encode($response), "info"); Log::record('info -------------' . json_encode($response), "info");*/
return $response; return $response;
} }
......
...@@ -29,6 +29,9 @@ class ChatRelation extends Model ...@@ -29,6 +29,9 @@ class ChatRelation extends Model
* @param $params * @param $params
* @param string $field * @param string $field
* @return false|\PDOStatement|string|\think\Collection * @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") public function getChatRelation($params, $field = "id,to_id,from_id")
{ {
......
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