UniPush推送 除了通知、透传消息可以正常发送以外。无法解决华为角标的问题、用uni-app 推荐用个推解决
//推送 unipush 推送
function send_push($type, $data, $uid,$ring,$vibrate) //透传消息不能空
{
vendor('UniPush.Push');
$result = new \Push();
return $result->jpush($type, $data, $uid,$ring,$vibrate);
}
//push.php 文件
require_once __DIR__ . '/IGt.Push.php';
define('HOST','http://sdk.open.api.igexin.com/apiex.htm');
define('APPKEY', 'xxxxx');
define('APPID','xxxxxxx');
define('MASTERSECRET','xxxxxxx');
define('DEVICETOKEN','');
class Push{
public function jpush($type,$data,$uid='',$ring,$vibrate){
$igt = new \IGeTui(HOST, APPKEY, MASTERSECRET);
switch ($type) {
case 1:
$template = $this->IGtNotificationTemplateDemo($data['title'],$data['content'],$ring,$vibrate);//单个通知栏广播(点击进入)
break;
case 2:
$template = $this->IGtTransmissionTemplateDemo($data);//单个透传功能模板(内部消息)
break;
case 3:
$template = $this->IGtNotificationTemplateDemo($data['title'],$data['content'],$ring,$vibrate);//整个应用推送
break;
default:
# code...
break;
}
//接收方
if(3 == $type){
//基于应用消息体
$message = new \IGtAppMessage();
$message->set_isOffline(true);
$message->set_offlineExpireTime(3600 * 12 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->set_data($template);
$appIdList=array(APPID);
$message->set_appIdList($appIdList);
$message->set_phoneTypeList(array('ANDROID','IOS'));
return $igt->pushMessageToApp($message);
}
//个推信息体
$message = new \IGtSingleMessage();
$message->set_isOffline(false);//是否离线
$message->set_offlineExpireTime(3600 * 12 * 1000);//离线时间
$message->set_data($template);//设置推送消息类型
$message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
$target = new \IGtTarget();
$target->set_appId(APPID);
$target->set_clientId($uid);
return $igt->pushMessageToSingle($message, $target);
}
//透传功能模板(内部消息)
private function IGtTransmissionTemplateDemo($content)
{
$template = new \IGtTransmissionTemplate();
$template->set_appId(APPID);//应用appid
$template->set_appkey(APPKEY);//应用appkey
$template->set_transmissionType(2);//透传消息类型
$template->set_transmissionContent($content);//透传内容
//$template->set_title($title); //通知栏标题
//ios
//APN高级推送
$apn = new \IGtAPNPayload();
$alertmsg=new \DictionaryAlertMsg();
$alertmsg->body="body";//通知栏内容
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";//通知栏内容
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
// IOS8.2 支持
$alertmsg->title="Title";//通知栏标题
$alertmsg->titleLocKey="TitleLocKey";//通知栏标题
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn->alertMsg=$alertmsg;
$apn->badge=1;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
$template->set_apnInfo($apn);
return $template;
}
//通知栏显示,点击进入应用
private function IGtNotificationTemplateDemo($title,$content,$ring = true,$vibrate = true){
$template = new \IGtNotificationTemplate();
$template->set_appId(APPID); //应用appid
$template->set_appkey(APPKEY); //应用appkey
$template->set_transmissionType(2); //透传消息类型
//$template->set_transmissionContent($data); //透传内容
$template->set_title($title); //通知栏标题
$template->set_text($content); //通知栏内容
$template->set_logo("logo.png"); //通知栏logo
$template->set_logoURL("http://wwww.igetui.com/logo.png"); //通知栏logo链接
$template->set_isRing($ring); //是否响铃
$template->set_isVibrate($vibrate); //是否震动
$template->set_isClearable(true); //通知栏是否可清除
//ios推送
//$this->push_ios($title,$content);
$apn = new \IGtAPNPayload();
$alertmsg=new \DictionaryAlertMsg();
$alertmsg->body=$content;//通知栏内容
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";//通知栏内容
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
// IOS8.2 支持
$alertmsg->title=$title;//通知栏标题
$alertmsg->titleLocKey="TitleLocKey";//通知栏标题
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn->alertMsg=$alertmsg;
$apn->badge=1;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;//透传数据
$apn->category="ACTIONABLE";
$template->set_apnInfo($apn);
return $template;
}
//ios推送
public function push_ios($title,$content){
$apn = new \IGtAPNPayload();
$alertmsg=new \DictionaryAlertMsg();
$template = new \IGtNotificationTemplate();
$alertmsg->body=$content;//通知栏内容
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";//通知栏内容
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
// IOS8.2 支持
$alertmsg->title=$title;//通知栏标题
$alertmsg->titleLocKey="TitleLocKey";//通知栏标题
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn->alertMsg=$alertmsg;
$apn->badge=1;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;//透传数据
$apn->category="ACTIONABLE";
$template->set_apnInfo($apn);
}
}
|