Commit 265d18c4 authored by clone's avatar clone Committed by hujun

消息发送成功失败存储 接口修改

parent 65cb1da5
......@@ -105,18 +105,15 @@ class AppChat extends Basic
{
$params = $this->params;
if (!isset($params['only_id']) || !isset($params['phone']) || !isset($params['source'])) {
if (!isset($params['only_id']) || !isset($params['source'])) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误");
}
/* $params = array(
"only_id" => "user_72,agent_10",
"phone" => "13112341234",
"source" => 2,// 1经纪人 or 2用户
);*/
$only_id = isset($params['only_id']) ? $params['only_id'] : 0;
$phone = isset($params['phone']) ? $params['phone'] : 0;
$result = $this->_chat->getUserInfo($only_id, $phone, $params["source"]);
$result = $this->_chat->getUserInfo($params['only_id'], $params["source"]);
if ($result) {
return $this->response("200", "request success", $result);
}
......@@ -131,21 +128,21 @@ class AppChat extends Basic
public function pushMsg()
{
$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, "请求参数错误");
}
/* $params = array(
'msg_content' => 'ceshi666',
'target_type' => 'users',
'source' => '1',
'from' => 'admin',
'type' => '1',
'is_user' => '0',
'target' => '18112347151',
);*/
/* $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, "请求参数错误");
}*/
$params = array(
'msg_content' => 'ceshi666',
'target_type' => 'users',
'source' => '1',
'from' => 'adminqwqw',
'type' => '1',
'is_user' => '0',
'target' => '18112347151',
);
$target_type = $params['target_type']; // 消息类型 users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
$target = $params['target']; //接受人 if target_type 群 者表示群id
$source = $params['source']; //消息来源 1c端app 2b端app 3其他
......
......@@ -15,6 +15,7 @@ use app\chat\utils\RPush;
use app\model\Agents;
use app\model\ChatMsg;
use app\model\ChatMsgExt;
use app\model\ChatMsgStatus;
use app\model\ChatUser;
use app\model\Users;
......@@ -172,25 +173,28 @@ class ChatService
*/
public function saveSendStatus($response, $target, $sender, $msg_content)
{
/* $response = json_decode($response, true);
$response['time'] = date('Y-m-d H:i:s');
$status = $response['statusCode'] == RPush::PUSH_STATUS_SUCCESS ? MsgStatus::STATUS_SUCCESS : MsgStatus::STATUS_FAILURE;
$this->insertPushLog($sender, $target, $msg_content, $status, $response['statusMsg']);*/
$response = json_decode($response, true);
//目前没有针对多人聊天
$status = isset($response["data"][$target[0]]) ? $response["data"][$target[0]] : "faild";
$error_reason = "";
if ($status != "success") {
$error_reason = "环信发送异常";
}
$this->insertPushLog($from, $target[0], $msg_content, $status, $error_reason);
}
/**
* 根据手机号或者onlyId获取用户信息
* @param $only_id
* @param $phone
* @param $type
* @param $type 之后扩展
* @return array|false|\PDOStatement|string|\think\Model
*
*/
public function getUserInfo($only_id, $phone, $type)
public function getUserInfo($only_id, $type)
{
$user_phone = $agent_phone = [];
$user_phone = $agent_phone = [];
$chat_user_arr = [];
if ($only_id) {
$only_id_arr = explode(",", $only_id);
$where_["only_id"] = array( "in", $only_id_arr );
......@@ -203,15 +207,10 @@ class ChatService
} else {
array_push($user_phone, $v["phone"]);
}
$chat_user_arr[$v["phone"]] = $v["only_id"];
}
} else {
if ($type == 1) {
$agent_phone = [ $phone ];
} else if ($type == 2) {
$user_phone = [ $phone ];
}
}
$info_arr = [];
......@@ -227,6 +226,8 @@ class ChatService
if ($v["user_pic"]) {
$v["user_pic"] = IMG_PATH . $v["user_pic"];
}
$v["only_id"] = $chat_user_arr [$v["user_phone"]];
array_push($info_arr, $v);
}
......@@ -243,6 +244,7 @@ class ChatService
if ($v["user_pic"]) {
$v["user_pic"] = HEADERIMGURL . $v["user_pic"];
}
$v["only_id"] = $chat_user_arr [$v["user_phone"]];
array_push($info_arr, $v);
}
}
......@@ -322,17 +324,24 @@ class ChatService
/**
* 往chat_msg_status中插入数据,记录推送的状态
* @param $sender
* @param $from
* @param $target
* @param $content
* @param $status
* @param $error_reason
* @return bool
*/
public function insertPushLog($sender, $target, $content, $status, $error_reason)
public function insertPushLog($from, $target, $content, $status, $error_reason)
{
//todo
$param["from"] = $from;
$param["target"] = $target;
$param["content"] = $content;
$param["status"] = $status;
$param["error_reason"] = $error_reason;
$param["create_time"] = date("Y-m-d H:i:s", time());
$model_ = new ChatMsgStatus();
$model_->addChatMsgStatus($param);
return true;
}
......
......@@ -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 1516874980 rememberMe deleteMe
a1.easemob.com FALSE / FALSE 1516954550 rememberMe deleteMe
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/26
* Time : 16:08
* Intro:
*/
use think\Model;
use think\Db;
class ChatMsgStatus extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'chat_msg_status';
protected $db;
public function __construct()
{
$this->db = Db::name($this->table);
}
public function addChatMsgStatus($params)
{
Db::startTrans();
try {
$this->db->insert($params);
Db::commit();
} catch (\Exception $e) {
dump($e);
Db::rollback();
}
return 0;
}
}
\ No newline at end of file
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