Commit 0f89df04 authored by clone's avatar clone

字段验证

parent dbd8809f
...@@ -159,9 +159,10 @@ class AppChat extends Basic ...@@ -159,9 +159,10 @@ class AppChat extends Basic
'is_user' => '0', 'is_user' => '0',
'target' => 'agent_5739', 'target' => 'agent_5739',
);*/ );*/
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'])) { $checkResult = $this->validate($params, "ChatVerifyValidate.pushMsg");
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, "请求参数错误"); if (true !== $checkResult) {
return $this->response(ErrorCodeConst::ERROR_CODE_PARAM_NOT_EXIST, $checkResult);
} }
$user_name = isset($params['user_name']) ? $params['user_name'] : $params['from'];//用户昵称 $user_name = isset($params['user_name']) ? $params['user_name'] : $params['from'];//用户昵称
...@@ -176,7 +177,7 @@ class AppChat extends Basic ...@@ -176,7 +177,7 @@ class AppChat extends Basic
return $this->response(ErrorCodeConst::ERROR_CODE_TARGET_TYPE_ERROR, "错误的消息类型"); return $this->response(ErrorCodeConst::ERROR_CODE_TARGET_TYPE_ERROR, "错误的消息类型");
} }
$result = $this->_chat->sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from, $this->accessToken); $result = $this->_chat->sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from);
if ($result) { if ($result) {
return $this->response("200", "", [ "msg" => "消息发送成功" ]); return $this->response("200", "", [ "msg" => "消息发送成功" ]);
} else { } else {
...@@ -322,7 +323,7 @@ class AppChat extends Basic ...@@ -322,7 +323,7 @@ class AppChat extends Basic
public function getChatRelation() public function getChatRelation()
{ {
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"target" => "user_2", //当前用户 "target" => "user_2", //当前用户
"is_user" => 0,//0用户1经纪人 "is_user" => 0,//0用户1经纪人
"relation_list" => '[{"r_id":"2","msg_id":3536},{"r_id":"8","msg_id":3524}]', "relation_list" => '[{"r_id":"2","msg_id":3536},{"r_id":"8","msg_id":3524}]',
......
...@@ -191,14 +191,13 @@ class ChatService ...@@ -191,14 +191,13 @@ class ChatService
* @param $type * @param $type
* @param $msg_content * @param $msg_content
* @param $from * @param $from
* @param $accessToken
* @return bool * @return bool
* @throws Exception * @throws Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from, $accessToken) public function sendMsg($user_name, $target_type, $target, $source, $is_user, $type, $msg_content, $from)
{ {
// 判断是否创建关系没有则保存 // 判断是否创建关系没有则保存
$this->verifyRelation($target, $from); $this->verifyRelation($target, $from);
...@@ -236,7 +235,7 @@ class ChatService ...@@ -236,7 +235,7 @@ class ChatService
foreach ($info as $item) { foreach ($info as $item) {
array_push($push_id, $item["push_id"]); array_push($push_id, $item["push_id"]);
} }
$rPush->send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $accessToken, [ $this, 'saveSendStatus' ], $push_id, $msg_id, $user_id); $rPush->send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, [ $this, 'saveSendStatus' ], $push_id, $msg_id, $user_id);
return true; return true;
} }
...@@ -249,14 +248,14 @@ class ChatService ...@@ -249,14 +248,14 @@ class ChatService
*/ */
public function saveSendStatus($response, $target, $from, $msg_content) public function saveSendStatus($response, $target, $from, $msg_content)
{ {
/* $response = json_decode($response, true); try{
//目前没有针对多人聊天 //目前没有针对多人聊天
$status = isset($response["data"][$target[0]]) ? $response["data"][$target[0]] : "faild"; $status = $response["code"];
$error_reason = ""; $this->insertPushLog($from, $target, $msg_content, $status, $response["msg"]);
if ($status != "success") { }catch (Exception $exception){
$error_reason = "环信发送异常"; //todo 暂不处理
} }
$this->insertPushLog($from, $target[0], $msg_content, $status, $error_reason);*/
} }
......
...@@ -26,13 +26,12 @@ class RPush ...@@ -26,13 +26,12 @@ class RPush
* @param $from * @param $from
* @param $is_user * @param $is_user
* @param $type * @param $type
* @param $access_token
* @param $callback * @param $callback
* @param $push_id * @param $push_id
* @param $msg_id * @param $msg_id
* @param $user_id * @param $user_id
*/ */
public function send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $callback, $push_id, $msg_id, $user_id) public function send($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $callback, $push_id, $msg_id, $user_id)
{ {
//todo //todo
if (Cache::get('save_message_num')) { if (Cache::get('save_message_num')) {
...@@ -48,7 +47,7 @@ class RPush ...@@ -48,7 +47,7 @@ class RPush
Cache::set('save_message_num', 0); Cache::set('save_message_num', 0);
} }
$response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $push_id, $msg_id,$user_id); $response = $this->sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $push_id, $msg_id, $user_id);
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 ]);
} }
...@@ -62,18 +61,16 @@ class RPush ...@@ -62,18 +61,16 @@ class RPush
* @param $from * @param $from
* @param $is_user * @param $is_user
* @param $type * @param $type
* @param $access_token
* @param $push_id * @param $push_id
* @param $message_id * @param $message_id
* @param $user_id * @param $user_id
* @return array * @return array
*/ */
public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $access_token, $push_id, $message_id,$user_id) public function sendRequestByCurl($user_name, $target_type, $target, $msg_content, $from, $is_user, $type, $push_id, $message_id, $user_id)
{ {
$title = "收到一条消息"; $title = "收到一条消息";
$msg_bin = array(
$payload = json_encode(array(
'title' => $title, 'title' => $title,
'content' => "", 'content' => "",
'type' => 'chat', 'type' => 'chat',
...@@ -93,25 +90,13 @@ class RPush ...@@ -93,25 +90,13 @@ class RPush
'message_id' => $message_id, 'message_id' => $message_id,
'user_id' => $user_id 'user_id' => $user_id
] ]
)); );
$payload = json_encode($msg_bin);
$pushMessageToIgt = new GeTuiUtils(); $pushMessageToIgt = new GeTuiUtils();
return $pushMessageToIgt->pushMessageToIgt($push_id, $title, $payload, $is_user); $result = $pushMessageToIgt->pushMessageToIgt($push_id, $title, $payload, $is_user);
/* $curl = new \app\chat\utils\CurlUtil(); return $result;
$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), "info");
return $response;*/
} }
/** /**
......
<?php
namespace app\chat\validate;
use think\Validate;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/6/19
* Time : 18:41
* Intro:
*/
class ChatVerifyValidate extends Validate
{
/**
* $target_type = $params['target_type']; // 消息类型 users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* $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']; //消息发送人
* @var array
*/
protected $rule = [
'target_type' => 'require',
'target' => 'require',
'source' => 'require|in:1,3',
'is_user' => 'require|in:0,1',
'type' => 'require|in:1,3',
'msg_content' => 'require',
'from' => 'require',
];
protected $message = [
'target_type.require' => '消息类型为必填字段',
'target.require' => '接收人为必填字段',
'source.require' => '消息来源为必填字段',
'source.in' => '消息来源值错误',
'is_user.require' => '发送人身份为必填字段',
'is_user.in' => '发送人身份值错误',
'type.require' => '消息类型为必填字段',
'type.in' => '消息类型值错误',
'msg_content.number' => '消息内容为必填字段',
'from.require' => '接收人为必填字段',
];
protected $scene = [
'pushMsg' => [ 'target_type', 'target', 'source', 'is_user', 'type', 'msg_content', 'from' ],
];
}
\ 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