| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | <?phpnamespace App\Console\Commands\Push;use App\Libs\Push\XMPush\Builder;use App\Libs\Push\XMPush\Constants;use App\Libs\Push\XMPush\Message;use App\Libs\Push\XMPush\Sender;use App\Libs\Push\XMPush\Stats;use App\Libs\Push\XMPush\TargetedMessage;use App\Libs\Push\XMPush\Tracer;use Illuminate\Console\Command;class MiPushTest extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'push:mi:test';    /**     * The console command description.     *     * @var string     */    protected $description = 'Command description';    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()    {        $secret  = 'W0OBbzwRFYE2qfqqzdxV7A==';        $package = 'com.beidao.kuaiying.zsy';        // 常量设置必须在new Sender()方法之前调用        Constants::setPackage($package);        Constants::setSecret($secret);        $aliasList = array('alias1', 'alias2');        $title     = '测试标题22';        $desc      = '这是一条mipush推送消息22';        $payload   = '{"test":1,"ok":"It\'s a string"}';        $sender = new Sender();        // message1 演示自定义的点击行为        $message1 = new Builder();        $message1->title($title);  // 通知栏的title        $message1->description($desc); // 通知栏的descption        $message1->passThrough(0);  // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数        $message1->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。        $message1->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0        $message1->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存        $message1->build();        $targetMessage = new TargetedMessage();        $targetMessage->setTarget('alias1', TargetedMessage::TARGET_TYPE_ALIAS); // 设置发送目标。可通过regID,alias和topic三种方式发送        $targetMessage->setMessage($message1);        // message2 演示预定义点击行为中的点击直接打开app行为        $message2 = new Builder();        $message2->title($title);        $message2->description($desc);        $message2->passThrough(0);        $message2->payload($payload); // 对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。        $message2->extra(Builder::notifyEffect, 1); // 此处设置预定义点击行为,1为打开app        $message2->extra(Builder::notifyForeground, 1);        $message2->notifyId(0);        $message2->build();        $targetMessage2 = new TargetedMessage();        $targetMessage2->setTarget('alias2', TargetedMessage::TARGET_TYPE_ALIAS);        $targetMessage2->setMessage($message2);        $targetMessageList = array($targetMessage, $targetMessage2);        print_r($sender->send($message1, 'yeCXNzRSIiqLPfeoejM4gaLlpz3Tm8zyOctN+wFx0v6U73mTud4cYEJhEDyCEQrC')->getRaw());        //print_r($sender->multiSend($targetMessageList, TargetedMessage::TARGET_TYPE_ALIAS)->getRaw());        // print_r($sender->sendToAliases($message1, $aliasList)->getRaw());        $stats     = new Stats();        $startDate = '20200727';        $endDate   = '20200728';        // print_r($stats->getStats($startDate, $endDate)->getRaw());        //$tracer = new Tracer();        //print_r($tracer->getMessageStatusById('sdm58749595907489079Yl')->getRaw());    }}
 |