__construct()
__construct() : void
Class constructor
Model Class
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Order Controller
* 推送控制器
*/
use JPush\Client as JPush;
class Push_model extends CI_Model {
public function __construct(){
$this->isNeedLogin = TRUE;
parent::__construct();
// $this->load->config('alipay_config',TRUE);
$this->load->model('Webcommon_model', 'common');
$this->load->model('sign_model','sign');
$this->load->model('Rechargepoints_model','recharge');
$this->load->model('My_model','My_model');
require_once(APPPATH.'libraries/jpush/autoload.php');
}
//极光推送appkey
static public function app_key(){
$app_key = "97b5e45424af767f83b06dab";
return $app_key;
}
//极光推送master_secret
static public function master_secret(){
$master_secret = "7e4ebd822b367b56d04ef721";
return $master_secret;
}
//获取alias和tags
public function getDevices($registrationID){
// require_once APP_PATH . '/../extend/jpush/autoload.php';
require_once(APPPATH.'libraries/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_once APP_PATH . '/../extend/jpush/autoload.php';
require_once(APPPATH.'libraries/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_once APP_PATH . '/../extend/jpush/autoload.php';
require_once(APPPATH.'libraries/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(){
require_once(APPPATH.'libraries/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'))
->addAllAudience()
// ->addTag($tags) //标签
->setNotificationAlert('推送') //内容
->send();
}
//别名推送
public function push_a($alias='353',$alert='别名推送'){
require_once(APPPATH.'libraries/jpush/autoload.php');
$app_key = $this->app_key();
$master_secret = $this->master_secret();
$client = new JPush($app_key, $master_secret);
// $alias['0'] = '353';
// $alias[1] =321;
// $alias = implode(",",$alias);
// echo $alias;exit;
$client->push()
->setPlatform(array('ios', 'android'))
->addAlias($alias) //别名
->setNotificationAlert($alert) //内容
->send();
}
}