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
d8f85518
Commit
d8f85518
authored
Jan 10, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
聊天
parent
415adc0a
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
757 additions
and
89 deletions
+757
-89
ConfigConst.php
application/chat/consts/ConfigConst.php
+20
-0
ErrorCodeConst.php
application/chat/consts/ErrorCodeConst.php
+22
-0
AppChat.php
application/chat/controller/AppChat.php
+34
-4
Basic.php
application/chat/extend/Basic.php
+94
-0
ChatService.php
application/chat/service/ChatService.php
+20
-6
CurlResponse.php
application/chat/utils/CurlResponse.php
+78
-0
CurlUtil.php
application/chat/utils/CurlUtil.php
+268
-0
RPush.php
application/chat/utils/RPush.php
+57
-38
RedisPackage.php
application/extra/RedisPackage.php
+106
-0
Agents.php
application/model/Agents.php
+57
-41
route.php
application/route.php
+1
-0
No files found.
application/chat/consts/ConfigConst.php
0 → 100644
View file @
d8f85518
<?php
namespace
app\chat\consts
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/9
* Time : 13:27
* Intro:
*/
class
ConfigConst
{
const
CLIENT_ID
=
"YXA6hqlTwLr0EeeNFrlhHiI-Xg"
;
const
CLIENT_SECRET
=
"YXA6BkraoPZqZYJoLce4sCyRebXMC48"
;
const
API_PATH
=
"https://a1.easemob.com/"
;
const
ORG_NAME
=
"1157170531115254"
;
const
APP_NAME
=
"tonglianjituan"
;
}
\ No newline at end of file
application/chat/consts/ErrorCodeConst.php
0 → 100644
View file @
d8f85518
<?php
namespace
app\chat\consts
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/9
* Time : 16:54
* Intro:
*/
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
;
}
\ No newline at end of file
application/chat/controller/AppChat.php
View file @
d8f85518
...
...
@@ -10,9 +10,17 @@ namespace app\chat\controller;
* Intro:
*/
use
app\chat\consts\ConfigConst
;
use
app\chat\consts\ErrorCodeConst
;
use
app\chat\extend\Basic
;
use
app\chat\service\ChatService
;
use
app\extra\RedisPackage
;
use
app\model\Users
;
use
CurlUtil
;
use
HttpException
;
use
RPush
;
use
think\Cache
;
use
think\Exception
;
use
Think\Log
;
use
think\Request
;
...
...
@@ -34,10 +42,11 @@ class AppChat extends Basic
{
parent
::
__construct
(
$request
);
$this
->
_push
=
new
RPush
();
$this
->
_chat
=
new
ChatService
();
/*
$this->_push = new RPush();
$this->_chat = new ChatService();*/
}
public
function
index
()
{
/*
...
...
@@ -48,6 +57,12 @@ class AppChat extends Basic
debug 调试,用于调试信息
sql SQL语句,用于SQL记录,只在数据库的调试模式开启时有效
*/
Cache
::
set
(
'name'
,
'121212'
);
echo
Cache
::
get
(
'name'
);
$redis
=
new
RedisPackage
();
$redis
::
set
(
'test'
,
'hello redis'
);
echo
$redis
::
get
(
'test'
);
Log
::
record
(
'日志'
,
'notice'
);
return
null
;
}
...
...
@@ -59,8 +74,23 @@ class AppChat extends Basic
*/
public
function
userChat
()
{
$this
->
_chat
->
createOnlyId
();
$params
=
array
(
"userId"
=>
1
,
"mobile"
=>
"13817616471"
,
"source"
=>
1
//1经纪人 2用户
);
//$params = $this->params;
$userId
=
$params
[
'sender'
];
$mobile
=
$params
[
'receiver'
];
$source
=
$params
[
'msg_type'
];
if
(
!
$userId
||
!
$mobile
||
!
$source
)
{
return
$this
->
response
(
ErrorCodeConst
::
ERROR_CODE_PARAM_NOT_EXIST
,
"请求参数错误"
);
}
return
$this
->
response
(
"200"
);
$onlyId
=
$this
->
_chat
->
createOnlyId
(
$userId
,
$mobile
,
$source
);
return
$this
->
response
(
"200"
,
array
(
"onlyId"
=>
$onlyId
));
}
}
application/chat/extend/Basic.php
View file @
d8f85518
...
...
@@ -9,7 +9,12 @@ namespace app\chat\extend;
* Time : 16:54
* Intro:
*/
use
app\chat\consts\ConfigConst
;
use
app\chat\utils\CurlUtil
;
use
http\Exception
;
use
think\Cache
;
use
think\Controller
;
use
Think\Log
;
use
think\Request
;
use
think\Response
;
...
...
@@ -21,8 +26,19 @@ class Basic extends Controller
*/
public
$request
;
/**
* 请求参数
* @var mixed|null
*/
public
$params
;
/**
* app通讯接口授权token
* @var
*/
public
$accessToken
;
/**
* 基础接口SDK
* @param Request|null $request
...
...
@@ -40,6 +56,22 @@ class Basic extends Controller
$this
->
params
=
$this
->
request
->
param
()
!=
null
?
$this
->
request
->
param
()
:
null
;
}
$this
->
accessToken
=
Cache
::
get
(
'access_token'
);
$expires_in
=
Cache
::
get
(
'expires_in'
);
$application
=
Cache
::
get
(
'application'
);
$accredit_time
=
Cache
::
get
(
'accredit_time'
);
if
(
!
$this
->
accessToken
||
!
$expires_in
||
!
$application
||
!
$accredit_time
||
(
time
()
-
$accredit_time
)
>
$expires_in
)
{
//todo 这里加个验证 多少时间内不能重复请求
$this
->
getToken
();
if
(
Cache
::
get
(
'access_token'
))
{
$this
->
accessToken
=
Cache
::
get
(
'access_token'
);
}
else
{
echo
json_encode
(
array
(
"code"
=>
"300"
,
"msg"
=>
"accessToken拉取失败,请稍后再试!"
,
"data"
=>
[],
"type"
=>
"json"
));
exit
;
}
}
}
...
...
@@ -57,6 +89,68 @@ class Basic extends Controller
return
Response
::
create
(
$result
,
$type
);
}
public
function
getApiPath
()
{
return
ConfigConst
::
API_PATH
.
ConfigConst
::
ORG_NAME
.
"/"
.
ConfigConst
::
APP_NAME
;
}
/**
* Cors Options 授权处理
*/
public
static
function
corsOptionsHandler
()
{
if
(
request
()
->
isOptions
())
{
header
(
'Access-Control-Allow-Origin:*'
);
header
(
'Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token'
);
header
(
'Access-Control-Allow-Credentials:true'
);
header
(
'Access-Control-Allow-Methods:GET,POST,OPTIONS'
);
header
(
'Access-Control-Max-Age:1728000'
);
header
(
'Content-Type:text/plain charset=UTF-8'
);
header
(
'Content-Length: 0'
,
true
);
header
(
'status: 204'
);
header
(
'HTTP/1.0 204 No Content'
);
exit
;
}
}
/**
* 获取调取接口的access_token
*/
public
function
getToken
()
{
$url
=
"/token"
;
$data
=
[
"grant_type"
=>
"client_credentials"
,
"client_id"
=>
ConfigConst
::
CLIENT_ID
,
"client_secret"
=>
ConfigConst
::
CLIENT_SECRET
];
$curl
=
new
CurlUtil
();
$curl
->
headers
=
[
"Accept"
=>
"application/json"
,
"Content-Type"
=>
"application/json;charset=utf-8"
,
];
$curl
->
options
=
[
"CURLOPT_SSL_VERIFYPEER"
=>
0
,
"CURLOPT_SSL_VERIFYHOST"
=>
2
,
];
$apiUrl
=
$this
->
getApiPath
()
.
$url
;
try
{
$response
=
$curl
->
post
(
$apiUrl
,
json_encode
(
$data
));
$response
=
json_decode
(
$response
,
true
);
if
(
$response
)
{
Cache
::
set
(
'access_token'
,
$response
[
"access_token"
]);
Cache
::
set
(
'expires_in'
,
$response
[
"expires_in"
]);
Cache
::
set
(
'application'
,
$response
[
"application"
]);
Cache
::
set
(
'accredit_time'
,
time
());
}
}
catch
(
Exception
$e
)
{
Log
::
record
(
'class:Basic,function:getToken get token ,Exception :'
.
$e
,
"error"
);
}
Log
::
record
(
'class:Basic,function:getToken get token'
,
"info"
);
}
}
application/chat/service/ChatService.php
View file @
d8f85518
...
...
@@ -2,6 +2,9 @@
namespace
app\chat\service
;
use
app\model\Agents
;
use
app\model\Users
;
class
ChatService
{
public
$connection
;
...
...
@@ -15,6 +18,15 @@ class ChatService
const
SOURCE_TYPE_AGENT
=
'agent_'
;
//经纪人 b端
protected
$userModel
;
protected
$agentsModel
;
public
function
__construct
()
{
$this
->
userModel
=
new
Users
();
$this
->
agentsModel
=
new
Agents
();
}
/**
* 生成唯一id
* @param $userId integer 用户id
...
...
@@ -25,17 +37,19 @@ class ChatService
public
function
createOnlyId
(
$userId
,
$mobile
,
$source
)
{
//todo 1.验证用户是否存在 经纪人和用户 2.根据规则生成唯一id 3.判断唯一id是否登录中,登陆中则调用退出接口 4.返回唯一id
$onlyId
=
""
;
switch
(
$source
)
{
case
1
:
$onlyId
=
self
::
SOURCE_TYPE_APP
;
break
;
$agentsResult
=
$this
->
agentsModel
->
getAgentsById
(
$userId
);
if
(
count
(
$agentsResult
)
>
1
)
$onlyId
=
self
::
SOURCE_TYPE_AGENT
.
$userId
;
case
2
:
$userResult
=
$this
->
userModel
->
selectUser
(
$userId
);
if
(
count
(
$userResult
)
>
1
)
$onlyId
=
self
::
SOURCE_TYPE_APP
.
$userId
;
break
;
default
:
return
array
(
"code"
=>
101
,
"msg"
=>
"没找到用户信息"
);
}
return
$onlyId
;
...
...
application/chat/utils/CurlResponse.php
0 → 100644
View file @
d8f85518
<?php
namespace
app\chat\utils
;
/**
* Parses the response from a Curl request into an object containing
* the response body and an associative array of headers
*
* @author qianfunian <qianfunian@51jk.com>
**/
class
CurlResponse
{
/**
* The body of the response without the headers block
*
* @var string
**/
public
$body
=
''
;
/**
* An associative array containing the response's headers
*
* @var array
**/
public
$headers
=
array
();
/**
* Accepts the result of a curl request as a string
*
* <code>
* $response = new CurlResponse(curl_exec($curl_handle));
* echo $response->body;
* echo $response->headers['Status'];
* </code>
*
* @param string $response
**/
function
__construct
(
$response
)
{
# Headers regex
$pattern
=
'#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims'
;
# Extract headers from response
preg_match_all
(
$pattern
,
$response
,
$matches
);
$headers_string
=
array_pop
(
$matches
[
0
]);
$headers
=
explode
(
"
\r\n
"
,
str_replace
(
"
\r\n\r\n
"
,
''
,
$headers_string
));
# Remove headers from the response body
$this
->
body
=
str_replace
(
$headers_string
,
''
,
$response
);
# Extract the version and status from the first header
$version_and_status
=
array_shift
(
$headers
);
preg_match
(
'#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#'
,
$version_and_status
,
$matches
);
$this
->
headers
[
'Http-Version'
]
=
$matches
[
1
];
$this
->
headers
[
'Status-Code'
]
=
$matches
[
2
];
$this
->
headers
[
'Status'
]
=
$matches
[
2
]
.
' '
.
$matches
[
3
];
# Convert headers into an associative array
foreach
(
$headers
as
$header
)
{
preg_match
(
'#(.*?)\:\s(.*)#'
,
$header
,
$matches
);
$this
->
headers
[
$matches
[
1
]]
=
$matches
[
2
];
}
}
/**
* Returns the response body
*
* <code>
* $curl = new Curl;
* $response = $curl->get('google.com');
* echo $response; # => echo $response->body;
* </code>
*
* @return string
**/
function
__toString
()
{
return
$this
->
body
;
}
}
\ No newline at end of file
application/chat/utils/CurlUtil.php
0 → 100644
View file @
d8f85518
<?php
namespace
app\chat\utils
;
/**
* A basic CURL wrapper
*
* @author qianfunian <qianfunian@51jk.com>
**/
class
CurlUtil
{
/**
* The file to read and write cookies to for requests
*
* @var string
**/
public
$cookie_file
;
/**
* Determines whether or not requests should follow redirects
*
* @var boolean
**/
public
$follow_redirects
=
true
;
/**
* An associative array of headers to send along with requests
*
* @var array
**/
public
$headers
=
array
();
/**
* An associative array of CURLOPT options to send along with requests
*
* @var array
**/
public
$options
=
array
();
/**
* The referer header to send along with requests
*
* @var string
**/
public
$referer
;
/**
* The user agent to send along with requests
*
* @var string
**/
public
$user_agent
;
/**
* Stores an error string for the last request if one occurred
*
* @var string
* @access protected
**/
protected
$error
=
''
;
/**
* Stores resource handle for the current CURL request
*
* @var resource
* @access protected
**/
protected
$request
;
/**
* Initializes a Curl object
*
* Sets the $cookie_file to "curl_cookie.txt" in the current directory
* Also sets the $user_agent to $_SERVER['HTTP_USER_AGENT'] if it exists, 'Curl/PHP '.PHP_VERSION.' (http://github.com/shuber/curl)' otherwise
**/
function
__construct
()
{
$this
->
cookie_file
=
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
.
'curl_cookie.txt'
;
$this
->
user_agent
=
isset
(
$_SERVER
[
'HTTP_USER_AGENT'
])
?
$_SERVER
[
'HTTP_USER_AGENT'
]
:
'Curl/PHP '
.
PHP_VERSION
;
}
/**
* Makes an HTTP DELETE request to the specified $url with an optional array or string of $vars
*
* Returns a CurlResponse object if the request was successful, false otherwise
*
* @param string $url
* @param array|string $vars
* @return CurlResponse object
**/
function
delete
(
$url
,
$vars
=
array
())
{
return
$this
->
request
(
'DELETE'
,
$url
,
$vars
);
}
/**
* Returns the error string of the current request if one occurred
*
* @return string
**/
function
error
()
{
return
$this
->
error
;
}
/**
* Makes an HTTP GET request to the specified $url with an optional array or string of $vars
*
* Returns a CurlResponse object if the request was successful, false otherwise
*
* @param string $url
* @param array|string $vars
* @return CurlResponse
**/
function
get
(
$url
,
$vars
=
array
())
{
$vars
[
'platform_type'
]
=
130
;
if
(
!
empty
(
$vars
))
{
$url
.=
(
stripos
(
$url
,
'?'
)
!==
false
)
?
'&'
:
'?'
;
$url
.=
(
is_string
(
$vars
))
?
$vars
:
http_build_query
(
$vars
,
''
,
'&'
);
}
$file
=
new
LogsService
(
LOGS_PATH
.
'/curl_get/'
.
date
(
'Y-m-d'
));
$file
->
info
(
$url
);
return
$this
->
request
(
'GET'
,
$url
);
}
/**
* Makes an HTTP HEAD request to the specified $url with an optional array or string of $vars
*
* Returns a CurlResponse object if the request was successful, false otherwise
*
* @param string $url
* @param array|string $vars
* @return CurlResponse
**/
function
head
(
$url
,
$vars
=
array
())
{
return
$this
->
request
(
'HEAD'
,
$url
,
$vars
);
}
/**
* Makes an HTTP POST request to the specified $url with an optional array or string of $vars
*
* @param string $url
* @param array|string $vars
* @return CurlResponse|boolean
**/
function
post
(
$url
,
$vars
=
array
())
{
if
(
!
is_string
(
$vars
))
{
$vars
[
'platform_type'
]
=
130
;
}
return
$this
->
request
(
'POST'
,
$url
,
$vars
);
}
/**
* Makes an HTTP PUT request to the specified $url with an optional array or string of $vars
*
* Returns a CurlResponse object if the request was successful, false otherwise
*
* @param string $url
* @param array|string $vars
* @return CurlResponse|boolean
**/
function
put
(
$url
,
$vars
=
array
())
{
return
$this
->
request
(
'PUT'
,
$url
,
$vars
);
}
/**
* Makes an HTTP request of the specified $method to a $url with an optional array or string of $vars
*
* Returns a CurlResponse object if the request was successful, false otherwise
*
* @param string $method
* @param string $url
* @param array|string $vars
* @return CurlResponse|boolean
**/
function
request
(
$method
,
$url
,
$vars
=
array
())
{
$this
->
error
=
''
;
$this
->
request
=
curl_init
();
if
(
is_array
(
$vars
))
$vars
=
http_build_query
(
$vars
,
''
,
'&'
);
$this
->
set_request_method
(
$method
);
$this
->
set_request_options
(
$url
,
$vars
);
$this
->
set_request_headers
();
$response
=
curl_exec
(
$this
->
request
);
if
(
$response
)
{
$response
=
new
CurlResponse
(
$response
);
}
else
{
$this
->
error
=
curl_errno
(
$this
->
request
)
.
' - '
.
curl_error
(
$this
->
request
);
}
curl_close
(
$this
->
request
);
return
$response
;
}
/**
* Formats and adds custom headers to the current request
*
* @return void
* @access protected
**/
protected
function
set_request_headers
()
{
$headers
=
array
();
foreach
(
$this
->
headers
as
$key
=>
$value
)
{
$headers
[]
=
$key
.
': '
.
$value
;
}
curl_setopt
(
$this
->
request
,
CURLOPT_HTTPHEADER
,
$headers
);
}
/**
* Set the associated CURL options for a request method
*
* @param string $method
* @return void
* @access protected
**/
protected
function
set_request_method
(
$method
)
{
switch
(
strtoupper
(
$method
))
{
case
'HEAD'
:
curl_setopt
(
$this
->
request
,
CURLOPT_NOBODY
,
true
);
break
;
case
'GET'
:
curl_setopt
(
$this
->
request
,
CURLOPT_HTTPGET
,
true
);
break
;
case
'POST'
:
curl_setopt
(
$this
->
request
,
CURLOPT_POST
,
true
);
break
;
default
:
curl_setopt
(
$this
->
request
,
CURLOPT_CUSTOMREQUEST
,
$method
);
}
}
/**
* Sets the CURLOPT options for the current request
*
* @param string $url
* @param string $vars
* @return void
* @access protected
**/
protected
function
set_request_options
(
$url
,
$vars
)
{
/* echo $url;
dump($vars);
dump($this->options);
echo $this->request;
exit;*/
curl_setopt
(
$this
->
request
,
CURLOPT_URL
,
$url
);
if
(
!
empty
(
$vars
))
curl_setopt
(
$this
->
request
,
CURLOPT_POSTFIELDS
,
$vars
);
# Set some default CURL options
curl_setopt
(
$this
->
request
,
CURLOPT_HEADER
,
true
);
curl_setopt
(
$this
->
request
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$this
->
request
,
CURLOPT_USERAGENT
,
$this
->
user_agent
);
if
(
$this
->
cookie_file
)
{
curl_setopt
(
$this
->
request
,
CURLOPT_COOKIEFILE
,
$this
->
cookie_file
);
curl_setopt
(
$this
->
request
,
CURLOPT_COOKIEJAR
,
$this
->
cookie_file
);
}
if
(
$this
->
follow_redirects
)
curl_setopt
(
$this
->
request
,
CURLOPT_FOLLOWLOCATION
,
true
);
if
(
$this
->
referer
)
curl_setopt
(
$this
->
request
,
CURLOPT_REFERER
,
$this
->
referer
);
# Set any custom CURL options
foreach
(
$this
->
options
as
$option
=>
$value
)
{
curl_setopt
(
$this
->
request
,
constant
(
'CURLOPT_'
.
str_replace
(
'CURLOPT_'
,
''
,
strtoupper
(
$option
))),
$value
);
}
}
}
\ No newline at end of file
application/chat/utils/RPush.php
View file @
d8f85518
<?php
use
Payment\Utils\Curl
;
/**
* Created by PhpStorm.
...
...
@@ -9,57 +8,77 @@ use Payment\Utils\Curl;
* Time : 17:17
* Intro: 发送消息类
*/
class
RPush
{
class
RPush
{
/**
* curl参数拼凑
* @param $push_type
* @param $sender
* @param $receiver
* @param $msg_content
* @param $msg_file_name
* @param $msg_file_url
* @return bool|CurlResponse
/** curl参数拼凑
* @param $target_type
* @param $target
* @param $msg
* @param $from
* @param $accessToken
* @return $this
*/
public
function
sendRequestByCurl
(
$push_type
,
$sender
,
$receiver
,
$msg_content
,
$msg_file_name
,
$msg_file_url
){
public
function
sendRequestByCurl
(
$target_type
,
$target
,
$msg
,
$from
,
$accessToken
)
{
/**
* { wenzi
* "target_type" : "users", // users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* "target" : ["u1", "u2", "u3"], // 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,
* // 也要用数组 ['u1'],给用户发送时数组元素是用户名,给群组发送时
* // 数组元素是groupid
* "msg" : {
* "type" : "txt",
* "msg" : "hello from rest" //消息内容,参考[[start:100serverintegration:30chatlog|聊天记录]]里的bodies内容
* },
* "from" : "jma2" //表示消息发送者。无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败
* }
*
*
*{
* "target_type" : "users", //users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* "target" : ["u1", "u2", "u3"],// 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,
* // 也要用数组 ['u1'],给用户发送时数组元素是用户名,给群组发送时
* // 数组元素是groupid
* "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
* }
* },
* "from" : "jma2" //表示消息发送者,无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败
* }
*
*
*/
$this
->
_log
->
info
(
"-------Rpush==>params:push_type==>"
.
$push_type
.
'sender==>'
.
$sender
.
'receiver==>'
.
$receiver
.
'msg_content==>'
.
$msg_content
);
$msg_content
[
'extended'
]
=
"
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
;
//让msg很长不会在push中显示出来
$arr
=
array
(
'pushType'
=>
$push_type
,
'appId'
=>
$this
->
app_id
,
'sender'
=>
$sender
,
'receiver'
=>
$receiver
,
'msgType'
=>
1
,
'msgContent'
=>
json_encode
(
$msg_content
),
'msgDomain'
=>
''
,
'msgFileName'
=>
$msg_file_name
,
'msgFileUrl'
=>
$msg_file_url
,
'target_type'
=>
$target_type
,
'target'
=>
$target
,
'msg'
=>
$msg
,
'from'
=>
$from
,
);
$data
=
json_encode
(
$arr
);
$data
=
json_encode
(
$arr
);
$curl
=
new
Cur
l
();
$curl
=
new
\app\chat\utils\CurlUti
l
();
$curl
->
headers
=
[
"Accept"
=>
"application/json"
,
"Content-Type"
=>
"application/json;charset=utf-8"
,
'Authorization'
=>
$
this
->
main_auth
,
'Authorization'
=>
$
accessToken
,
];
$curl
->
options
=
[
"CURLOPT_SSL_VERIFYPEER"
=>
0
,
"CURLOPT_SSL_VERIFYHOST"
=>
1
,
"CURLOPT_SSL_VERIFYHOST"
=>
2
,
];
$url
=
$this
->
buildSendUrl
();
$response
=
$curl
->
post
(
$url
,
$data
);
$this
->
_log
->
info
(
sprintf
(
"%s::%s,url[%s],data[%s] response[%s]"
,
__CLASS__
,
__FUNCTION__
,
$url
,
json_encode
(
$data
),
json_encode
(
$response
)));
$url
=
$this
->
buildSendUrl
();
$response
=
$curl
->
post
(
$url
,
$data
);
return
$response
;
}
...
...
application/extra/RedisPackage.php
0 → 100644
View file @
d8f85518
<?php
namespace
app\extra
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/9
* Time : 15:20
* Intro: redis connect class
*/
class
RedisPackage
{
protected
static
$handler
=
null
;
protected
$options
=
[
'host'
=>
'101.132.186.250'
,
'port'
=>
6379
,
'password'
=>
''
,
'select'
=>
0
,
'timeout'
=>
0
,
'expire'
=>
0
,
'persistent'
=>
false
,
'prefix'
=>
''
,
];
public
function
__construct
(
$options
=
[])
{
if
(
!
extension_loaded
(
'redis'
))
{
//判断是否有扩展(如果你的apache没reids扩展就会抛出这个异常)
throw
new
\BadFunctionCallException
(
'not support: redis'
);
}
if
(
!
empty
(
$options
))
{
$this
->
options
=
array_merge
(
$this
->
options
,
$options
);
}
$func
=
$this
->
options
[
'persistent'
]
?
'pconnect'
:
'connect'
;
//判断是否长连接
self
::
$handler
=
new
\Redis
;
self
::
$handler
->
$func
(
$this
->
options
[
'host'
],
$this
->
options
[
'port'
],
$this
->
options
[
'timeout'
]);
if
(
''
!=
$this
->
options
[
'password'
])
{
self
::
$handler
->
auth
(
$this
->
options
[
'password'
]);
}
if
(
0
!=
$this
->
options
[
'select'
])
{
self
::
$handler
->
select
(
$this
->
options
[
'select'
]);
}
}
/**
* 写入缓存
* @param string $key 键名
* @param string $value 键值
* @param int $exprie 过期时间 0:永不过期
* @return bool
*/
public
static
function
set
(
$key
,
$value
,
$exprie
=
0
)
{
if
(
$exprie
==
0
)
{
$set
=
self
::
$handler
->
set
(
$key
,
$value
);
}
else
{
$set
=
self
::
$handler
->
setex
(
$key
,
$exprie
,
$value
);
}
return
$set
;
}
/**
* 读取缓存
* @param string $key 键值
* @return mixed
*/
public
static
function
get
(
$key
)
{
$fun
=
is_array
(
$key
)
?
'Mget'
:
'get'
;
return
self
::
$handler
->
{
$fun
}(
$key
);
}
/**
* 获取值长度
* @param string $key
* @return int
*/
public
static
function
lLen
(
$key
)
{
return
self
::
$handler
->
lLen
(
$key
);
}
/**
* 将一个或多个值插入到列表头部
* @param $key
* @param $value
* @return int
*/
public
static
function
LPush
(
$key
,
$value
,
$value2
=
null
,
$valueN
=
null
)
{
return
self
::
$handler
->
lPush
(
$key
,
$value
,
$value2
,
$valueN
);
}
/**
* 移出并获取列表的第一个元素
* @param string $key
* @return string
*/
public
static
function
lPop
(
$key
)
{
return
self
::
$handler
->
lPop
(
$key
);
}
}
\ No newline at end of file
application/model/Agents.php
View file @
d8f85518
...
...
@@ -9,7 +9,7 @@ class Agents extends Model
{
/**
* 查询经纪人
*
*
* @param type $pageNo
* @param type $pageSize
* @param type $order_
...
...
@@ -18,85 +18,100 @@ class Agents extends Model
* @param type $house_id 查询该街铺和商铺的经纪人评论信息
* @return type
*/
public
function
getUser
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
,
$house_id
=
''
)
{
public
function
getUser
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
,
$house_id
=
''
)
{
if
(
$house_id
==
''
)
{
$data
=
$this
->
field
(
$field
)
->
alias
(
'a'
)
->
join
(
'u_evaluate b'
,
'a.id = b.agents_id'
,
'left'
)
->
where
(
$params
)
->
where
(
'level=2 or level=5'
)
->
group
(
'a.id'
)
->
order
(
$order_
)
->
limit
(
$pageSize
)
->
page
(
$pageNo
)
->
select
();
->
join
(
'u_evaluate b'
,
'a.id = b.agents_id'
,
'left'
)
->
where
(
$params
)
->
where
(
'level=2 or level=5'
)
->
group
(
'a.id'
)
->
order
(
$order_
)
->
limit
(
$pageSize
)
->
page
(
$pageNo
)
->
select
();
}
else
{
$data
=
$this
->
field
(
$field
)
->
alias
(
'a'
)
->
join
(
'u_evaluate b'
,
'a.id = b.agents_id'
,
'left'
)
->
where
(
'find_in_set('
.
$house_id
.
', house_ids) or find_in_set('
.
$house_id
.
', house_ids2)'
)
->
where
(
$params
)
->
where
(
'level=2 or level=5'
)
->
group
(
'a.id'
)
->
order
(
$order_
)
->
limit
(
$pageSize
)
->
page
(
$pageNo
)
->
select
();
->
join
(
'u_evaluate b'
,
'a.id = b.agents_id'
,
'left'
)
->
where
(
'find_in_set('
.
$house_id
.
', house_ids) or find_in_set('
.
$house_id
.
', house_ids2)'
)
->
where
(
$params
)
->
where
(
'level=2 or level=5'
)
->
group
(
'a.id'
)
->
order
(
$order_
)
->
limit
(
$pageSize
)
->
page
(
$pageNo
)
->
select
();
}
return
$data
;
}
/**
* 经纪人详情
*
*
* @param type $id
* @return boolean
*/
public
function
agentsDetail
(
$id
)
{
public
function
agentsDetail
(
$id
)
{
if
(
$id
)
{
$result
=
$this
->
field
(
'id,realname,created,sub_shopname,head_portrait'
)
->
where
(
'level=2 or level=5'
)
->
where
(
'id'
,
$id
)
->
find
();
$result
[
'head_portrait'
]
=
'user_header/'
.
$result
[
'head_portrait'
];
//头像
->
where
(
'level=2 or level=5'
)
->
where
(
'id'
,
$id
)
->
find
();
$result
[
'head_portrait'
]
=
'user_header/'
.
$result
[
'head_portrait'
];
//头像
$evaluate_grade
=
Db
::
table
(
'u_evaluate'
)
->
field
(
'sum(evaluate_grade) as evaluate_grade, count(*) as evaluate_num'
)
->
where
(
'agents_id'
,
$id
)
->
where
(
'is_show'
,
0
)
->
find
();
->
field
(
'sum(evaluate_grade) as evaluate_grade, count(*) as evaluate_num'
)
->
where
(
'agents_id'
,
$id
)
->
where
(
'is_show'
,
0
)
->
find
();
if
(
$evaluate_grade
[
'evaluate_grade'
])
{
$grade
=
floor
((
$evaluate_grade
[
'evaluate_grade'
]
/
2
)
/
$evaluate_grade
[
'evaluate_num'
]);
$grade
=
floor
((
$evaluate_grade
[
'evaluate_grade'
]
/
2
)
/
$evaluate_grade
[
'evaluate_num'
]);
}
else
{
$grade
=
0
;
}
$result
[
'evaluate_grade'
]
=
$grade
;
//评分等级
$result
[
'evaluate_num'
]
=
$evaluate_grade
[
'evaluate_num'
];
//评论数量
$result
[
'watch_shop'
]
=
Db
::
table
(
'u_appoint_watch_shop'
)
->
where
(
'agents_id'
,
$id
)
->
count
();
//看铺
$result
[
'evaluate_num'
]
=
$evaluate_grade
[
'evaluate_num'
];
//评论数量
$result
[
'watch_shop'
]
=
Db
::
table
(
'u_appoint_watch_shop'
)
->
where
(
'agents_id'
,
$id
)
->
count
();
//看铺
$result
[
'head_portrait'
]
=
ADMIN_URL_TL
.
$result
[
'head_portrait'
];
$result
[
'head_portrait'
]
=
ADMIN_URL_TL
.
$result
[
'head_portrait'
];
$journal
=
new
JournalAccounts
();
$fields
=
'count(j.id) as num'
;
$fields
=
'count(j.id) as num'
;
$result
[
'JournalAccounts'
]
=
$journal
->
getJournalHouseInfoId
(
$fields
,
$id
)[
'num'
];
//成交记录
$current_time
=
time
();
$user_time
=
strtotime
(
$result
[
'created'
]);
$year
=
date
(
'Y'
,
$current_time
)
-
date
(
'Y'
,
$user_time
);
$user_time
=
strtotime
(
$result
[
'created'
]);
$year
=
date
(
'Y'
,
$current_time
)
-
date
(
'Y'
,
$user_time
);
//入职年限
if
(
$year
==
0
)
{
$result
[
'created'
]
=
$year
.
'个月以上'
;
$result
[
'created'
]
=
$year
.
'个月以上'
;
}
else
{
$result
[
'created'
]
=
$year
.
'年以上'
;
$result
[
'created'
]
=
$year
.
'年以上'
;
}
$result
[
'label'
]
=
array
(
0
=>
'待定标签数据'
,
1
=>
'待定标签数据'
);
$result
[
'label'
]
=
array
(
0
=>
'待定标签数据'
,
1
=>
'待定标签数据'
);
$data
=
$result
;
}
else
{
$data
=
false
;
}
return
$data
;
}
/**
* 获取经纪人 by zw
* @param $id
* @return array|false|\PDOStatement|string|Model
*/
public
function
getAgentsById
(
$id
)
{
return
$this
->
field
(
'id'
)
->
where
(
'inuse = 1 and id = '
.
$id
)
->
find
();
}
/**
* 查询经纪人列表
*
...
...
@@ -111,7 +126,8 @@ class Agents extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getAgents
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
,
$house_id
=
''
)
{
public
function
getAgents
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
,
$house_id
=
''
)
{
if
(
$house_id
==
''
)
{
$data
=
$this
->
field
(
$field
)
->
where
(
$params
)
...
...
@@ -122,7 +138,7 @@ class Agents extends Model
->
select
();
}
else
{
$data
=
$this
->
field
(
$field
)
->
where
(
'find_in_set('
.
$house_id
.
', house_ids) or find_in_set('
.
$house_id
.
', house_ids2)'
)
->
where
(
'find_in_set('
.
$house_id
.
', house_ids) or find_in_set('
.
$house_id
.
', house_ids2)'
)
->
where
(
$params
)
->
where
(
'level=2 or level=5'
)
->
order
(
$order_
)
...
...
application/route.php
View file @
d8f85518
...
...
@@ -139,6 +139,7 @@ Route::group('api', [
Route
::
group
(
'chat'
,
[
'index'
=>
[
'chat/AppChat/index'
,
[
'method'
=>
'get'
]
],
'userChat'
=>
[
'chat/AppChat/userChat'
,
[
'method'
=>
'get'
]
],
]);
...
...
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