写app推送后台时,需要用到第三方极光Jpush推送,看了官网api,实现了极光推送,定时推送,修改和删除推送功能,主要代码如下,都是亲测可用的。并且推送可以实现跳转到指定页面,这个只需要我们在调用极光推送接口时,带上想要带的参数,如下面代码addAndroidNotification中的nid。
//立即推送 $result = $this->client->push() ->setPlatform($system) ->addTag('资讯news123123') ->setNotificationAlert($content) ->addAndroidNotification($content, $title, 1, array("nid" => $nid)) ->addIosNotification($content, 'iOS sound', +1, true, 'iOS category', array("nid" => $nid)) ->setMessage("msg content", 'msg title', 'type', array("nid" => $nid)) ->setOptions(100000, 3600, null, false) ->send();
//定时推送 $payload = $this->client->push() ->setPlatform($system) ->addAllAudience() ->setNotificationAlert($content) ->build(); $response = $this->client->schedule() ->createSingleSchedule("定时任务" . $nowid, $payload, array("time" => $releasetime . ' ' . $releasetimes));
$this->client->schedule()-> updateSingleSchedule($pushid, '定时任务', true, $payload, array("time" => $releasetime . ' ' . $releasetimes));
$this->client->schedule()->deleteSchedule($pushid);
注:附上stdclass转化array方法,你会需要的
$arr = json_decode(json_encode($response), True);
通过以上方法,可以实现极光定时推送,修改和删除功能,以及推送跳转指定页面的功能。