thinkphp5个推SDK

发布时间 2023-04-07 09:50:21作者: zhang_you_wu

首先先下载个推官方的sdk

直接在根目录下

composer require getuilaboratory/getui-pushapi-php-client-v2

如果报错请用

composer require getuilaboratory/getui-pushapi-php-client-v2 dev-master

下载以后文件会在vendor目录下

 composer下完以后,直接new \GTClient这样引用就行,

  public function pushToSingleByCids(){
        //创建API,APPID等配置参考 环境要求 进行获取
        $api = new \GTClient("https://restapi.getui.com","你的APPKEY", "你的APPID","你的MASTERSECRET");
        //设置推送参数
        $push = new \GTPushRequest();
        $push->setRequestId($this->micro_time());
        $message = new \GTPushMessage();
        $notify = new \GTNotification();
        $notify->setTitle("123");
        $notify->setBody("456");
        //点击通知后续动作,目前支持以下后续动作:
        //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
        $notify->setClickType("none");
        $message->setNotification($notify);
        $push->setPushMessage($message);
        $push->setCid("前段传来的clientId");
        //处理返回结果
        $result = $api->pushApi()->pushToSingleByCid($push);
    }
    public function micro_time()
    {
        list($usec, $sec) = explode(" ", microtime());
        $time = ($sec . substr($usec, 2, 3));
        return $time;
    }