步骤:
1在激光网上注册账号创建应用(包名要是你的appcan自定义包名)
2.激光网创建好的应用有一个推送设置点击设置进入设置页 下面有一个推送设置点击完成设置
3.下载设置完成后的demo
4.解压完成后哪里有一个src文件夹和autoload.php把他们放到你的后台文件那
5.进行前台的标签,别名等设置 在appcan的文档上有实例代码
6. PHP封装的类
header("content-type:text/html;charset=utf-8");
use JPush\Client as JPush;
class Common {
//极光推送appkey
static public function app_key(){
$app_key = "14c88ed2b8f84**6f44924"; 极光申请的appkey
return $app_key;
}
//极光推送master_secret
static public function master_secret(){
$master_secret = "990d9df9***3cbcdc5163ed";极光申请的master
return $master_secret;
}
//获取alias和tags
public function getDevices($registrationID){
require 'JPush/autoload.php'; //这是我的引用路径
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
$result = $client->device()->getDevices($registrationID);
return $result;
}
//添加tags
public function addTags($registrationID,$tags){
require 'JPush/autoload.php';
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
$result = $client->device()->addTags($registrationID,$tags);
return $result;
}
//移除tags
public function removeTags($registrationID,$tags){
require 'JPush/autoload.php';
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
$result = $client->device()->removeTags($registrationID,$tags);
return $result;
}
//标签推送
public function push($tag,$alert){
require 'JPush/autoload.php';
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
$tags = implode(",",$tag);
$client->push()
->setPlatform(array('ios', 'android'))
->addTag($tags) //标签
->setNotificationAlert($alert) //内容
->send();
}
//别名推送
public function push_a($alias,$alert){
require 'JPush/autoload.php';
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
//$alias = implode(",",$alias);
foreach($alias as $v){
$client->push()
->setPlatform(array('ios', 'android'))
->addAlias($v) //别名
->setNotificationAlert($alert) //内容
->send();
}
}
}
?>
7、调用方法
$common = new Common();
$tag = array(
"a00"
);
$alert = $mesg;
$result=$common->push($tag,$alert);
echo json_encode($result);