PHP code example of agileadept / tpns

1. Go to this page and download the library: Download agileadept/tpns library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

agileadept / tpns example snippets


   
       use Agileadept\Tpns\AndroidMessage;
       use Agileadept\Tpns\iOSMessage;
       use Agileadept\Tpns\Message;
       use Agileadept\Tpns\Request;
       use Agileadept\Tpns\Stub;
       use Agileadept\Tpns\Tpns;
       use Agileadept\Tpns\TagItem;
       use Agileadept\Tpns\TagRule;

       //$android = new AndroidMessage;
       //$android->n_ch_id = "chid";
                       
       $ios = new iOSMessage;
       $ios->custom = "{\"key\":\"value\"}";

       $tagItem = new TagItem;
       $tagItem->tags = array("tag1", "tag2");
       $tagItem->tags_operator = Tpns::TAG_OPERATOR_AND;
       $tagItem->items_operator = Tpns::TAG_OPERATOR_OR;
       $tagItem->tag_type = "xg_auto_active";

       $tagRule = new TagRule;
       $tagRule->operator = Tpns::TAG_OPERATOR_OR;
       $tagRule->tag_items = array($tagItem);

       $tpns = new Tpns();                            
       $req = $tpns->NewRequest(
           $tpns->WithAudienceType(Tpns::AUDIENCE_TAG),
           $tpns->WithMessageType(Tpns::MESSAGE_NOTIFY),
           $tpns->WithTitle("this-title"),
           $tpns->WithContent("this-content"),
           //$tpns->WithAndroidMessage($android),
           $tpns->WithIOSMessage($ios),
           $tpns->WithTagRules(array($tagRule)),
           $tpns->WithEnvironment(Tpns::ENVIRONMENT_PROD)
       );
       
       //@parameter: accessId=123456, secretKey="abcdef", host="api.tpns.tencent.com"
       $stub = new Stub(123456, "abcdef", Tpns::GUANGZHOU);
       $result = $stub->Push($req);
       var_dump($result);