当前位置:网站首页>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 .
边栏推荐
- What if the desktop computer is not connected to WiFi
- Le chemin de l'apprentissage immutable - - Adieu à la copie traditionnelle
- 绝了!自动点赞,我用 PyAutoGUI!
- 融合CDN,为客户打造极致服务体验!
- Kotlin Compose 监听软键盘 点击enter提交事件
- Construction scheme of distributed websocket
- 小白一键重装官网下载使用方法
- 「 每日一练,快乐水题 」1108. IP 地址无效化
- 渗透测试-目录遍历漏洞
- 基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
猜你喜欢

领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!

In Net 6 using dotnet format formatting code

Upgrade PHP to php7 The impact of X (I). The problem of session retention. Keep login

绝了!自动点赞,我用 PyAutoGUI!

Teach you to write non maintainable PHP code step by step

Vscode 设置clang-format

Upgrade PHP to php7 The impact of X (2), the obsolescence of mcrypt decryption

ROS2/DDS/QoS/主题的记录

JS' sort() function

WPF uses Maui's self drawing logic
随机推荐
Machine learning deep learning -- Vectorization
OLAP analysis engine kylin4.0
halcon之区域:多种区域(Region)生成(3)
初识 Flutter 的绘图组件 — CustomPaint
Virtual honeypot Honeyd installation and deployment
Integrate CDN to create the ultimate service experience for customers!
Chapter IX app project test (2) test tools
How PHP gets the user's City
Excel exports data to SQL and pictures to folder through macro | VBA
【FLink】access closed classloader classloader. check-leaked-classloader
本轮压力测试下,DeFi协议们表现如何?
Vscade setting clang format
Separation of storage and computing in Dahua cloud native database
At the age of 30, I began to learn programming by myself. Is it still time for me to have difficulties at home?
Upgrade PHP to php7 The impact of X (2), the obsolescence of mcrypt decryption
Why PHP is not safe
File upload vulnerability shooting range upload labs learning (pass1-pass5)
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
Record of the 25th week
ThinkPHP 5 log management