├── config └── serverchan.php ├── src ├── SevenFacade.php ├── SevenServiceProvider.php └── SevenService.php ├── composer.json └── README.md /config/serverchan.php: -------------------------------------------------------------------------------- 1 | env('SCKEY',"") 10 | ]; -------------------------------------------------------------------------------- /src/SevenFacade.php: -------------------------------------------------------------------------------- 1 | publishes([ 19 | __DIR__.'/../config/serverchan.php' => config_path('serverchan.php'), 20 | ], 'serverchan'); 21 | } 22 | 23 | public function register() 24 | { 25 | $this->mergeConfigFrom( __DIR__.'/../config/serverchan.php', 'serverchan'); 26 | 27 | $this->app->singleton('serverchan', function ($app) { 28 | 29 | $config = $app->make('config'); 30 | 31 | $SCKEY = $config->get('serverchan.SCKEY'); 32 | 33 | return new SevenService($SCKEY); 34 | }); 35 | } 36 | 37 | public function provides() { 38 | return ['serverchan']; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Easy Laravel Package for ServerChan 2 | 3 | See [Server酱](http://sc.ftqq.com/3.version) 4 | 5 | ## Quick Start Guide 6 | 7 | - Create a Laravel 5.5 project: `composer create-project laravel/laravel myproject dev-develop` 8 | 9 | - `cd myproject` 10 | 11 | - Add dependency: `composer require sevenshi/serverchan` 12 | 13 | - Copy configuration: `php artisan vendor:publish` 14 | 15 | - set the SCKEY you get from the serverchan on the .env `SCKEY=SCU17044T7eafa406fxxxxxxxxxx` 16 | 17 | Now you are ready to use the Seven Facade, e.g. open routes/web.php: 18 | 19 | 20 | - send message to yourself 21 | 22 | ``` PHP 23 | setMessage('hello world')->push(); 26 | 27 | 28 | ``` 29 | 30 | - send message to who subscribe your channel 31 | 32 | the channel comes from the [PushBear](http://pushbear.ftqq.com/admin/#/),and channel key comes from the channel you create 33 | 34 | ``` PHP 35 | setMessage('hello every body')->setChannel('4794-e28b9dae54e86365773xxx')->pushbear(); 39 | 40 | 41 | ``` 42 | 43 | - response 44 | 45 | 46 | if the request is ok,it will response these data below: 47 | 48 | push: 49 | 50 | - success {"errno":0,"errmsg":"success","dataset":"done"} 51 | 52 | pushbear: 53 | 54 | - {"code":0,"message":"","data":"1\u6761\u6d88\u606f\u5df2\u6210\u529f\u63a8\u9001\u5230\u53d1\u9001\u961f\u5217","created":"2018-07-18 14:43:05"} 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/SevenService.php: -------------------------------------------------------------------------------- 1 | sckey = $sckey; 24 | } 25 | 26 | public function setTitle($text){ 27 | $this->text = $text; 28 | return $this; 29 | } 30 | 31 | public function setMessage($desp) 32 | { 33 | $this->desp = $desp; 34 | return $this; 35 | } 36 | 37 | public function setChannel($channel) 38 | { 39 | $this->channel = $channel; 40 | return $this; 41 | } 42 | 43 | 44 | public function push() 45 | { 46 | $postdata = http_build_query( 47 | array( 48 | 'text' => $this->text, 49 | 'desp' => $this->desp 50 | ) 51 | ); 52 | 53 | $opts = array('http' => 54 | array( 55 | 'method' => 'POST', 56 | 'header' => 'Content-type: application/x-www-form-urlencoded', 57 | 'content' => $postdata 58 | ) 59 | ); 60 | 61 | $context = stream_context_create($opts); 62 | 63 | return $result = file_get_contents('https://sc.ftqq.com/'.$this->sckey.'.send', false, $context); 64 | } 65 | 66 | public function pushbear() 67 | { 68 | $postdata = http_build_query( 69 | array( 70 | 'text' => $this->text, 71 | 'desp' => $this->desp, 72 | 'sendkey'=>$this->channel 73 | ) 74 | ); 75 | 76 | $opts = array('http' => 77 | array( 78 | 'method' => 'POST', 79 | 'header' => 'Content-type: application/x-www-form-urlencoded', 80 | 'content' => $postdata 81 | ) 82 | ); 83 | 84 | $context = stream_context_create($opts); 85 | 86 | return $result = file_get_contents('https://pushbear.ftqq.com/sub', false, $context); 87 | } 88 | } 89 | 90 | --------------------------------------------------------------------------------