Commit fdb008d5 authored by clone's avatar clone Committed by hujun

新增组群

parent ee74588a
......@@ -15,6 +15,7 @@ use app\chat\extend\Basic;
use app\chat\service\ChatService;
use app\chat\utils\RPush;
use app\extra\RedisPackage;
use app\model\ChatMsg;
use think\Cache;
use Think\Log;
......@@ -148,4 +149,38 @@ class AppChat extends Basic
}
/**
* 查询历史和搜索历史
* @return \think\Response
*/
public function getChatHistory()
{
$params = $this->params;
if (!isset($params['target_type']) || !isset($params['from']) || !isset($params['target'])) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
}
/* $params = array(
'target_type' => 'users', // 消息类型 users 用户消息。chatgroups: 群消息,chatrooms: 聊天室消息
'from' => 'app_64', //发送人
'target' => '18112347151', //接受人
'page_no' => '1', //第几页
'page_size' => '15' //每页多少条
);*/
$page_no = empty($params['page_no']) ? 1 : $params['page_no'];
$page_size = empty($params['page_size']) ? 15 : $params['page_size'];
$field = "a.id,a.to_id,a.from_id,a.created_at,b.type,b.body";
$msgModel = new ChatMsg();
$history_result = $msgModel->getChatHistory($params, $field, $page_no, $page_size);
if ($history_result) {
return $this->response("200", "request success", $history_result);
}
}
}
<?php
namespace app\chat\controller;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/23
* Time : 13:47
* Intro:
*/
use app\chat\extend\Basic;
class Group extends Basic
{
public function createGroupByOnlyId()
{
//todo 组群创建 1.存表,2调用环信接口
}
public function updateGroup()
{
//todo 修改组群信息 1.群信息完善到后台表 无需调用环信接口
}
public function delGroup()
{
//todo 删除群组 1.改变我们group表的状态2.调用环信删群接口
}
/**
* 群组管理
*/
public function getGroupUser()
{
//todo 获取群组成员/管理员 我们的数据库获取
}
public function addGroupUserByIds()
{
//todo 添加群组成员 1.单个/多个到表中,2.调用环信接口更新进去
}
public function delGroupUserByIds()
{
//todo 移除群组成员 1.单个或多个跟新到库, 2.调用环信接口更新
}
public function addGroupManage()
{
//todo 添加群组管理员 1.单个更新到库, 2.调用环信接口更新
}
public function delGroupManage()
{
//todo 移除群组管理员 1.单个更新到库, 2.调用环信接口更新
}
}
\ No newline at end of file
<?php
namespace app\chat\utils;
use app\chat\consts\ConfigConst;
......@@ -19,19 +20,19 @@ class RPush
* 发送消息
* @param $target_type
* @param $target
* @param $type
* @param $msg_content
* @param $from
* @param $type
* @param $access_token
* @param $callback
*/
public function send($target_type, $target, $type, $msg_content, $from, $access_token, $callback)
public function send($target_type, $target, $msg_content, $from, $type, $access_token, $callback)
{
//todo 这里做算法优化,环信接口有限制,每个时间段最多能推送多少请求
$response = $this->sendRequestByCurl($target_type, $target, $msg_content, $from, $access_token);
$response = $this->sendRequestByCurl($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 ]);
}
......@@ -42,32 +43,33 @@ class RPush
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $from
* @param $type
* @param $access_token
* @return \app\chat\utils\CurlResponse|bool
*/
public function sendRequestByCurl($target_type, $target, $msg_content, $from ,$access_token)
public function sendRequestByCurl($target_type, $target, $msg_content, $from, $type, $access_token)
{
$arr = array(
$arr = array(
'target_type' => $target_type,
'target' => $target,
'msg' => [ "type" => "txt", "msg" => $msg_content ],
'from' => $from,
'ext' => [ "msg_type" => $type ]
);
$data = json_encode($arr);
echo $data;echo "-------------";
$data = json_encode($arr);
$curl = new \app\chat\utils\CurlUtil();
$curl->headers = [
"Accept" => "application/json",
"Content-Type" => "application/json;charset=utf-8",
'Authorization' => "Bearer " . $access_token,
];
];
$curl->options = [
"CURLOPT_SSL_VERIFYPEER" => 0,
"CURLOPT_SSL_VERIFYHOST" => 2,
];
$url = $this->buildSendUrl();
$response = $curl->post($url, $data);
Log::record('info -------------', json_encode($response));
Log::record('info -------------' . json_encode($response), "info");
return $response;
}
......
......@@ -2,4 +2,4 @@
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
a1.easemob.com FALSE / FALSE 1516419232 rememberMe deleteMe
a1.easemob.com FALSE / FALSE 1516687414 rememberMe deleteMe
......@@ -38,4 +38,44 @@ class ChatMsg extends Model
return 0;
}
/**
* @param $params
* @param $field
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
*/
public function getChatHistory($params, $field, $page_no, $page_size)
{
if (isset($params["from"])) {
$where_["a.from_id"] = $params["from"];
$where_or["a.to_id"] = $params["from"];
}
if (isset($params["target"])) {
$where_["a.to_id"] = $params["target"];
$where_or["a.from_id"] = $params["target"];
}
if (isset($params["is_group"])) {
$where_["a.is_group"] = $params["is_group"];
}
if (isset($params["body"])) {
$where_["b.body"] = array( 'like', "%" . trim($params["body"]) . "%" );
}
$where_["a.is_del"] = 0;
$data = $this->field($field)
->alias("a")
->join('chat_msg_ext b', 'a.id = b.msg_id', 'LEFT')
->where($where_)
->whereOr(function ($query) use ($where_or) {
$query->where($where_or);
})
->order("a.created_at desc")
->limit($page_size)
->page($page_no)
->select();
return $data;
}
}
\ No newline at end of file
......@@ -284,3 +284,55 @@ response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>15032323232</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>4355</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=157B3CA0CF0C1D232FE6D6758A6F9E77
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>18756254444</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>8064</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=EA2BC31B5B5662AD292223DC686FA26D
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>18756253333</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>7687</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=00F01FFDBFD51AA503BB5585E4D2DC21
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>13112341234</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>8858</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=873B52C43862749A39926C652B5834DC
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
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