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
b1eaeab6
Commit
b1eaeab6
authored
Jul 05, 2018
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送
parent
670b94e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
192 additions
and
0 deletions
+192
-0
GeTuiUtils.php
application/chat/utils/GeTuiUtils.php
+192
-0
No files found.
application/chat/utils/GeTuiUtils.php
0 → 100644
View file @
b1eaeab6
<?php
/**
* Created by PhpStorm.
* User: hujun
* Date: 2017/12/24
* Time: 21:09
*/
namespace
app\chat\utils
;
define
(
'TL_GETUI_APPID'
,
'A8raBWQxuX9bcVmk3rkWa5'
);
define
(
'TL_GETUI_APPSECRET'
,
'TLNDlz8YsW6J4gexzb4AX3'
);
define
(
'TL_GETUI_APPKEY'
,
'dEC3iu81ZC9XbsVLwoiHA6'
);
define
(
'TL_GETUI_MASTERSECRET'
,
'3NNdfsgjCJ6Rmfr9l0EeI1'
);
define
(
'TL_GETUI_HOST'
,
'http://sdk.open.api.igexin.com/apiex.htm'
);
class
GeTuiUtils
{
public
function
__construct
()
{
include_once
(
EXTEND_PATH
.
'GETUI_PHP_SDK'
.
DS
.
'IGt.Push.php'
);
}
/**
* 个推
*
* @param $data
* @return array
*/
function
push_message_for_one
(
$data
)
{
$cid
=
$data
[
'device_id'
];
$igt
=
new
\IGeTui
(
TL_GETUI_HOST
,
TL_GETUI_APPKEY
,
TL_GETUI_MASTERSECRET
);
//模板
$template
=
$this
->
onli_all_template
(
$data
[
'touchuan'
],
$data
[
'black_title'
],
$data
[
'content'
]);
//个推信息体
$message
=
new
\IGtSingleMessage
();
$message
->
set_isOffline
(
true
);
//是否离线
$message
->
set_offlineExpireTime
(
3600
*
12
*
1000
);
//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message
->
set_data
(
$template
);
//设置推送消息类型
$message
->
set_PushNetWorkType
(
0
);
//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//接收方
$target
=
new
\IGtTarget
();
$target
->
set_appId
(
TL_GETUI_APPID
);
$target
->
set_clientId
(
$cid
);
try
{
$rep
=
$igt
->
pushMessageToSingle
(
$message
,
$target
);
}
catch
(
RequestException
$e
)
{
$requestId
=
$e
.
getRequestId
();
$rep
=
$igt
->
pushMessageToSingle
(
$message
,
$target
,
$requestId
);
//失败重发
}
return
$rep
;
}
/**
* 群推
*
* @param $title
* @param $content
* @param $link
* @return mixed|null
*/
function
push_message_for_all
(
$title
,
$content
,
$link
)
{
$igt
=
new
\IGeTui
(
TL_GETUI_HOST
,
TL_GETUI_APPKEY
,
TL_GETUI_MASTERSECRET
);
$homeurl
=
$this
->
http_host
();
$data
[
'black_title'
]
=
$title
;
$data
[
'content'
]
=
$content
;
$data
[
'touchuan'
]
=
json_encode
([
'title'
=>
$title
,
'content'
=>
$content
,
'type'
=>
'url'
,
'url'
=>
$link
,
'name'
=>
$title
,
'id'
=>
''
,
'imageUrl'
=>
$homeurl
.
'/notice_android_logo.png'
]);
$template
=
$this
->
onli_all_template
(
$data
[
'touchuan'
],
$data
[
'black_title'
],
$data
[
'content'
]);
//个推信息体
//基于应用消息体
$message
=
new
\IGtAppMessage
();
$message
->
set_isOffline
(
true
);
$message
->
set_offlineExpireTime
(
3600
*
12
*
1000
);
//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message
->
set_data
(
$template
);
$message
->
set_PushNetWorkType
(
0
);
//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//$message->set_speed(1);// 设置群推接口的推送速度,单位为条/秒,例如填写100,则为100条/秒。仅对指定应用群推接口有效。
$appIdList
=
[
TL_GETUI_APPID
];
$message
->
set_appIdList
(
$appIdList
);
$rep
=
$igt
->
pushMessageToApp
(
$message
);
return
$rep
;
}
/**
* 推送模板
* zhuwei
* 2017-11-06
*/
function
onli_all_template
(
$touchuan
,
$black_title
,
$content
)
{
$template
=
new
\IGtTransmissionTemplate
();
$template
->
set_appId
(
TL_GETUI_APPID
);
//应用appid
$template
->
set_appkey
(
TL_GETUI_APPKEY
);
//应用appkey
$template
->
set_transmissionType
(
2
);
//透传消息类型
$template
->
set_transmissionContent
(
$touchuan
);
//透传内容
//APN高级推送
$apn
=
new
\IGtAPNPayload
();
$alertmsg
=
new
\DictionaryAlertMsg
();
$alertmsg
->
body
=
$content
;
//对应的是在线透传的content
$alertmsg
->
actionLocKey
=
"打开同联商业"
;
//滑动打开app
$alertmsg
->
locKey
=
$content
;
//锁屏提示下框
$alertmsg
->
title
=
$black_title
;
//标题 锁屏标题
$alertmsg
->
titleLocKey
=
$black_title
;
//下拉通知上部框框
$alertmsg
->
titleLocArgs
=
[
"TitleLocArg"
];
$apn
->
alertMsg
=
$alertmsg
;
$apn
->
badge
=
1
;
//应用icon上显示的数字
$apn
->
sound
=
""
;
$template
->
set_apnInfo
(
$apn
);
return
$template
;
}
/**
* 对某个人推送消息-公共
*
* @param $id
* @param $device_id
* @param $title
* @param $content
* @param string $type
* @param $user_id
* @return array
*/
function
public_push_message_for_one
(
$id
,
$device_id
,
$title
,
$content
,
$type
=
'other'
,
$user_id
)
{
$home_url
=
$this
->
http_host
();
$data
[
'agent_id'
]
=
$id
;
$data
[
'black_title'
]
=
$title
;
$data
[
'content'
]
=
$content
;
$data
[
'device_id'
]
=
$device_id
;
$data
[
'touchuan'
]
=
json_encode
([
'title'
=>
$title
,
'content'
=>
$content
,
'type'
=>
$type
,
'url'
=>
''
,
'name'
=>
$title
,
'id'
=>
$user_id
,
'imageUrl'
=>
$home_url
.
'notice_android_logo.png'
]);
return
$this
->
push_message_for_one
(
$data
);
}
public
function
http_host
()
{
$http_type
=
((
isset
(
$_SERVER
[
'HTTPS'
])
&&
$_SERVER
[
'HTTPS'
]
==
'on'
)
||
(
isset
(
$_SERVER
[
'HTTP_X_FORWARDED_PROTO'
])
&&
$_SERVER
[
'HTTP_X_FORWARDED_PROTO'
]
==
'https'
))
?
'https://'
:
'http://'
;
$host
=
$http_type
.
$_SERVER
[
'HTTP_HOST'
];
return
$host
;
}
/**
* https请求(支持GET和POST)
*
* @param $url
* @param null $data
* @return mixed|string
*/
function
http_request
(
$url
,
$data
=
null
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
false
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
false
);
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
$result
=
curl_exec
(
$curl
);
if
(
curl_errno
(
$curl
))
{
return
'Errno'
.
curl_error
(
$curl
);
}
curl_close
(
$curl
);
return
$result
;
}
}
\ 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