Commit fa4b714b authored by zw's avatar zw

liaotian

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