Commit abbeba2e authored by clone's avatar clone

聊天

parent 217213b8
......@@ -93,4 +93,60 @@ class AppChat extends Basic
return $this->response("200", array( "onlyId" => $onlyId ));
}
public function pushMsg(){
$params = $this->params;
$sender = $params['sender'];//发送者帐号
$receiver = $params['receiver'];//接收者帐号
$msg_type = $params['msg_type'];//这个用我们自己的类型不用容联的 1文本 2图片 3,系统消息 4推送消息
$msg_content = $params['msg_content'];//文本内容
$msg_filename = $params['msg_filename'];//文件名
$msg_file_url = $params['msg_fileurl'];//文件绝对路径
$site_id = $params['site_id'];
$group_id = $params['group_id'];//用户组id
$lng = $params['lng'];//113;//经度
$lat = $params['lat'];//31;//纬度
$source = $params['source'];
$this->_log->info(sprintf("%s::%s,request[%s]",__CLASS__, __FUNCTION__, json_encode($this->request->getJsonRawBody(true))));
if (!$sender || !$msg_type || !$site_id || !isset($lng) || !isset($lat)) {
throw new HTTPException(ErrorCodeConsts::ERROR_CODE_PARAM_NOT_EXIST);
}
if (!$this->_chat->getCanChat($sender, $receiver, $msg_type)) {
throw new CHTTPException(ErrorCodeConsts::ERROR_CODE_NOT_FRIENDS);
}
$result = $this->_queue->msgSend($this->request->getHttpHost() . '/chat/receiveMsg', [
'sender' => $sender,
'receiver' => $receiver,
'site_id' => $site_id,
'group_id' => $group_id,
'msg_type' => $msg_type,
'msg_content' => json_encode($msg_content),
'msg_filename' => $msg_filename,
'msg_file_url' => $msg_file_url,
'lng' => $lng,
'lat' => $lat,
'source' => $source,
]);
$this->_log->info(sprintf("%s::%s,msgSend---->[%s]",__CLASS__, __FUNCTION__, json_encode($result)));
if ($result) {
return array(
'statusMsg' => "success",
'statusCode' => "000000",
'time' => date("Y-m-d H:m:s", time()
)
);
} else {
return array(
'statusMsg' => "error",
'statusCode' => "170003",
'time' => date("Y-m-d H:m:s", time()
)
);
}
}
}
......@@ -11,37 +11,31 @@
class RPush
{
public function send($target_type, $target, $type, $msg_content, $from, $access_token, $callback)
{
$response = $this->sendRequestByCurl($target_type, $target, $type, $msg_content, $from, $access_token);
call_user_func_array([ $callback[0], $callback[1] ],
[ $response, $receivers_to_send, $sender, $msg_content ]);
}
/** curl参数拼凑
* @param $target_type
* @param $target
* @param $msg
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $from
* @param $accessToken
* @param $access_token
* @return $this
*/
public function sendRequestByCurl($target_type, $target, $msg, $from ,$accessToken)
public function sendRequestByCurl($target_type, $target, $type, $msg_content, $from, $access_token)
{
/**
* "msg" : {
* "type" : "txt",
* "msg" : "hello from rest" //消息内容,参考[[start:100serverintegration:30chatlog|聊天记录]]里的bodies内容
* },
* "msg" : { //消息内容
* "type" : "img", // 消息类型
* "url": "https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles/55f12940-64af-11e4-8a5b-ff2336f03252", //成功上传文件返回的UUID
* "filename": "24849.jpg", // 指定一个文件名
* "secret": "VfEpSmSvEeS7yU8dwa9rAQc-DIL2HhmpujTNfSTsrDt6eNb_", // 成功上传文件后返回的secret
* "size" : {
* "width" : 480,
* "height" : 720
* }
* },
*/
$arr = array(
'target_type' => $target_type,
'target' => $target,
'msg' => $msg,
'msg' => [ "type" => $type, "msg" => $msg_content ],
'from' => $from,
);
......@@ -51,7 +45,7 @@ class RPush
$curl->headers = [
"Accept" => "application/json",
"Content-Type" => "application/json;charset=utf-8",
'Authorization' => $accessToken,
'Authorization' => $access_token,
];
$curl->options = [
"CURLOPT_SSL_VERIFYPEER" => 0,
......
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