mmbang gexin push driver


License
MIT

Documentation

个信推送驱动SDK(基于个推v1.2.0)

使用说明

Composer安装

require: {
    "mmbang/gexin-push": "dev-master"
}

工厂创建消息实例

$PushFactory = new \Mmbang\Gexin\PushFactory(array(
    'appid' => 'xxx',
    'appkey' => 'xxxx'
));

// 点开通知打开应用
$notification = $PushFactory->notification;

// 点开通知打开网页
$link = $PushFactory->link;

// 点开通知弹窗下载
$notypopload = $PushFactory->notypopload;

// 透传
$transmission = $PushFactory->transmission;

场景实例

// 以alias方式推送
$title = 'xxxx';
$text = 'xxx';
$aliasOrCidValue = 'CID-VALUE';
$aliasOrCidType = 'alias';
$result = $notification
            ->pushSingle($title, $text, $aliasOrCidValue, $aliasOrCidType)
            ->receive();

// 以alias方式同时推送多个cid
$aliasOrCidValue1 = 'CID-VALUE1';
$aliasOrCidValue2 = 'CID-VALUE2';
$result = $notification
            ->pushSingle($title, $text, $aliasOrCidValue1, $aliasOrCidType)
            ->pushSingle($title, $text, $aliasOrCidValue2, $aliasOrCidType)
            ->receive();

// 失败重试
if ($result['pushSingle'] === false) {
    $result = $notification->retryPush('pushSingle');
}

NOTE: 以下接口调用默认均以点开通知打开应用

鉴权

$mastersecret = 'xxxx';
$notification = $notification->authSign($mastersecret);

关闭鉴权

$notification = $notification->authClose();

单推

Notification:

调用原型:

pushSingle($title, $text, $aliasOrCidValue, $aliasOrCidType = 'cid', array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$aliasOrCidValue = 'this is cid value';
$result = $notification->pushSingle($title, $text, $url, $aliasOrCidValue)->receive();

Transmission:

调用原型:

pushSingle($transmissionContent, $aliasOrCidValue, $aliasOrCidType = 'cid', array $extra = array());

Demo:

$transmissionContent = 'Transmission content';
$aliasOrCidValue = 'this is cid value';
$result = $transmission->pushSingle($transmissionContent, $aliasOrCidValue)->receive();

Link:

调用原型:

pushSingle($title, $text, $url, $aliasOrCidValue, $aliasOrCidType = 'cid', array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$url = 'http://www.example.com/demo.html';
$aliasOrCidValue = 'this is cid value';
$result = $transmission->pushSingle($title, $text, $url, $aliasOrCidValue)->receive();

Notypopload:

调用原型:

pushSingle(array $mustParams, $aliasOrCidValue, $aliasOrCidType = 'cid', $extra = array());

Demo:

$mustParams = array(
    'notyicon' => 'http://notyicon/icon.png',
    'notytitle' => 'noty title',
    'notycontent' => 'noty content',
    'poptitle' => 'pop title',
    'popcontent' => 'pop content',
    'popimage' => 'http://notyimage/icon.jpg',
    'popbutton1' => 'pop button 1',
    'popbutton2' => 'pop button 2',
    'loadurl' => 'http://loadurl/demo.html'
);
$aliasOrCidValue = 'this is cid value';
$result = $notypopload->pushSingle($mustParams, $aliasOrCidValue)->receive();

保存消息公共体

Notification:

调用原型:

saveListBody($title, $text, array $extra = array(), $offlineExpireTime = 10000000);

Demo:

$title = 'push title';
$text = 'push text';
$result = $notification->pushSingle($title, $text)->receive();

Transmission:

调用原型:

saveListBody($transmissionContent, array $extra = array(), $offlineExpireTime = 10000000);

Demo:

$transmissionContent = 'Transmission content';
$result = $transmission->pushSingle($transmissionContent)->receive();

Link:

调用原型:

saveListBody($title, $text, $url, array $extra = array(), $offlineExpireTime = 10000000);

Demo:

$title = 'push title';
$text = 'push text';
$url = 'http://www.example.com/demo.html';
$result = $transmission->pushSingle($title, $text, $url)->receive();

Notypopload:

调用原型:

saveListBody(array $mustParams, array $extra = array(), $offlineExpireTime = 10000000);

Demo:

$mustParams = array(
    'notyicon' => 'http://notyicon/icon.png',
    'notytitle' => 'noty title',
    'notycontent' => 'noty content',
    'poptitle' => 'pop title',
    'popcontent' => 'pop content',
    'popimage' => 'http://notyimage/icon.jpg',
    'popbutton1' => 'pop button 1',
    'popbutton2' => 'pop button 2',
    'loadurl' => 'http://loadurl/demo.html'
);
$result = $notypopload->pushSingle($mustParams)->receive();

tolist群推

调用原型:

pushList($aliasOrCidValue, $taskid, $aliasOrCidType = 'cid', $needDetail = true);

Demo:

$cid = 'xxx';
$taskid = 'xxx'; // 任务号,取save_list_body返回的taskid
$aliasOrCidValue = 'this is cid value';
$result = $notification->pushList($cid, $taskid, $aliasOrCidValue)->receive();

toapp群推

Notification:

调用原型:

pushApp($title, $text, array $condition, array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$conditon = array(
    array(
        'phonetype' => array("ANDROID"),
    ),
    array(
        'tag' => array("meishi", "yumaoqiu"),
        'opt_type' => 1 // meishi and yumaoqiu
    )
);
$result = $notification->pushApp($title, $text, $conditon)->receive();

Transmission:

调用原型:

pushApp($transmissionContent, array $condition, array $extra = array());

Demo:

$transmissionContent = 'Transmission content';
$conditon = array(
    array(
        'phonetype' => array("ANDROID"),
    ),
    array(
        'tag' => array("meishi", "yumaoqiu"),
        'opt_type' => 1 // meishi and yumaoqiu
    )
);
$result = $transmission->pushSingle($transmissionContent, $conditon)->receive();

Link:

调用原型:

pushApp($title, $text, $url, array $condition, array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$url = 'http://www.example.com/demo.html';
$conditon = array(
    array(
        'phonetype' => array("ANDROID"),
    ),
    array(
        'tag' => array("meishi", "yumaoqiu"),
        'opt_type' => 1 // meishi and yumaoqiu
    )
);
$result = $transmission->pushSingle($title, $text, $url, $conditon)->receive();

Notypopload:

调用原型:

pushApp(array $mustParams, array $condition, array $extra = array());

Demo:

$mustParams = array(
    'notyicon' => 'http://notyicon/icon.png',
    'notytitle' => 'noty title',
    'notycontent' => 'noty content',
    'poptitle' => 'pop title',
    'popcontent' => 'pop content',
    'popimage' => 'http://notyimage/icon.jpg',
    'popbutton1' => 'pop button 1',
    'popbutton2' => 'pop button 2',
    'loadurl' => 'http://loadurl/demo.html'
);
$conditon = array(
    array(
        'phonetype' => array("ANDROID"),
    ),
    array(
        'tag' => array("meishi", "yumaoqiu"),
        'opt_type' => 1 // meishi and yumaoqiu
    )
);
$result = $notypopload->pushSingle($mustParams, $conditon)->receive();

stop群推任务

$taskid = 'xxx'; // 任务号,取save_list_body返回的taskid
$notification = $notification->stopTask($taskid);

批量单推接口

Notification:

调用原型:

pushSingleBatch($title, $text, $aliasOrCidValue, $aliasOrCidType = 'cid', array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$aliasOrCidValue = 'this is cid value';
$result = $notification->pushSingleBatch($title, $text, $aliasOrCidValue)->receive();

Transmission:

调用原型:

pushSingleBatch($transmissionContent, $cid, array $extra = array());

Demo:

$transmissionContent = 'Transmission content';
$cid = 'this is cid value';
$result = $transmission->pushSingleBatch($transmissionContent, $cid)->receive();

Link:

调用原型:

pushSingleBatch($title, $text, $url, $cid, array $extra = array());

Demo:

$title = 'push title';
$text = 'push text';
$url = 'http://www.example.com/demo.html';
$cid = 'this is cid value';
$result = $transmission->pushSingleBatch($title, $text, $url, $cid)->receive();

Notypopload:

调用原型:

pushSingleBatch(array $mustParams, $cid, array $extra = array());

Demo:

$mustParams = array(
    'notyicon' => 'http://notyicon/icon.png',
    'notytitle' => 'noty title',
    'notycontent' => 'noty content',
    'poptitle' => 'pop title',
    'popcontent' => 'pop content',
    'popimage' => 'http://notyimage/icon.jpg',
    'popbutton1' => 'pop button 1',
    'popbutton2' => 'pop button 2',
    'loadurl' => 'http://loadurl/demo.html'
);
$cid = 'this is cid value';
$result = $notypopload->pushSingleBatch($mustParams, $cid)->receive();

APNS单推消息

$deviceToken = 'xxx';
$pushInfo = array(
    "aps" => array(
        "alert" => array(
            "title" => "xxx",
            "body" => ""
        )
    )
);
$notification = $notification->pushApnsSingle($deviceToken, $pushInfo);

上传APNS群推消息体

$pushInfo = array(
    "aps" => array(
        "alert" => array(
            "title" => "xxx",
            "body" => ""
        )
    )
);
$notification = $notification->saveApnsListBody($pushInfo);

APNS群推消息

$deviceTokens = array('xxx', 'xxxx');
$taskid = 'xxx'; // 任务号,取save_list_body返回的taskid
$notification = $notification->pushApnsList($deviceTokens, $taskid);

cid绑定别名

$aliasList = array('xxx');
$notification = $notification->bindAlias($aliasList);

别名查询cid

$alias = 'xxx';
$notification = $notification->queryCid($alias);

cid查询别名

$cid = 'xxx';
$notification = $notification->queryAlias($cid);

单个cid和别名解绑

$cid = 'xxx';
$alias = 'xxx';
$notification = $notification->unbindAlias($cid, $alias);

解绑别名所有cid

$alias = 'xxx';
$notification = $notification->unbindAliasAll($alias);

对指定用户设置tag属性

$cid = 'xxx';
$tagList = array('xxx');
$notification = $notification->setTags($cid, $tagList);

查询指定用户tag属性

$cid = 'xxx';
$notification = $notification->getTags($cid);

添加黑名单用户

$cid = 'xxx';
$notification = $notification->userBlkList($cid, $method = 'post');

移除黑名单用户

$cid = 'xxx';
$notification = $notification->userBlkList($cid, $method = 'delete');

查询用户状态

$cid = 'xxx';
$notification = $notification->userStatus($id);

获取推送结果接口

$cid = 'xxx';
$notification = $notification->pushResult();

获取单日用户数据接口

$date = 'xxx'; // 格式:yyyyMMdd
$notification = $notification->queryAppUser($date);

获取单日推送数据接口

$date = 'xxx'; // 格式:yyyyMMdd
$notification = $notification->queryAppPush($date);

应用角标设置接口(仅IOS)

$msgid = 'xxx';
$cidList = array('xxx');
$devicetokenList = array('xxx');
$badge = 10;
$notification = $notification->setBadge($msgid, $cidList, $devicetokenList, $badge);

根据任务组名获取推送结果数据

$groupName = 'xxxx';
$notification = $notification->getPushResultByGroupName($groupName);

获取24小时在线用户数

$groupName = 'xxxx';
$notification = $notification->getLast24hoursOnlineUserStatistics();

按条件查询用户数

$conditon = array(
    'phonetype' => array("ANDROID"),
    'opt_type' => 0
);
$notification = $notification->queryUserCount($conditon);

获取可用bi标签

$notification = $notification->queryBiTags();