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
415adc0a
Commit
415adc0a
authored
Jan 08, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
聊天服务
parent
66666288
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
285 additions
and
5 deletions
+285
-5
common.php
application/chat/common.php
+1
-0
config.php
application/chat/config.php
+6
-0
AppChat.php
application/chat/controller/AppChat.php
+66
-0
Basic.php
application/chat/extend/Basic.php
+62
-0
ChatService.php
application/chat/service/ChatService.php
+45
-0
RPush.php
application/chat/utils/RPush.php
+75
-0
route.php
application/route.php
+7
-0
build.php
build.php
+4
-5
chat.php
public/chat.php
+19
-0
No files found.
application/chat/common.php
0 → 100644
View file @
415adc0a
<?php
application/chat/config.php
0 → 100644
View file @
415adc0a
<?php
//配置文件
return
[
];
\ No newline at end of file
application/chat/controller/AppChat.php
0 → 100644
View file @
415adc0a
<?php
namespace
app\chat\controller
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 16:54
* Intro:
*/
use
app\chat\extend\Basic
;
use
app\chat\service\ChatService
;
use
RPush
;
use
Think\Log
;
use
think\Request
;
class
AppChat
extends
Basic
{
/**
* @var RPush
*/
private
$_push
;
//环信接口消息推送
/**
* @var ChatService
*/
private
$_chat
;
public
function
__construct
(
$request
=
null
)
{
parent
::
__construct
(
$request
);
$this
->
_push
=
new
RPush
();
$this
->
_chat
=
new
ChatService
();
}
public
function
index
()
{
/*
log 常规日志,用于记录日志
error 错误,一般会导致程序的终止
notice 警告,程序可以运行但是还不够完美的错误
info 信息,程序输出信息
debug 调试,用于调试信息
sql SQL语句,用于SQL记录,只在数据库的调试模式开启时有效
*/
Log
::
record
(
'日志'
,
'notice'
);
return
null
;
}
/**
* 验证用户角色,生成唯一id
*
* @return \think\Response
*/
public
function
userChat
()
{
$this
->
_chat
->
createOnlyId
();
return
$this
->
response
(
"200"
);
}
}
application/chat/extend/Basic.php
0 → 100644
View file @
415adc0a
<?php
namespace
app\chat\extend
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 16:54
* Intro:
*/
use
think\Controller
;
use
think\Request
;
use
think\Response
;
class
Basic
extends
Controller
{
/**
* 访问请求对象
* @var Request
*/
public
$request
;
public
$params
;
/**
* 基础接口SDK
* @param Request|null $request
*/
public
function
__construct
(
Request
$request
=
null
)
{
// CORS 跨域 Options 检测响应
$this
->
corsOptionsHandler
();
// 输入对象
$this
->
request
=
is_null
(
$request
)
?
Request
::
instance
()
:
$request
;
if
(
strtoupper
(
$this
->
request
->
method
())
===
"GET"
)
{
$this
->
params
=
$this
->
request
->
param
();
}
elseif
(
strtoupper
(
$this
->
request
->
method
())
===
"POST"
)
{
$this
->
params
=
$this
->
request
->
param
()
!=
null
?
$this
->
request
->
param
()
:
null
;
}
}
/**
* 输出返回数据
* @param string $msg 提示消息内容
* @param string $code 业务状态码
* @param mixed $data 要返回的数据
* @param string $type 返回类型 JSON XML
* @return Response
*/
public
function
response
(
$code
=
'SUCCESS'
,
$msg
,
$data
=
[],
$type
=
'json'
)
{
$result
=
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
,
'type'
=>
strtolower
(
$type
)
];
return
Response
::
create
(
$result
,
$type
);
}
}
application/chat/service/ChatService.php
0 → 100644
View file @
415adc0a
<?php
namespace
app\chat\service
;
class
ChatService
{
public
$connection
;
public
$logs
;
const
MSG_CONTENT_TYPE_TEXT
=
1
;
//文字
const
MSG_CONTENT_TYPE_VOICE
=
2
;
//语音
const
MSG_CONTENT_TYPE_VIDEO
=
3
;
//视频
const
SOURCE_TYPE_APP
=
'app_'
;
// 用户 c端
const
SOURCE_TYPE_AGENT
=
'agent_'
;
//经纪人 b端
/**
* 生成唯一id
* @param $userId integer 用户id
* @param $mobile string 手机号
* @param $source integer 来源 '1经纪人 2用户'
* @return string
*/
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
;
case
2
:
break
;
default
:
}
return
$onlyId
;
}
}
\ No newline at end of file
application/chat/utils/RPush.php
0 → 100644
View file @
415adc0a
<?php
use
Payment\Utils\Curl
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 17:17
* Intro: 发送消息类
*/
class
RPush
{
/**
* curl参数拼凑
* @param $push_type
* @param $sender
* @param $receiver
* @param $msg_content
* @param $msg_file_name
* @param $msg_file_url
* @return bool|CurlResponse
*/
public
function
sendRequestByCurl
(
$push_type
,
$sender
,
$receiver
,
$msg_content
,
$msg_file_name
,
$msg_file_url
){
$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
,
);
$data
=
json_encode
(
$arr
);
$curl
=
new
Curl
();
$curl
->
headers
=
[
"Accept"
=>
"application/json"
,
"Content-Type"
=>
"application/json;charset=utf-8"
,
'Authorization'
=>
$this
->
main_auth
,
];
$curl
->
options
=
[
"CURLOPT_SSL_VERIFYPEER"
=>
0
,
"CURLOPT_SSL_VERIFYHOST"
=>
1
,
];
$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
)));
return
$response
;
}
/**
* @return string
*/
private
function
buildSendUrl
()
{
return
$this
->
base_url
.
'/Accounts/'
.
$this
->
account_sid
.
'/IM/PushMsg?sig='
.
$this
->
main_sig
;
}
}
\ No newline at end of file
application/route.php
View file @
415adc0a
...
@@ -136,4 +136,10 @@ Route::group('api', [
...
@@ -136,4 +136,10 @@ Route::group('api', [
]);
]);
Route
::
group
(
'chat'
,
[
'userChat'
=>
[
'chat/AppChat/userChat'
,
[
'method'
=>
'get'
]
],
]);
//Route::miss('api/index/miss');//处理错误的url
//Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
build.php
View file @
415adc0a
...
@@ -22,11 +22,10 @@ return [
...
@@ -22,11 +22,10 @@ return [
'view' => ['index/index'],
'view' => ['index/index'],
],*/
],*/
// 其他更多的模块定义
// 其他更多的模块定义
'
app
'
=>
[
'
chat
'
=>
[
'__file__'
=>
[
'common.php'
],
'__file__'
=>
[
'common.php'
],
'__dir__'
=>
[
'behavior'
,
'controller'
,
'model'
,
'view'
],
'__dir__'
=>
[
'behavior'
,
'controller'
,
'service'
,
'utils'
],
'controller'
=>
[
'Index'
,
'Test'
,
'UserType'
],
'controller'
=>
[
'Index'
],
'model'
=>
[
'User'
,
'UserType'
],
'service'
=>
[
'IndexService'
],
'view'
=>
[
'index/index'
],
],
],
];
];
public/chat.php
0 → 100644
View file @
415adc0a
<?php
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 15:56
* Intro:
*/
// [ 应用入口文件 ]
// 定义应用目录
define
(
'APP_PATH'
,
__DIR__
.
'/../application/'
);
// 加载框架引导文件
require
__DIR__
.
'/../thinkphp/start.php'
;
// 读取自动生成定义文件
/*$build = include './../build.php';
// 运行自动生成
\think\Build::run($build);*/
\ 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