<?php
namespace AppHttpControllers;
use AppUser;
use Validator;
use AppHttpControllersController;
use LaravelSocialiteFacadesSocialite;
use IlluminateHttpRequest;
use IlluminateSupportFacadesCache;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesCookie;
class UserThirdPushController extends Controller
{
public function pushMessage()
{
header("Content-Type: text/html; charset=utf-8");
require_once(dirname(__FILE__) . '/os-php/' . 'IGt.Push.php');
require_once(dirname(__FILE__) . '/os-php/' . 'igetui/IGt.AppMessage.php');
require_once(dirname(__FILE__) . '/os-php/' . 'igetui/IGt.APNPayload.php');
require_once(dirname(__FILE__) . '/os-php/' . 'igetui/template/IGt.BaseTemplate.php');
require_once(dirname(__FILE__) . '/os-php/' . 'IGt.Batch.php');
require_once(dirname(__FILE__) . '/os-php/' . 'igetui/utils/AppConditions.php');
//http的域名
define('HOST', 'http://sdk.open.api.igexin.com/apiex.htm');
define('APPKEY', '');
define('APPID', '');
define('MASTERSECRET', '');
define('CID', '');
define('DEVICETOKEN', '');
define('Alias', '请输入别名');
$this->pushMessageToApp();
}
//群推接口案例
function pushMessageToApp()
{
$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
$template = $this->IGtTransmissionTemplateDemo();
//$template = $this->IGtNotificationTemplateDemo();
//$template = IGtLinkTemplateDemo();
//个推信息体
//基于应用消息体
$message = new IGtAppMessage();
$message->set_isOffline(true);
$message->set_offlineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->set_data($template);
$appIdList=array(APPID);
$message->set_appIdList($appIdList);
$rep = $igt->pushMessageToApp($message,"任务组名");
var_dump($rep);
echo ("<br><br>");
}
function IGtTransmissionTemplateDemo()
{
$template = new IGtTransmissionTemplate();
$template->set_appId(APPID);//应用appid
$template->set_appkey(APPKEY);//应用appkey
$template->set_transmissionType(2);//透传消息类型
$info = DB::table('push_message')->orderBy('id','desc')->select('objectid','userid','title','objtype','content')->first();
$title = $info->title;
$content = htmlspecialchars_decode(html_entity_decode(cleanJs($info->content)));
$b = $info;
$info = json_encode($info);
/* var_dump($info);
exit;*/
$template->set_transmissionContent($info);//透传内容
//APN高级推送
$apn = new IGtAPNPayload();
$alertmsg=new DictionaryAlertMsg();
//$alertmsg->body="hebintest22222222";
$alertmsg->body = $content;
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
//IOS8.2 支持
//$alertmsg->title="phptest";
$alertmsg->title = $title;
$alertmsg->titleLocKey="TitleLocKey";
//$alertmsg->titleLocArgs=array("TitleLocArg");
$alertmsg->titleLocArgs = $b;
$apn->alertMsg=$alertmsg;
$apn->badge=1;//icon角标设置数量
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
//添加自定义数据
//$alertmsg->addCustomMsg = $info;
$template->set_apnInfo($apn);
return $template;
}
}
?>