├── .gitignore ├── screenshot ├── screen.png └── screen2.png ├── .gitlab-ci.yml ├── phpunit.xml ├── composer.json ├── .travis.yml ├── tests └── LineNotifyTest.php ├── LICENSE ├── .scrutinizer.yml ├── README.md └── src └── LineNotify.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | build/ 3 | composer.lock 4 | -------------------------------------------------------------------------------- /screenshot/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittinan/php-line-notify/HEAD/screenshot/screen.png -------------------------------------------------------------------------------- /screenshot/screen2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittinan/php-line-notify/HEAD/screenshot/screen2.png -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | before_script: 2 | - composer install --prefer-dist 3 | 4 | job1: 5 | script: 6 | - vendor/bin/phpunit tests/ -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 10 | 11 | ./src/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kittinan/php-line-notify", 3 | "description": "PHP Line Notify", 4 | "keywords": ["line", "line notify"], 5 | "license": "MIT", 6 | "require": { 7 | "php": ">=5.5", 8 | "guzzlehttp/guzzle": ">=6.2.2" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "4.8.12", 12 | "satooshi/php-coveralls": "dev-master" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "KS\\Line\\": "src" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 7.0 4 | - 5.6 5 | - 5.5 6 | 7 | before_script: 8 | - composer install 9 | 10 | script: 11 | - vendor/bin/phpunit ./tests 12 | - mkdir -p build/logs 13 | - vendor/bin/phpunit -c ./phpunit.xml --coverage-clover build/logs/clover.xml ./tests 14 | 15 | after_script: 16 | - php vendor/bin/coveralls -v 17 | - wget https://scrutinizer-ci.com/ocular.phar 18 | - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml -------------------------------------------------------------------------------- /tests/LineNotifyTest.php: -------------------------------------------------------------------------------- 1 | LineNotify = new KS\Line\LineNotify($this->token); 16 | } 17 | 18 | public function testGetToken() { 19 | $result = $this->LineNotify->getToken(); 20 | $this->assertEquals($this->token, $result); 21 | } 22 | 23 | public function testSetToken() { 24 | $token = 'new_token'; 25 | $this->LineNotify->setToken($token); 26 | $result = $this->LineNotify->getToken(); 27 | $this->assertEquals($token, $result); 28 | } 29 | 30 | public function testUrlApi() { 31 | $expected = 'https://notify-api.line.me/api/notify'; 32 | $this->assertEquals($expected, KS\Line\LineNotify::API_URL); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kittinan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | tools: 2 | external_code_coverage: true 3 | filter: 4 | excluded_paths: [tests/*] 5 | checks: 6 | php: 7 | code_rating: true 8 | remove_extra_empty_lines: true 9 | remove_php_closing_tag: true 10 | remove_trailing_whitespace: true 11 | fix_use_statements: 12 | remove_unused: true 13 | preserve_multiple: false 14 | preserve_blanklines: true 15 | order_alphabetically: true 16 | fix_php_opening_tag: true 17 | fix_linefeed: true 18 | fix_line_ending: true 19 | fix_identation_4spaces: true 20 | fix_doc_comments: true 21 | tools: 22 | external_code_coverage: 23 | timeout: 1200 24 | runs: 3 25 | php_analyzer: true 26 | php_code_coverage: false 27 | php_code_sniffer: 28 | config: 29 | standard: PSR2 30 | filter: 31 | paths: ['src'] 32 | php_cpd: 33 | enabled: true 34 | excluded_dirs: [vendor, tests] 35 | php_loc: 36 | enabled: true 37 | excluded_dirs: [vendor, tests] 38 | php_pdepend: true 39 | php_sim: true 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # End of service for LINE Notify 2 | 3 | https://notify-bot.line.me/closing-announce 4 | 5 | --- 6 | 7 | php-line-notify 8 | ======== 9 | [![Build Status](https://travis-ci.org/kittinan/php-line-notify.svg?branch=master)](https://travis-ci.org/kittinan/php-line-notify) 10 | [![Code Coverage](https://scrutinizer-ci.com/g/kittinan/php-line-notify/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/kittinan/php-line-notify/?branch=master) 11 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kittinan/php-line-notify/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kittinan/php-line-notify/?branch=master) 12 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 13 | 14 | Simple PHP Line Notify Class 15 | 16 | [Line Notify Document](https://notify-bot.line.me/doc/en/) 17 | 18 | 19 | 20 | ## Requirement 21 | * PHP 5.5+ 22 | * [guzzlehttp](https://github.com/guzzle/guzzle) 23 | 24 | ## Composer 25 | 26 | Install the latest version with composer 27 | 28 | ``` 29 | composer require kittinan/php-line-notify 30 | ``` 31 | 32 | [https://packagist.org/packages/kittinan/php-line-notify](https://packagist.org/packages/kittinan/php-line-notify) 33 | 34 | ## Generate Line Notify Token 35 | 36 | [https://notify-bot.line.me/my/](https://notify-bot.line.me/my/) 37 | 38 | ## Usage 39 | *Example : notify text message* 40 | ```php 41 | $token = 'YOUR LINE NOTIFY TOKEN'; 42 | $ln = new KS\Line\LineNotify($token); 43 | 44 | $text = 'Hello Line Notify'; 45 | $ln->send($text); 46 | ``` 47 | 48 | *Example : notify text with image* 49 | 50 | ```php 51 | $text = 'Hello Line Notify'; 52 | $image_path = '/YOUR/IMAGE/PATH'; //Line notify allow only jpeg and png file 53 | $ln->send($text, $image_path); 54 | 55 | //HTTP or HTTPS image path 56 | $image_path = 'https://lorempixel.com/800/600/'; //Line notify allow only jpeg and png file 57 | $ln->send($text, $image_path); 58 | 59 | ``` 60 | 61 | *Example : notify text with sticker* 62 | 63 | See sticker list [https://devdocs.line.me/files/sticker_list.pdf](https://devdocs.line.me/files/sticker_list.pdf) 64 | 65 | ```php 66 | $text = 'Hello Sticker'; 67 | $sticker = ['stickerPackageId' => '1', 'stickerId' => '401']; 68 | $ln->send($text, null, $sticker); 69 | ``` 70 | 71 | ## Screenshot 72 | ![Screenshot](/screenshot/screen2.png?raw=true "Screenshot") 73 | 74 | 75 | License 76 | ======= 77 | The MIT License (MIT) 78 | -------------------------------------------------------------------------------- /src/LineNotify.php: -------------------------------------------------------------------------------- 1 | token = $token; 30 | $this->http = new Client(); 31 | } 32 | 33 | /** 34 | * Set token Line notify that want to send message 35 | * 36 | * @param string $token the token of Line notify 37 | */ 38 | public function setToken($token) { 39 | $this->token = $token; 40 | } 41 | 42 | /** 43 | * Get current token Line Notify 44 | * 45 | * @return string the token of Line notify 46 | */ 47 | public function getToken() { 48 | return $this->token; 49 | } 50 | 51 | /** 52 | * Send text message, image or sticker on Line notify 53 | * 54 | * @param string $text text message on Line notify can not be empty 55 | * @param string $imagePath image path you want to send on the local machine 56 | * @param array() $sticker array of line sticker ['stickerPackageId' => PACKAGE_ID, 'stickerId' => STICKER_ID ] 57 | * more info https://devdocs.line.me/files/sticker_list.pdf 58 | * @return boolean success or fail on send Line notify message 59 | */ 60 | public function send($text, $imagePath = null, $sticker = null) { 61 | 62 | if (empty($text)) { 63 | return false; 64 | } 65 | 66 | $request_params = [ 67 | 'headers' => [ 68 | 'Authorization' => 'Bearer ' . $this->token, 69 | ], 70 | ]; 71 | 72 | //Message always required 73 | $request_params['multipart'] = [ 74 | [ 75 | 'name' => 'message', 76 | 'contents' => $text 77 | ] 78 | ]; 79 | 80 | if (!empty($imagePath) && preg_match("#^https?://#", $imagePath)) { 81 | // Remote HTTP / HTTPS image 82 | $request_params['multipart'][] = [ 83 | 'name' => 'imageThumbnail', 84 | 'contents' => $imagePath 85 | ]; 86 | 87 | $request_params['multipart'][] = [ 88 | 'name' => 'imageFullsize', 89 | 'contents' => $imagePath 90 | ]; 91 | 92 | } elseif (!empty($imagePath) && file_exists($imagePath)) { 93 | // Local image 94 | $request_params['multipart'][] = [ 95 | 'name' => 'imageFile', 96 | 'contents' => fopen($imagePath, 'r') 97 | ]; 98 | } 99 | 100 | //https://devdocs.line.me/files/sticker_list.pdf 101 | if (!empty($sticker) 102 | && !empty($sticker['stickerPackageId']) 103 | && !empty($sticker['stickerId'])) { 104 | 105 | $request_params['multipart'][] = [ 106 | 'name' => 'stickerPackageId', 107 | 'contents' => $sticker['stickerPackageId'] 108 | ]; 109 | 110 | $request_params['multipart'][] = [ 111 | 'name' => 'stickerId', 112 | 'contents' => $sticker['stickerId'] 113 | ]; 114 | 115 | } 116 | 117 | $response = $this->http->request('POST', LineNotify::API_URL, $request_params); 118 | 119 | if ($response->getStatusCode() != 200) { 120 | return false; 121 | } 122 | 123 | $body = (string) $response->getBody(); 124 | $json = json_decode($body, true); 125 | if (empty($json['status']) || empty($json['message'])) { 126 | return false; 127 | } 128 | 129 | return true; 130 | } 131 | 132 | } 133 | --------------------------------------------------------------------------------