public function createPushMessage($p, $i, $t, $c){
$template = new \IGtTransmissionTemplate();
$template->set_appId($this->appid);//应用appid
$template->set_appkey($this->appkey);//应用appkey
$template->set_transmissionType(1);//透传消息类型:1为激活客户端启动
//为了保证应用切换到后台时接收到个推在线推送消息,转换为{title:'',content:'',payload:''}格式数据,UniPush将在系统通知栏显示
//如果开发者不希望由UniPush处理,则不需要转换为上述格式数据(将触发receive事件,由应用业务逻辑处理)
//注意:iOS在线时转换为此格式也触发receive事件
$payload = array('title'=>$t, 'content'=>$c);
$pj = json_decode($p, TRUE);
$payload['payload'] = is_array($pj)?$pj:$p;
//$template->set_transmissionContent(json_encode($payload));//透传内容
$template->set_transmissionContent(json_encode($payload));//透传内容
$inde = new \NotifyInfo_type();
//兼容使用厂商通道传输
$notify = new \IGtNotify();
$notify->set_title($t);
$notify->set_content($c);
$notify->set_intent($i);
$notify->set_type($inde::_intent);
$template->set3rdNotifyInfo($notify);
//iOS平台设置APN信息,如果应用离线(不在前台运行)则通过APNS下发推送消息
/*$apn = new \IGtAPNPayload();
$apn->alertMsg = new \DictionaryAlertMsg();
$apn->alertMsg->body = $c;
$apn->add_customMsg('payload', is_array($pj)?json_encode($pj):$p);//payload兼容json格式字符串
$template->set_apnInfo($apn);*/
//个推老版本接口: $template ->set_pushInfo($actionLocKey,$badge,$message,$sound,$payload,$locKey,$locArgs,$launchImage);
//$template->set_pushInfo('', 0, $c, '', $p, '', '', '');
return $template;
}
/**
- 单推接口示例
- @param $template: 推送的消息模板
-
@param $cid: 推送的客户端标识
*/
public function pushMessageToSingle($template, $cid){
// 创建推送对象
$igt = new \IGeTui($this->host,$this->appkey,$this->mastersecret);//个推信息体 $message = new \IGtSingleMessage(); $message->set_isOffline(true);//是否离线 $message->set_offlineExpireTime(3600*12*1000);//离线时间 $message->set_data($template);//设置推送消息类型
// $message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//接收方
$target = new \IGtTarget();
$target->set_appId($this->appid);
$target->set_clientId($cid);
// $target->set_alias(Alias);try { $rep = $igt->pushMessageToSingle($message, $target); var_dump($rep); }catch(RequestException $e){ $requstId =e.getRequestId(); $rep = $igt->pushMessageToSingle($message, $target, $requstId); var_dump($rep); }
}
self::pushMessageToSingle(self::createPushMessage($payload,$intent,$title,$content), $cid);
set_transmissionType设置为1 是客户端启动不了 手机小米8 离线消息
可以收到
1 个回复
2***@qq.com (作者) - 兰陵笑笑生
有没有哪位大佬帮忙看看 是哪里写错了