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
52d1871e
Commit
52d1871e
authored
Jul 10, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
聊天
parent
14250637
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
46 deletions
+103
-46
ChatService.php
application/chat/service/ChatService.php
+24
-3
GeTuiUtils.php
application/chat/utils/GeTuiUtils.php
+11
-9
RPush.php
application/chat/utils/RPush.php
+27
-24
ChatMsg.php
application/model/ChatMsg.php
+5
-5
ChatRelation.php
application/model/ChatRelation.php
+12
-5
ChatUserExt.php
application/model/ChatUserExt.php
+24
-0
No files found.
application/chat/service/ChatService.php
View file @
52d1871e
...
...
@@ -205,7 +205,19 @@ class ChatService
$rPush
=
new
RPush
();
// 消息接收人必须是数组
$rPush
->
send
(
$user_name
,
$target_type
,
[
$target
],
$msg_content
,
$from
,
$type
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
$userExt
=
new
ChatUserExt
();
$where
[
'only_id'
]
=
$target
;
$info
=
$userExt
->
getChatUserExtByUserId
(
$where
,
'a.id,a.ext_id,a.device_id,a.push_id'
);
if
(
count
(
$info
)
<=
0
)
{
return
false
;
}
$target
=
[];
foreach
(
$info
as
$item
)
{
array_push
(
$target
,
$item
[
"push_id"
]);
}
$rPush
->
send
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
return
true
;
}
...
...
@@ -329,7 +341,7 @@ class ChatService
$params
[
"is_user"
]
=
$is_user
;
$params
[
"created_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"updated_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
//dump($params);
$msgModel
=
new
ChatMsg
();
$id
=
$msgModel
->
addChatMsg
(
$params
);
...
...
@@ -381,7 +393,16 @@ class ChatService
$field
=
"a.id,a.to_id,a.from_id,a.create_time,b.type,b.id as user_or_agent_id,b.only_id,
c.name as agent_name,c.img,d.user_name,d.user_phone,d.user_nick,d.user_pic,d.other_pic"
;
return
$chatRelationModel
->
getChatRelationInfo
(
$params
,
$field
);
$relationList
=
$chatRelationModel
->
getChatRelationInfo
(
$params
,
$field
);
dump
(
$relationList
);
$fields
=
"a.id,a.from_id,a.to_id,b.body,a.created_at"
;
$msgModel
=
new
ChatMsg
();
foreach
(
$relationList
as
$key
=>
$item
)
{
$select_
[
"from"
]
=
$item
[
"from_id"
];
$select_
[
"target"
]
=
$item
[
"to_id"
];
$relationList
[
$key
][
"chat_info"
]
=
$msgModel
->
getChatHistory
(
$select_
,
$fields
,
1
,
1
);
}
return
$relationList
;
}
/**
...
...
application/chat/utils/GeTuiUtils.php
View file @
52d1871e
...
...
@@ -12,11 +12,11 @@ namespace app\chat\utils;
class
GeTuiUtils
{
const
IGT_APP_ID
=
'A8raBWQxuX9bcVmk3rkWa5'
;
const
IGT_APP_SECRET
=
'TLNDlz8YsW6J4gexzb4AX3'
;
const
IGT_APP_KEY
=
'dEC3iu81ZC9XbsVLwoiHA6'
;
const
IGT_APP_ID
=
'A8raBWQxuX9bcVmk3rkWa5'
;
const
IGT_APP_SECRET
=
'TLNDlz8YsW6J4gexzb4AX3'
;
const
IGT_APP_KEY
=
'dEC3iu81ZC9XbsVLwoiHA6'
;
const
IGT_MASTER_SECRET
=
'3NNdfsgjCJ6Rmfr9l0EeI1'
;
const
IGT_HOST
=
'http://sdk.open.api.igexin.com/apiex.htm'
;
const
IGT_HOST
=
'http://sdk.open.api.igexin.com/apiex.htm'
;
/**
* 引入类文件
...
...
@@ -37,24 +37,24 @@ class GeTuiUtils
* @param $data
* @return array
*/
public
function
pushMessageToIgt
(
$push_id
,
$type
=
'other'
,
$title
,
$
data
)
public
function
pushMessageToIgt
(
$push_id
,
$type
=
'other'
,
$title
,
$
payload
)
{
$igt
=
new
\IGeTui
(
self
::
IGT_HOST
,
self
::
IGT_APP_KEY
,
self
::
IGT_MASTER_SECRET
);
$payload
[
'title'
]
=
$title
;
/*
$payload['title'] = $title;
$payload['type'] = $type; //0系统,1用户消息
$payload['msg_content'] = $data['msg_content'];
$payload['to_id'] = $data['to_id']; //接收人
$payload['from_id'] = $data['from_id']; //发送人
$payload['to_name'] = $data['to_name'];//接收人名字
$payload['from_name'] = $data['from_name'];//发送人名字
$payload
[
'target_type'
]
=
$data
[
'target_type'
];
//1文字,2.图片 3.楼盘
$payload['target_type'] = $data['target_type']; //1文字,2.图片 3.楼盘
*/
$payload
=
json_encode
(
$payload
);
try
{
//模板
$template
=
$this
->
onlineAllTemplate
(
$payload
,
$title
,
$data
[
'msg_content'
]
);
$template
=
$this
->
onlineAllTemplate
(
$payload
,
$title
,
"1231231"
);
}
catch
(
\Exception
$e
)
{
$result
[
'code'
]
=
'failed'
;
$result
[
'msg'
]
=
'字数超过限制'
;
...
...
@@ -75,7 +75,9 @@ class GeTuiUtils
$result
=
[];
foreach
(
$push_id
as
$k
=>
$v
)
{
echo
$v
;
$target
->
set_clientId
(
$v
);
dump
(
$target
);
$res
=
$igt
->
pushMessageToSingle
(
$message
,
$target
);
if
(
$res
[
'result'
]
==
'ok'
)
{
...
...
application/chat/utils/RPush.php
View file @
52d1871e
...
...
@@ -45,7 +45,6 @@ class RPush
}
$response
=
$this
->
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
);
call_user_func_array
([
$callback
[
0
],
$callback
[
1
]
],
[
$response
,
$target
,
$from
,
$msg_content
]);
}
...
...
@@ -55,40 +54,44 @@ class RPush
* @param $target_type users 给用户发消息。chatgroups: 给群发消息,chatrooms: 给聊天室发消息
* @param $target 注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'],给用户发送时数组元素是用户名,
* 给群组发送时数组元素是groupid
* @param $type //目前只有文本的消息
* @param $msg_content
* @param $from
* @param $type //目前只有文本的消息
* @param $access_token
* @return \app\chat\utils\CurlResponse|bool
*/
public
function
sendRequestByCurl
(
$user_name
,
$target_type
,
$target
,
$msg_content
,
$from
,
$type
,
$access_token
)
{
$arr
=
array
(
$title
=
"收到一条消息"
;
$arr
=
array
(
'target_type'
=>
$target_type
,
'target'
=>
$target
,
//[1,2,3]
'msg'
=>
[
"type"
=>
"txt"
,
"msg"
=>
$msg_content
],
'from'
=>
$from
,
'ext'
=>
[
"msg_type"
=>
$type
,
"user_name"
=>
$user_name
]
'target'
=>
$target
,
'msg'
=>
[
"type"
=>
"txt"
,
"msg"
=>
$msg_content
],
'from'
=>
$from
,
'ext'
=>
[
"msg_type"
=>
$type
,
"user_name"
=>
$user_name
]
);
$data
=
json_encode
(
$arr
);
$pushMessageToIgt
=
new
GeTuiUtils
();
$push_arr
=
$target
;
$response_
=
new
GeTuiUtils
();
$response_
->
pushMessageToIgt
();
/* $data = json_encode($arr
);
$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
;
$response
=
$pushMessageToIgt
->
pushMessageToIgt
(
$push_arr
,
$type
=
'other'
,
$title
,
$data
);
/*
$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;*/
}
/**
...
...
application/model/ChatMsg.php
View file @
52d1871e
...
...
@@ -26,16 +26,15 @@ class ChatMsg extends Model
public
function
addChatMsg
(
$params
)
{
Db
::
startTrans
();
$id
=
0
;
try
{
$this
->
save
(
$params
);
$id
=
$this
->
id
;
$id
=
$this
->
db
->
insertGetId
(
$params
);
Db
::
commit
();
return
$id
;
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
}
return
0
;
return
$id
;
}
/**
...
...
@@ -64,7 +63,7 @@ class ChatMsg extends Model
}
$where_
[
"a.is_del"
]
=
0
;
$data
=
$this
->
field
(
$field
)
$data
=
$this
->
db
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
'chat_msg_ext b'
,
'a.id = b.msg_id'
,
'LEFT'
)
->
where
(
$where_
)
...
...
@@ -75,6 +74,7 @@ class ChatMsg extends Model
->
limit
(
$page_size
)
->
page
(
$page_no
)
->
select
();
//echo $this->getLastSql();
return
$data
;
}
...
...
application/model/ChatRelation.php
View file @
52d1871e
...
...
@@ -42,18 +42,19 @@ class ChatRelation extends Model
$whereOr_
[
"from_id"
]
=
$params
[
"target"
];
}
if
(
isset
(
$params
[
"from"
]))
{
$where_
[
"
to
_id"
]
=
$params
[
"from"
];
$whereOr_
[
"
from
_id"
]
=
$params
[
"from"
];
$where_
[
"
from
_id"
]
=
$params
[
"from"
];
$whereOr_
[
"
to
_id"
]
=
$params
[
"from"
];
}
$where_
[
"disable"
]
=
0
;
$whereOr_
[
"disable"
]
=
0
;
return
$this
->
field
(
$field
)
$data
=
$this
->
field
(
$field
)
->
where
(
$where_
)
->
whereOr
(
function
(
$query
)
use
(
$whereOr_
)
{
$query
->
where
(
$whereOr_
);
})
->
select
();
// echo $this->getLastSql();
return
$data
;
}
/**
...
...
@@ -76,7 +77,7 @@ class ChatRelation extends Model
}
$where_
[
"disable"
]
=
0
;
$whereOr_
[
"disable"
]
=
0
;
return
$this
->
field
(
$field
)
$date
=
$this
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
"chat_user b"
,
"a.to_id != '"
.
$only_id
.
"' and a.to_id=b.only_id or a.from_id=b.only_id"
,
"left"
)
->
join
(
"a_agents c"
,
"b.type = 1 and b.id = c.id"
,
"left"
)
...
...
@@ -86,9 +87,15 @@ class ChatRelation extends Model
$query
->
where
(
$whereOr_
);
})
->
select
();
// echo $this->getLastSql();
return
$date
;
}
/**
* 新增联系人
* @param $params
*/
public
function
addChatRelation
(
$params
)
{
$where_
=
[];
...
...
application/model/ChatUserExt.php
View file @
52d1871e
...
...
@@ -48,6 +48,30 @@ class ChatUserExt extends BaseModel
return
$data
;
}
/**
* @param $params
* @param string $field
* @return mixed
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public
function
getChatUserExtByUserId
(
$params
,
$field
)
{
$where_
=
[];
if
(
isset
(
$params
[
'only_id'
]))
{
$where_
[
'b.only_id'
]
=
$params
[
'only_id'
];
$where_
[
'a.is_forbidden'
]
=
0
;
}
$data
=
$this
->
db
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
"chat_user b"
,
"a.ext_id = b.id"
,
"right"
)
->
where
(
$where_
)
->
select
();
//echo $this->getLastSql();
return
$data
;
}
/**
* @param $params
* @param $v
...
...
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