当前位置:网站首页>Laravel Aurora push

Laravel Aurora push

2022-06-25 04:52:00 Kiway.

Laravel Aurora push

  • composer Reference Aurora files
    composer require jpush/jpush
    This operation may lead to the problem that the package is not imported , View reasons , Because php.ini Configuration problem of , Or because composer The problem of , When I quote php.ini Of limit Limit impulse of 256MB Changed to -1, then composer require jpush/jpush And then continue composer update once .

Quote it jpush After the package , stay vendor Folder can be found , Put... Directly jpush It's no use throwing folders in , Not through composer require jpush/jpush Set up laravel Many places have not established a good connection with the aurora .

The main code can be written in one file , Then other files can reference this file to call methods .
The code is as follows :

<?php
namespace App\Http\Controllers\Api;
use JPush\Client as JPushClient;
use Illuminate\Http\Request;

class JpushController  extends BaseController
{
    
    public function __construct(){
    
        $this->request = request();
        $this->app_key="****";
        $this->master_secret="*****";
        $this->client=new JPushClient($this->app_key, $this->master_secret);
 
    }
    
 /** =================================================== Calling method =================================================== */
    // obtain alias and tags
    public function getDevices($registrationID){
    
        
        $result = $this->client->device()->getDevices($registrationID);
        return $result;
    }
    // add to tags
    public function addTags($registrationID, $tags){
    
        $result = $this->client->device()->addTags($registrationID,$tags);
        return $result;
    }
 
    // remove tags
    public function removeTags($registrationID, $tags){
    
        $result = $this->client->device()->removeTags($registrationID,$tags);
        return $result;
    }
    // Label push 
    public function push($tag, $alert){
    
        $tags = explode(",", $tag);
        $response = $this->client->push()
                     ->setPlatform(array('ios', 'android'))
                     ->addTag($tags)                          // label 
                     ->setNotificationAlert($alert)           // Content 
                     ->send(); 
        //  Keep a record 
        \DB::table('jpush_msg')->insert([
            'sendno' =>$response['body']['sendno'],
            'msg_id' => $response['body']['msg_id'],
            'http_code' => $response['http_code'],
            'date' => $response['headers']['date'],
            'x-jpush-timestamp'=>$response['headers']['x-jpush-timestamp'],
            'server'=>$response['headers']['server'],
            'type'=>' label '
        ]); 
        return $response;
    }
    
    // Update the alias of the specified device 
    public function updateAlias($reg_id, $alias) {
    
        $response = $this->client->device()->updateAlias($reg_id, $alias);  
        if ($response['http_code'] == 200) {
    
            return $response;
        }
        return false;
    }
    // Alias push 
    // public function aliasPush($alias, $alert){
    
        
    // $alias = explode(",",$alias);
    // $response = $this->client->push()
    // ->setPlatform(array('ios', 'android'))
    // ->addAlias($alias) // Alias 
    // ->setNotificationAlert($alert) // Content 
    // ->send();
    // return $response;
    // }
    public function aliasPush($alias, $alert,$content,$extras){
    
        
        $alias = explode(",",$alias);
        $response = $this->client->push()
                     ->setPlatform(array('ios', 'android'))
                     ->addAlias($alias)                      // Alias 
                    // ->setNotificationAlert($alert) // Content 
                    ->iosNotification(['title' => $alert, 'body' => $content], [
                        'sound' => 'sound',
                        'badge' => '+1',
                        'extras' => $extras,
                        'content-available'=>true,
                        'mutable-content'=>true,
                    ])
                    //Android
                    ->androidNotification($alert, [
                        'title' => $content,
                        'extras' => $extras
                    ])
                    // Whether the production environment 
                    ->options(array(
                        'apns_production' => false, //  development environment   Only on IOS The push of is valid 
                        'time_to_live'=>10000
                    ))
                     ->send();
        //  Keep a record 
        \DB::table('jpush_msg')->insert([
            'sendno' =>$response['body']['sendno'],
            'msg_id' => $response['body']['msg_id'],
            'http_code' => $response['http_code'],
            'date' => $response['headers']['date'],
            'x-jpush-timestamp'=>$response['headers']['x-jpush-timestamp'],
            'server'=>$response['headers']['server'],
            'type'=>' Alias '
        ]);
        return $response;
    }

    public function regidPush($regid, $alert,$content,$extras){
    
        
        // $alias = explode(",",$alias);
        $response = $this->client->push()
                     ->setPlatform(array('ios', 'android'))
                     ->addRegistrationId($regid)                      // Alias 
                    // ->setNotificationAlert($alert) // Content 
                    ->iosNotification(['title' => $alert, 'body' => $content], [
                        'sound' => 'sound',
                        'badge' => '+1',
                        'extras' => $extras,
                        'content-available'=>true,
                        'mutable-content'=>true,
                    ])
                    //Android
                    ->androidNotification($alert, [
                        'title' => $content,
                        'extras' => $extras
                    ])
                    // Whether the production environment 
                    ->options(array(
                        'apns_production' => false, //  development environment   Only on IOS The push of is valid 
                        'time_to_live'=>10000
                    ))
                     ->send();
        //  Keep a record 
        \DB::table('jpush_msg')->insert([
            'sendno' =>$response['body']['sendno'],
            'msg_id' => $response['body']['msg_id'],
            'http_code' => $response['http_code'],
            'date' => $response['headers']['date'],
            'x-jpush-timestamp'=>$response['headers']['x-jpush-timestamp'],
            'server'=>$response['headers']['server'],
            'type'=>' equipment ID'
        ]);
        return $response;
    }

    // notice 
    public function pushNotice($message){
    
        $result = $client->push()
        ->setPlatform('all')
        ->addAllAudience()
        ->setNotificationAlert($message)  // The information you want to push  
        ->send();
        return $result;
    }
 /** =================================================== Calling method =================================================== */
    

}

When I was doing this Aurora push, the main articles I checked were php Aurora push detailed explanation process
You can refer to many experiments , It will be done .

原网站

版权声明
本文为[Kiway.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210533123498.html