Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
0f89df04
Commit
0f89df04
authored
Jul 20, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
字段验证
parent
dbd8809f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
56 deletions
+95
-56
AppChat.php
application/chat/controller/AppChat.php
+20
-19
ChatService.php
application/chat/service/ChatService.php
+9
-10
RPush.php
application/chat/utils/RPush.php
+12
-27
ChatVerifyValidate.php
application/chat/validate/ChatVerifyValidate.php
+54
-0
No files found.
application/chat/controller/AppChat.php
View file @
0f89df04
...
...
@@ -149,19 +149,20 @@ class AppChat extends Basic
{
$params
=
$this
->
params
;
/* $params = array(
'user_name' => 'cesh',
'msg_content' => 'ceshi666',
'target_type' => 'users',
'source' => '1',
'from' => 'user_1',
'type' => '1',
'is_user' => '0',
'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'
]))
{
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
"请求参数错误"
);
/* $params = array(
'user_name' => 'cesh',
'msg_content' => 'ceshi666',
'target_type' => 'users',
'source' => '1',
'from' => 'user_1',
'type' => '1',
'is_user' => '0',
'target' => 'agent_5739',
);*/
$checkResult
=
$this
->
validate
(
$params
,
"ChatVerifyValidate.pushMsg"
);
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
$checkResult
);
}
$user_name
=
isset
(
$params
[
'user_name'
])
?
$params
[
'user_name'
]
:
$params
[
'from'
];
//用户昵称
...
...
@@ -176,7 +177,7 @@ class AppChat extends Basic
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
)
{
return
$this
->
response
(
"200"
,
""
,
[
"msg"
=>
"消息发送成功"
]);
}
else
{
...
...
@@ -322,11 +323,11 @@ class AppChat extends Basic
public
function
getChatRelation
()
{
$params
=
$this
->
params
;
/* $params = array(
"target" => "user_2", //当前用户
"is_user" => 0,//0用户1经纪人
"relation_list" => '[{"r_id":"2","msg_id":3536},{"r_id":"8","msg_id":3524}]',
);*/
/* $params = array(
"target" => "user_2", //当前用户
"is_user" => 0,//0用户1经纪人
"relation_list" => '[{"r_id":"2","msg_id":3536},{"r_id":"8","msg_id":3524}]',
);*/
if
(
!
isset
(
$params
[
'target'
])
||
!
isset
(
$params
[
"is_user"
]))
{
return
$this
->
response
(
"300"
,
"参数不全"
);
}
...
...
application/chat/service/ChatService.php
View file @
0f89df04
...
...
@@ -191,14 +191,13 @@ class ChatService
* @param $type
* @param $msg_content
* @param $from
* @param $accessToken
* @return bool
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @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
);
...
...
@@ -236,7 +235,7 @@ class ChatService
foreach
(
$info
as
$item
)
{
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
;
}
...
...
@@ -249,14 +248,14 @@ class ChatService
*/
public
function
saveSendStatus
(
$response
,
$target
,
$from
,
$msg_content
)
{
/* $response = json_decode($response, true);
//目前没有针对多人聊天
$status = isset($response["data"][$target[0]]) ? $response["data"][$target[0]] : "faild"
;
$error_reason = ""
;
if ($status != "success")
{
$error_reason = "环信发送异常";
try
{
//目前没有针对多人聊天
$status
=
$response
[
"code"
]
;
$this
->
insertPushLog
(
$from
,
$target
,
$msg_content
,
$status
,
$response
[
"msg"
])
;
}
catch
(
Exception
$exception
)
{
//todo 暂不处理
}
$this->insertPushLog($from, $target[0], $msg_content, $status, $error_reason);*/
}
...
...
application/chat/utils/RPush.php
View file @
0f89df04
...
...
@@ -26,13 +26,12 @@ class RPush
* @param $from
* @param $is_user
* @param $type
* @param $access_token
* @param $callback
* @param $push_id
* @param $msg_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
if
(
Cache
::
get
(
'save_message_num'
))
{
...
...
@@ -48,32 +47,30 @@ class RPush
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
]);
}
/**
* @param $user_name
* @param $target_type
//users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target
//注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* @param $target_type //users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target //注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $msg_content //目前只有文本的消息
* @param $from
* @param $is_user
* @param $type
* @param $access_token
* @param $push_id
* @param $message_id
* @param $user_id
* @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
=
"收到一条消息"
;
$payload
=
json_encode
(
array
(
$title
=
"收到一条消息"
;
$msg_bin
=
array
(
'title'
=>
$title
,
'content'
=>
""
,
'type'
=>
'chat'
,
...
...
@@ -93,25 +90,13 @@ class RPush
'message_id'
=>
$message_id
,
'user_id'
=>
$user_id
]
));
);
$payload
=
json_encode
(
$msg_bin
);
$pushMessageToIgt
=
new
GeTuiUtils
();
return
$pushMessageToIgt
->
pushMessageToIgt
(
$push_id
,
$title
,
$payload
,
$is_user
);
/* $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), "info");
return $response;*/
$result
=
$pushMessageToIgt
->
pushMessageToIgt
(
$push_id
,
$title
,
$payload
,
$is_user
);
return
$result
;
}
/**
...
...
application/chat/validate/ChatVerifyValidate.php
0 → 100644
View file @
0f89df04
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment