laravel jpush

composer require jpush/jpush

新建 config/jpush.php 文件

<?php
return [
    'appKey' =>env('JPUSH_APP_KEY', 'AppKey'),
    'masterSecret' =>env('JPUSH_MASTER_SECRET', 'Master Secret')
];

php artisan make:controller JPushController –resource

Route::resource(‘jpush’, ‘JPushController’);

use JPush\Client as JPush;

$jpush = new JPush(config(‘jpush.appKey’), config(‘jpush.masterSecret’));
$response = $jpush->push()
->setPlatform(‘all’)
->addRegistrationId(‘190e35f7e0007dd42b0’)
->setNotificationAlert(‘hello tp3.2’)
->options([‘apns_production’=>true])//这句很重要,开发和生产版本通知切换,之前遇的坑。
->send();
print_r($response);

问题:laravel ios jpush 无法收到推送,web端正常,api不成功。

options 的 apns_production 要为true。见上方代码。

laravel openssl_cipher_iv_length()

laravel 错误

Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()

phpinfo()

OpenSSL support disabled (install ext/openssl)

下载https://windows.php.net/downloads/php-sdk/deps/vc15/x64/openssl-1.1.1a-vc15-x64.zip

解压后bin目录能看到libcrypto-1_1-x64.dll和libssl-1_1-x64.dll,两个文件都拷到php目录和apache的bin下

开启extension=openssl

重启Apache就好了

laravel5.7 passport

composer require laravel/passport
php artisan migrate
php artisan passport:install

app/User.php

<?php

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

app/Providers/AuthServiceProvider.php

<?php

namespace App\Providers;

use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        Passport::routes();
    }
}

config/auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],