jpush / jpush-api-php-client

JPush's officially supported PHP client library for accessing JPush APIs. 极光推送官方支持的 PHP 版本服务器端 SDK。
https://docs.jiguang.cn
MIT License
523 stars 174 forks source link

推送 API 上缺少 “推送撤销”功能 #95

Open altwei opened 2 years ago

altwei commented 2 years ago

官方文档 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#%E6%8E%A8%E9%80%81%E6%92%A4%E9%94%80

我自己的解决方案 ,注意自己处理命名空间,还要修改 key 和 密钥

Aurora.php

<?php

namespace xxx

use InvalidArgumentException;
use JPush\Client;
use JPush\Http;

class Aurora {

    const APP_KEY = 'xxx';
    const MASTER_SECRET = 'xxx';

    protected static $client;

    /**
     * 推送撤销
     * @param $msgId
     * @return array
     */
    public static function cancelMessage($msgId)
    {
        if (!is_string($msgId)) {
            throw new InvalidArgumentException('Invalid msg id');
        }
        $url = Aurora::getClient()->makeURL('push') . 'push/' . $msgId;

        return Http::delete(Aurora::getClient(), $url);
    }

    /**
     * @return Client
     */
    public static function getClient()
    {
        if (self::$client === null) {
            self::$client = new Client(self::APP_KEY, self::MASTER_SECRET);
        }
        return self::$client;
    }
}