极光php后端,极光推送 PHP后端

步骤:

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值