PHP code example of yzw / kabel-sign

1. Go to this page and download the library: Download yzw/kabel-sign library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yzw / kabel-sign example snippets


    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \Kabel\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \Kabel\Middleware\RedirectIfAuthenticated::class,
        'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        // 验证签名
        'verify.sign' => \Kabel\Sign\Middleware\SignMiddleware::class,
    ];

    Route::middleware('verify.sign')->group(function () {
        //需要登录的路由组
    });

    use Kabel\Sign\Services\SignService;
    use Kabel\Interfaces\RpcRequestInterface;
    class test
    {
    
        /**
         * RPC请求类
         * @var RpcRequestInterface
         */
        protected RpcRequestInterface $request;
    
        public function __construct(RpcRequestInterface $request)
        {
            $this->request = $request;
        }
        
        public function test()
        {
           // 发送请求
           $params = ["user_id":1001,"company_id":2];
           $this->request->setApiName($apiName)->uploadFile($apiUri, $fileParams, SignService::setParams($params));       
        }
    }

php artisan vendor:publish --provider="Kabel\Sign\SignServiceProvider"
kabel_sign.php: sign配置文件