Commit 454177c6 authored by hujun's avatar hujun

修改

parent b1eaeab6
......@@ -8,34 +8,38 @@
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');
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
{
/**
* GeTuiUtils constructor.
*/
public function __construct()
{
include_once(EXTEND_PATH . 'GETUI_PHP_SDK' . DS . 'IGt.Push.php');
include_once(EXTEND_PATH . 'GETUI_PHP_SDK/IGt.Push.php');
}
/**
* 个推
*
* @param $data
* @return array
* @throws \Exception
*/
function push_message_for_one($data)
{
$cid = $data['device_id'];
$igt = new \IGeTui(TL_GETUI_HOST, TL_GETUI_APPKEY, TL_GETUI_MASTERSECRET);
$igt = new \IGeTui(IGT_HOST, IGT_APP_KEY, IGT_MASTER_SECRET);
//模板
$template = $this->onli_all_template($data['touchuan'], $data['black_title'], $data['content']);
$template = $this->online_all_template($data['touchuan'], $data['black_title'], $data['content']);
//个推信息体
$message = new \IGtSingleMessage();
......@@ -43,14 +47,15 @@ class GeTuiUtils
$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_appId(IGT_APP_ID);
$target->set_clientId($cid);
try {
$rep = $igt->pushMessageToSingle($message, $target);
} catch (RequestException $e) {
$requestId = $e . getRequestId();
$requestId = $e->getRequestId();
$rep = $igt->pushMessageToSingle($message, $target, $requestId); //失败重发
}
......@@ -58,78 +63,43 @@ class GeTuiUtils
}
/**
* 群推
* 推送模板
*
* @param $title
* @param $payload
* @param $black_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
* @return \IGtTransmissionTemplate
* @throws \Exception
*/
function onli_all_template($touchuan, $black_title, $content)
function online_all_template($payload, $black_title, $content)
{
$template = new \IGtTransmissionTemplate();
$template->set_appId(TL_GETUI_APPID);//应用appid
$template->set_appkey(TL_GETUI_APPKEY);//应用appkey
$template->set_appId(IGT_APP_ID);//应用appid
$template->set_appkey(IGT_APP_KEY);//应用appkey
$template->set_transmissionType(2);//透传消息类型
$template->set_transmissionContent($touchuan); //透传内容
$template->set_transmissionContent($payload); //透传内容
//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;
$alert_msg = new \DictionaryAlertMsg();
$alert_msg->body = $content;//对应的是在线透传的content
$alert_msg->actionLocKey = "打开同联商业";//滑动打开app
$alert_msg->locKey = $content;//锁屏提示下框
$alert_msg->title = $black_title;//标题 锁屏标题
$alert_msg->titleLocKey = $black_title;//下拉通知上部框框
$alert_msg->titleLocArgs = [ "TitleLocArg" ];
$apn->alertMsg = $alert_msg;
$apn->badge = 1;//应用icon上显示的数字
$apn->sound = "";
$template->set_apnInfo($apn);
return $template;
}
/**
* 对某个人推送消息-公共
*
* 对某个人推送消息
*
* @param $id
* @param $device_id
* @param $title
......@@ -137,6 +107,7 @@ class GeTuiUtils
* @param string $type
* @param $user_id
* @return array
* @throws \Exception
*/
function public_push_message_for_one($id, $device_id, $title, $content, $type = 'other', $user_id)
{
......@@ -156,6 +127,11 @@ class GeTuiUtils
return $this->push_message_for_one($data);
}
/**
* 当前域名
*
* @return string
*/
public function http_host()
{
$http_type =
......@@ -175,15 +151,17 @@ class GeTuiUtils
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);
return 'Error_no' . curl_error($curl);
}
curl_close($curl);
return $result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment