极光推送
This commit is contained in:
parent
4c847f2668
commit
1a81f8baee
|
@ -54,3 +54,7 @@ JWT_SECRET=
|
||||||
# 单位分钟
|
# 单位分钟
|
||||||
JWT_TTL=60
|
JWT_TTL=60
|
||||||
JWT_REFRESH_TTL=20160
|
JWT_REFRESH_TTL=20160
|
||||||
|
|
||||||
|
#极光推送
|
||||||
|
JPUSH_KEY=
|
||||||
|
JPUSH_SECRET=
|
|
@ -35,7 +35,7 @@ class UsersController extends Controller
|
||||||
public function update(UserRequest $request)
|
public function update(UserRequest $request)
|
||||||
{
|
{
|
||||||
$user = $this->user();
|
$user = $this->user();
|
||||||
$attributes = $request->only(['name', 'email', 'introduction']);
|
$attributes = $request->only(['name', 'email', 'introduction', 'registration_id']);
|
||||||
if ($request->get('avatar_image_id')) {
|
if ($request->get('avatar_image_id')) {
|
||||||
$image = Image::find($request['avatar_image_id']);
|
$image = Image::find($request['avatar_image_id']);
|
||||||
$attributes['avatar'] = $image->path;
|
$attributes['avatar'] = $image->path;
|
||||||
|
|
|
@ -54,6 +54,7 @@ class UserRequest extends FormRequest
|
||||||
'verification_key' => '短信验证码 key',
|
'verification_key' => '短信验证码 key',
|
||||||
'verification_code' => '短信验证码',
|
'verification_code' => '短信验证码',
|
||||||
'introduction' => '个人简介',
|
'introduction' => '个人简介',
|
||||||
|
'registration_id' => '设备id'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
app/Listeners/PushNotification.php
Normal file
48
app/Listeners/PushNotification.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\DatabaseNotification;
|
||||||
|
use JPush\Client;
|
||||||
|
|
||||||
|
class PushNotification implements ShouldQueue
|
||||||
|
{
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
* @param Client $client
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param DatabaseNotification $notification
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(DatabaseNotification $notification)
|
||||||
|
{
|
||||||
|
if (app()->environment('local')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $notification->notifiable;
|
||||||
|
|
||||||
|
if (!$user->registration_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 推送消息
|
||||||
|
$this->client->push()
|
||||||
|
->setPlatform('all')
|
||||||
|
->addRegistrationId($user->registration_id)
|
||||||
|
->setNotificationAlert(strip_tags($notification->data['reply_content']))
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,7 +39,7 @@ class User extends Authenticatable implements JWTSubject
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'phone', 'email', 'password', 'introduction', 'avatar ',
|
'name', 'phone', 'email', 'password', 'introduction', 'avatar ',
|
||||||
'weixin_openid', 'weixin_unionid',
|
'weixin_openid', 'weixin_unionid', 'registration_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,9 @@ class EventServiceProvider extends ServiceProvider
|
||||||
// add your listeners (aka providers) here
|
// add your listeners (aka providers) here
|
||||||
'SocialiteProviders\Weixin\WeixinExtendSocialite@handle'
|
'SocialiteProviders\Weixin\WeixinExtendSocialite@handle'
|
||||||
],
|
],
|
||||||
|
'eloquent.created: Illuminate\Notifications\DatabaseNotification' => [
|
||||||
|
'App\Listeners\PushNotification',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
33
app/Providers/JpushServiceProvider.php
Normal file
33
app/Providers/JpushServiceProvider.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use JPush\Client;
|
||||||
|
|
||||||
|
class JpushServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->singleton(Client::class, function ($app) {
|
||||||
|
return new Client(config('jpush.key'), config('jpush.secret'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->app->alias(Client::class, 'jpush');
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
"guzzlehttp/guzzle": "~6.3",
|
"guzzlehttp/guzzle": "~6.3",
|
||||||
"hieu-le/active": "~3.5",
|
"hieu-le/active": "~3.5",
|
||||||
"intervention/image": "^2.4",
|
"intervention/image": "^2.4",
|
||||||
|
"jpush/jpush": "^3.6",
|
||||||
"laravel/framework": "5.5.*",
|
"laravel/framework": "5.5.*",
|
||||||
"laravel/horizon": "~1.0",
|
"laravel/horizon": "~1.0",
|
||||||
"laravel/tinker": "~1.0",
|
"laravel/tinker": "~1.0",
|
||||||
|
|
45
composer.lock
generated
45
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "32f207e4a0d2ec61b4710f12c6b34d6d",
|
"content-hash": "e838c10d6726e4e4ac83fcfec83bc9d7",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "cakephp/chronos",
|
"name": "cakephp/chronos",
|
||||||
|
@ -1456,6 +1456,49 @@
|
||||||
],
|
],
|
||||||
"time": "2015-04-20T18:58:01+00:00"
|
"time": "2015-04-20T18:58:01+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "jpush/jpush",
|
||||||
|
"version": "v3.6.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/jpush/jpush-api-php-client.git",
|
||||||
|
"reference": "a2250612a33ced6c3e565eb9807089b693111154"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/jpush/jpush-api-php-client/zipball/a2250612a33ced6c3e565eb9807089b693111154",
|
||||||
|
"reference": "a2250612a33ced6c3e565eb9807089b693111154",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-curl": "*",
|
||||||
|
"php": ">=5.3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"JPush\\": "src/JPush/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "JPush",
|
||||||
|
"email": "support@jpush.cn",
|
||||||
|
"homepage": "https://www.jpush.cn/",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "JPush API PHP Client",
|
||||||
|
"homepage": "https://github.com/jpush/jpush-api-php-client",
|
||||||
|
"time": "2018-05-30T02:28:58+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/framework",
|
"name": "laravel/framework",
|
||||||
"version": "v5.5.40",
|
"version": "v5.5.40",
|
||||||
|
|
|
@ -178,7 +178,7 @@ return [
|
||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
|
|
||||||
App\Providers\EasySmsServiceProvider::class,
|
App\Providers\EasySmsServiceProvider::class,
|
||||||
|
App\Providers\JpushServiceProvider::class
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
12
config/jpush.php
Normal file
12
config/jpush.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: xing
|
||||||
|
* Date: 2018/6/16
|
||||||
|
* Time: 9:51
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'key' => env('JPUSH_KEY'),
|
||||||
|
'secret' => env('JPUSH_SECRET'),
|
||||||
|
];
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddRegistrationIdToUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('registration_id')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('registration_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user