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
10f7ae05
Commit
10f7ae05
authored
Jul 06, 2018
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送
parent
b4958556
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
86 deletions
+108
-86
GeTuiUtils.php
application/chat/utils/GeTuiUtils.php
+108
-86
No files found.
application/chat/utils/GeTuiUtils.php
View file @
10f7ae05
<?php
namespace
app\chat\utils
;
/**
* Created by PhpStorm.
* User: hujun
...
...
@@ -7,17 +9,18 @@ namespace app\chat\utils;
* Time: 21:09
*/
use
RequestException
;
define
(
'IGT_APP_ID'
,
'A8raBWQxuX9bcVmk3rkWa5'
);
define
(
'IGT_APP_SECRET'
,
'TLNDlz8YsW6J4gexzb4AX3'
);
define
(
'IGT_APP_KEY'
,
'dEC3iu81ZC9XbsVLwoiHA6'
);
define
(
'IGT_MASTER_SECRET'
,
'3NNdfsgjCJ6Rmfr9l0EeI1'
);
define
(
'IGT_HOST'
,
'http://sdk.open.api.igexin.com/apiex.htm'
);
class
GeTuiUtils
{
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'
;
/**
* 引入类文件
*
* GeTuiUtils constructor.
*/
public
function
__construct
()
...
...
@@ -26,56 +29,32 @@ class GeTuiUtils
}
/**
*
对某个人
推送消息
* 推送消息
*
* @param $id
* @param $device_id
* @param string $type
* @param $title
* @param $content
* @param string $type
* @param $user_id
* @param null $id
* @return array
* @throws \Exception
*/
public
function
push
ToPerson
(
$id
,
$device_id
,
$title
,
$content
,
$type
=
'other'
,
$user_
id
=
null
)
public
function
push
MessageToIgt
(
$device_id
,
$type
=
'other'
,
$title
,
$content
,
$
id
=
null
)
{
$home_url
=
$this
->
httpHost
();
$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'
]);
try
{
$result
=
$this
->
pushMessageToIgt
(
$data
);
}
catch
(
\Exception
$e
)
{
$result
[
'result'
]
=
'error'
;
$result
[
'status'
]
=
$e
->
getMessage
();
}
return
$result
;
}
$igt
=
new
\IGeTui
(
self
::
IGT_HOST
,
self
::
IGT_APP_KEY
,
self
::
IGT_MASTER_SECRET
);
/**
* @param $data
* @return array
* @throws \Exception
*/
public
function
pushMessageToIgt
(
$data
)
{
$cid
=
$data
[
'device_id'
];
$payload
[
'title'
]
=
$title
;
$payload
[
'content'
]
=
$content
;
$payload
[
'type'
]
=
$type
;
$payload
[
'url'
]
=
""
;
$payload
[
'name'
]
=
$title
;
$payload
[
'id'
]
=
$id
;
$payload
[
'imageUrl'
]
=
""
;
$
igt
=
new
\IGeTui
(
IGT_HOST
,
IGT_APP_KEY
,
IGT_MASTER_SECRET
);
$
payload
=
json_encode
(
$payload
);
//模板
$template
=
$this
->
onlineAllTemplate
(
$
data
[
'touchuan'
],
$data
[
'black_title'
],
$data
[
'content'
]
);
$template
=
$this
->
onlineAllTemplate
(
$
payload
,
$title
,
$content
);
//个推信息体
$message
=
new
\IGtSingleMessage
();
...
...
@@ -86,16 +65,20 @@ class GeTuiUtils
//接收方
$target
=
new
\IGtTarget
();
$target
->
set_appId
(
IGT_APP_ID
);
$target
->
set_clientId
(
$cid
);
try
{
$rep
=
$igt
->
pushMessageToSingle
(
$message
,
$target
);
}
catch
(
RequestException
$e
)
{
$requestId
=
$e
->
getRequestId
();
$rep
=
$igt
->
pushMessageToSingle
(
$message
,
$target
,
$requestId
);
//失败重发
$target
->
set_appId
(
self
::
IGT_APP_ID
);
$target
->
set_clientId
(
$device_id
);
$res
=
$igt
->
pushMessageToSingle
(
$message
,
$target
);
if
(
$res
[
'result'
]
==
'ok'
)
{
$result
[
'code'
]
=
'success'
;
$result
[
'msg'
]
=
$res
[
'result'
];
}
else
{
$result
[
'code'
]
=
'failed'
;
$result
[
'msg'
]
=
$this
->
getReturnCode
(
$res
[
'result'
]);
}
return
$re
p
;
return
$re
sult
;
}
/**
...
...
@@ -111,8 +94,8 @@ class GeTuiUtils
{
$template
=
new
\IGtTransmissionTemplate
();
$template
->
set_appId
(
IGT_APP_ID
);
//应用appid
$template
->
set_appkey
(
IGT_APP_KEY
);
//应用appkey
$template
->
set_appId
(
self
::
IGT_APP_ID
);
//应用appid
$template
->
set_appkey
(
self
::
IGT_APP_KEY
);
//应用appkey
$template
->
set_transmissionType
(
2
);
//透传消息类型
$template
->
set_transmissionContent
(
$payload
);
//透传内容
...
...
@@ -134,42 +117,80 @@ class GeTuiUtils
}
/**
*
当前域名
*
返回code码对应信息
*
* @param $code
* @return string
*/
public
function
httpHost
(
)
public
function
getReturnCode
(
$code
)
{
$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
httpRequest
(
$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
'Error_no'
.
curl_error
(
$curl
);
$result
=
''
;
switch
(
$code
)
{
case
'Error'
:
$result
=
'请求信息填写有误'
;
break
;
case
'action_error'
:
$result
=
'未找到对应的action动作'
;
break
;
case
'appkey_error'
:
$result
=
'Appkey填写错误'
;
break
;
case
'domain_error'
:
$result
=
'填写的域名错误或者无法解析'
;
break
;
case
'sign_error'
:
$result
=
'Appkey与ClientId不匹配,鉴权失败'
;
break
;
case
'AppidNoMatchAppKey'
:
$result
=
'appid和鉴权的appkey不匹配'
;
break
;
case
'PushMsgToListOrAppTimesOverLimit'
:
$result
=
' 群推次数超过最大值'
;
break
;
case
'AppIdNoUsers'
:
$result
=
'该AppId下的用户总数为0'
;
break
;
case
'SendError'
:
$result
=
'消息推送发送错误'
;
break
;
case
'SynSendError'
:
$result
=
'报文发送错误'
;
break
;
case
'flow_exceeded'
:
$result
=
'接口消息推送流量已超限'
;
break
;
case
'TargetListIsNullOrSizeIs0'
:
$result
=
'推送target列表为空'
;
break
;
case
'PushTotalNumOverLimit'
:
$result
=
'推送消息个数总数超限'
;
break
;
case
'TokenMD5NoUsers'
:
$result
=
'target列表没有有效的clientID'
;
break
;
case
'NullMsgCommon'
:
$result
=
'未找到contentId对应的任务'
;
break
;
case
'TaskIdHasBeanCanceled'
:
$result
=
'任务已经被取消'
;
break
;
case
'AppidError'
:
$result
=
'clientid绑定的appid与推送的appid不符'
;
break
;
case
'successed_ignore'
:
$result
=
'无效用户,消息丢弃'
;
break
;
case
'TokenMD5Error'
:
$result
=
'clientID填写有误'
;
break
;
case
'AppidNoAppSecret'
:
$result
=
'appid未找到对应的appSecret'
;
break
;
case
'OtherError'
:
$result
=
'未知错误,无法判定错误类型'
;
break
;
}
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