Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
altwei opened this issue Jun 25, 2022 · 0 comments
Open

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

altwei opened this issue Jun 25, 2022 · 0 comments

Comments

@altwei
Copy link

altwei commented Jun 25, 2022

官方文档
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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant