Commit 8cf2aff0 authored by clone's avatar clone

chat build

parent 19ca4f31
......@@ -12,10 +12,5 @@ class ErrorCodeConst
{
//聊天
const ERROR_CODE_PARAM_NOT_EXIST = 110001;
const ERROR_CODE_NOT_FRIENDS = 170002;
const ERROR_CODE_ALREADY_FRIENDS = 170003;
const ERROR_CODE_REMARK_TOO_LONG = 170004;
const ERROR_CODE_PARAM_ILLEGAL = 170005;
const ERROR_CODE_MSG_NOT_EXIST = 170006;
const ERROR_CODE_IS_NOT_ONLINE = 170007;
const ERROR_CODE_TARGET_TYPE_ERROR = 110002;
}
\ No newline at end of file
......@@ -69,12 +69,12 @@ class AppChat extends Basic
public function userChat()
{
/* $params = array(
"user_id" => 2,
"mobile" => "18205625020",
"user_id" => 1,
"mobile" => "15720682761",
"source" => 2 //1经纪人 2用户
);*/
$params = $this->params;
$params = $this->params;
if (!isset($params['user_id']) || !isset($params['mobile']) || !isset($params['source'])) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
......@@ -90,24 +90,45 @@ class AppChat extends Basic
} else {
return $this->response("101", $only_arr["msg"]);
}
}
/**
* c端根据经纪人的手机号获取唯一id
* @return \think\Response
*/
public function getAgentOnlyId()
{
//todo
return $this->response("200", "success", "");
}
/**
* 发送消息接口
* @return \think\Response
*/
public function pushMsg()
{
$params = $this->params;
$params = $this->params;
if (!isset($params['target_type']) || !isset($params['target']) || !isset($params['type']) || !isset($params['msg_content'])
|| !isset($params['source']) || !isset($params['is_user']) || !isset($params['from'])) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
}
$target_type = $params['target_type']; // 消息类型 users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
$target = $params['target']; //发送人 if target_type 群 者表示群id
$type = $params['type']; //消息类型 1文字 2图片
$target = $params['target']; //接受人 if target_type 群 者表示群id
$source = $params['source']; //消息来源 1c端app 2b端app 3其他
$is_user = $params['is_user']; //发送人是否是会员 0是1经济人
$type = $params['type']; //消息类型 1文字 2图片 3楼盘
$msg_content = $params['msg_content'];
$from = $params['from']; //消息发送人
if (!$target_type || !$target || !$type || !$msg_content || !$from) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
if ($target_type != "users" && $target_type != "chatgroups" && $target_type != "chatrooms") {
return $this->response(ErrorCodeConst::ERROR_CODE_TARGET_TYPE_ERROR, "错误的消息类型");
}
$result = $this->_chat->sendMsg($target_type, $target, $type, $msg_content, $from, $this->accessToken);
$result = $this->_chat->sendMsg($target_type, $target, $source, $is_user, $type, $msg_content, $from, $this->accessToken);
if (count($result) > 0) {
return $this->response("200", [ "msg" => "消息发送成功" ]);
}
......
......@@ -29,7 +29,7 @@ class ChatService
const MSG_TYPE_CHAT_GROUPS = "chatgroups"; //给群发消息
const MSG_TYPE_CHAT_CHAT_ROOMS = "chatrooms"; //给聊天室发消息
const SOURCE_TYPE_APP = 'app_'; // 用户 c端
const SOURCE_TYPE_APP = 'user_'; // 用户 c端
const SOURCE_TYPE_AGENT = 'agent_';//经纪人 b端
......@@ -125,29 +125,18 @@ class ChatService
* 发送消息
* @param $target_type
* @param $target
* @param $source
* @param $is_user
* @param $type
* @param $msg_content
* @param $from
* @param $accessToken
* @return bool
*/
public function sendMsg($target_type, $target, $type, $msg_content, $from, $accessToken)
public function sendMsg($target_type, $target,$source,$is_user, $type, $msg_content, $from, $accessToken)
{
switch ($target_type) {
case self::MSG_TYPE_USERS:
//todo 判断用户是否存在
break;
case self::MSG_TYPE_CHAT_GROUPS:
//todo 判断组群是否存在
break;
case self::MSG_TYPE_CHAT_CHAT_ROOMS:
//todo 判断聊天室是否存在
break;
default:
return [ "code" => 101, "msg" => "消息类型错误" ];
}
//todo
$this->insertMsg();
$this->insertMsg($target_type, $target,$source,$is_user, $type, $msg_content, $from);
$rPush = new RPush();
$rPush->send($target_type, $target, $type, $msg_content, $from, $accessToken, [ $this, 'saveSendStatus' ]);
//返回消息发送成功
......@@ -171,17 +160,27 @@ class ChatService
/**
* 保存用户发送的消息
* @param $sender
* @param $receiver
* @param $group_id
* @param $msg_content
* @param $target_type
* @param $target
* @param $source
* @param $is_user
* @param $type
* @param $msg_filename
* @param $msg_file_url
* @param $msg_content
* @param $from
*/
private function insertMsg($sender, $receiver, $group_id, $msg_content, $type, $msg_filename, $msg_file_url)
private function insertMsg($target_type, $target,$source,$is_user, $type, $msg_content, $from)
{
//todo
$params["msg_type"] = 1; //目前只用到了环信的文本消息
$params["to_id"] = $target;
$params["from_id"] = $from;
$params["is_group"] = $target_type == "users" ? 0 : 1;
$params["account_type"] = date("Y-m-d H:i:s", time());
$params["source"] = $source;
$params["is_user"] = $is_user;
$params["created_at"] = date("Y-m-d H:i:s", time());
$params["updated_at"] = date("Y-m-d H:i:s", time());
$this->chatUserModel->addChatUser($params);
}
/** 获取聊天记录
......
......@@ -52,7 +52,6 @@ class RPush
'msg' => [ "type" => $type, "msg" => $msg_content ],
'from' => $from,
);
$data = json_encode($arr);
$curl = new \app\chat\utils\CurlUtil();
......
......@@ -30,7 +30,6 @@ class RegisterUtil
'username' => $username,
'password' => $password,
);
$data = json_encode($arr);
$curl = new CurlUtil();
......
......@@ -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 1516264437 rememberMe deleteMe
a1.easemob.com FALSE / FALSE 1516352505 rememberMe deleteMe
......@@ -141,6 +141,7 @@ Route::group('api', [
Route::group('chat', [
'index' => [ 'chat/AppChat/index', [ 'method' => 'get' ] ],
'userChat' => [ 'chat/AppChat/userChat', [ 'method' => 'post|get' ] ],
'sendMsg' => [ 'chat/AppChat/sendMsg', [ 'method' => 'post|get' ] ],
]);
Route::group('task',[
......
......@@ -206,3 +206,42 @@ response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>18756258888</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>7572</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=1566AAB75F25B6DD28A4902FA26AEC0F
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>18756259999</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>3479</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=DE9865EE495BD9B0D85EDAF249CDA24F
response body = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>160053</statusCode>
<statusMsg>IP鉴权失败</statusMsg>
</Response>
request body = <TemplateSMS>
<to>18756257777</to>
<appId>8a216da85f5c89b1015f7718e2b90a63</appId>
<templateId>214759</templateId>
<datas><data>7094</data><data>5分钟</data></datas>
</TemplateSMS>
request url = https://app.cloopen.com:8883/2013-12-26/Accounts/8a48b55153eae51101540e763d3b3888/SMS/TemplateSMS?sig=7977CEC21F534DD1E5D675D792595DC9
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