├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .php-cs-fixer.php ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src └── EasySmsServiceProvider.php └── tests ├── FeatureTest.php ├── TestCase.php └── User.php /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | phpcs: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Setup PHP environment 15 | uses: shivammathur/setup-php@v2 16 | - name: Install dependencies 17 | run: composer install 18 | - name: PHPCSFixer check 19 | run: composer check-style 20 | phpunit: 21 | strategy: 22 | matrix: 23 | php_version: [8.0, 8.1] 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - name: Setup PHP environment 28 | uses: shivammathur/setup-php@v2 29 | with: 30 | php-version: ${{ matrix.php_version }} 31 | coverage: xdebug 32 | - name: Install dependencies 33 | run: composer install 34 | - name: PHPUnit check 35 | run: ./vendor/bin/phpunit --coverage-text 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /vendor/ 3 | composer.lock 4 | .php_cs.cache 5 | /coverage/ 6 | .phpunit.result.cache 7 | .php-cs-fixer.cache -------------------------------------------------------------------------------- /.php-cs-fixer.php: -------------------------------------------------------------------------------- 1 | setRules([ 5 | '@PSR12' => true, 6 | 'binary_operator_spaces' => true, 7 | 'blank_line_after_opening_tag' => true, 8 | 'compact_nullable_typehint' => true, 9 | 'declare_equal_normalize' => true, 10 | 'lowercase_cast' => true, 11 | 'lowercase_static_reference' => true, 12 | 'new_with_braces' => true, 13 | 'no_blank_lines_after_class_opening' => true, 14 | 'no_leading_import_slash' => true, 15 | 'no_whitespace_in_blank_line' => true, 16 | 'no_unused_imports' => true, 17 | 'ordered_class_elements' => [ 18 | 'order' => [ 19 | 'use_trait', 20 | ], 21 | ], 22 | 'ordered_imports' => [ 23 | 'imports_order' => [ 24 | 'class', 25 | 'function', 26 | 'const', 27 | ], 28 | 'sort_algorithm' => 'none', 29 | ], 30 | 'return_type_declaration' => true, 31 | 'short_scalar_cast' => true, 32 | 'single_blank_line_before_namespace' => true, 33 | 'single_trait_insert_per_statement' => true, 34 | 'ternary_operator_spaces' => true, 35 | 'unary_operator_spaces' => true, 36 | 'visibility_required' => [ 37 | 'elements' => [ 38 | 'const', 39 | 'method', 40 | 'property', 41 | ], 42 | ], 43 | ]) 44 | ->setFinder( 45 | PhpCsFixer\Finder::create() 46 | ->exclude('vendor') 47 | ->in([__DIR__.'/src/', __DIR__.'/tests/']) 48 | ) 49 | ; 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 overtrue 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel EasySMS 2 | 3 | [overtrue/easy-sms](https://github.com/overtrue/easy-sms) service provider for Laravel. 4 | 5 | ![Laravel Octane Ready Status](https://img.shields.io/badge/Octance-ready-green?style=flat-square) 6 | ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/overtrue/laravel-easy-sms?style=flat-square) 7 | ![GitHub License](https://img.shields.io/github/license/overtrue/laravel-easy-sms?style=flat-square) 8 | ![Packagist Downloads](https://img.shields.io/packagist/dt/overtrue/laravel-easy-sms?style=flat-square) 9 | 10 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue) 11 | 12 | ## Installing 13 | 14 | ```shell 15 | $ composer require overtrue/laravel-easy-sms 16 | ``` 17 | 18 | ## Usage 19 | 20 | _config/services.php_ 21 | 22 | ```php 23 | 'easy-sms' => [ 24 | // HTTP 请求的超时时间(秒) 25 | 'timeout' => 5.0, 26 | 27 | // 默认发送配置 28 | 'default' => [ 29 | // 网关调用策略,默认:顺序调用 30 | 'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class, 31 | 32 | // 默认可用的发送网关 33 | 'gateways' => [ 34 | 'yunpian', 'aliyun', 35 | ], 36 | ], 37 | // 可用的网关配置 38 | 'gateways' => [ 39 | 'errorlog' => [ 40 | 'file' => '/tmp/easy-sms.log', 41 | ], 42 | 'yunpian' => [ 43 | 'api_key' => env('EASY_SMS_YUNPIAN_API_KEY'), 44 | ], 45 | 'aliyun' => [ 46 | 'access_key_id' => env('EASY_SMS_ALIYUN_KEY_ID'), 47 | 'access_key_secret' => env('EASY_SMS_ALIYUN_API_KEY'), 48 | 'sign_name' => '', 49 | ], 50 | //... 51 | ], 52 | ], 53 | ``` 54 | 55 | Send a message: 56 | 57 | ```php 58 | app('easy-sms')->send(13188888888, [ 59 | 'content' => '您的验证码为: 6379', 60 | 'template' => 'SMS_001', 61 | 'data' => [ 62 | 'code' => 6379 63 | ], 64 | ]); 65 | ``` 66 | 67 | [More...](https://github.com/overtrue/easy-sms) 68 | 69 | ## Contributing 70 | 71 | You can contribute in one of three ways: 72 | 73 | 1. File bug reports using the [issue tracker](https://github.com/overtrue/laravel-easy-sms/issues). 74 | 2. Answer questions or fix bugs on the [issue tracker](https://github.com/overtrue/laravel-easy-sms/issues). 75 | 3. Contribute new features or update the wiki. 76 | 77 | _The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._ 78 | 79 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue) 80 | 81 | ## Project supported by JetBrains 82 | 83 | Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects. 84 | 85 | [![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue) 86 | 87 | ## PHP 扩展包开发 88 | 89 | > 想知道如何从零开始构建 PHP 扩展包? 90 | > 91 | > 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) 92 | 93 | ## License 94 | 95 | MIT 96 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "overtrue/laravel-easy-sms", 3 | "description": "overtrue/easy-sms service provider for Laravel.", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "overtrue", 8 | "email": "anzhengchao@gmail.com" 9 | } 10 | ], 11 | "require": { 12 | "laravel/framework": "^9.0|^10.0|^11.0|^12.0", 13 | "overtrue/easy-sms": "^2.0" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "Overtrue\\LaravelEasySms\\": "src" 18 | } 19 | }, 20 | "autoload-dev": { 21 | "psr-4": { 22 | "Tests\\": "tests" 23 | } 24 | }, 25 | "require-dev": { 26 | "mockery/mockery": "^1.2", 27 | "phpunit/phpunit": "^9.0", 28 | "orchestra/testbench": "^7.0", 29 | "friendsofphp/php-cs-fixer": "^3.0" 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "providers": [ 34 | "\\Overtrue\\LaravelEasySms\\EasySmsServiceProvider" 35 | ] 36 | }, 37 | "hooks": { 38 | "pre-commit": [ 39 | "composer test", 40 | "composer check-style" 41 | ], 42 | "pre-push": [ 43 | "composer test", 44 | "composer check-style" 45 | ] 46 | } 47 | }, 48 | "scripts": { 49 | "post-update-cmd": [ 50 | "cghooks update" 51 | ], 52 | "post-merge": "composer install", 53 | "post-install-cmd": [ 54 | "cghooks add --ignore-lock", 55 | "cghooks update" 56 | ], 57 | "cghooks": "vendor/bin/cghooks", 58 | "check-style": "php-cs-fixer fix --using-cache=no --diff --dry-run --ansi", 59 | "fix-style": "php-cs-fixer fix --using-cache=no --ansi", 60 | "test": "vendor/bin/phpunit --colors=always" 61 | }, 62 | "scripts-descriptions": { 63 | "test": "Run all tests.", 64 | "check-style": "Run style checks (only dry run - no fixing!).", 65 | "fix-style": "Run style checks and fix violations." 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | src/ 6 | 7 | 8 | 9 | 10 | ./tests/ 11 | vendor 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/EasySmsServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->bind(EasySms::class, function () { 19 | return new EasySms(\config('services.easy-sms')); 20 | }); 21 | 22 | $this->app->alias(EasySms::class, 'easy-sms'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/FeatureTest.php: -------------------------------------------------------------------------------- 1 | User::class]); 19 | } 20 | 21 | public function test_basic_features() 22 | { 23 | $this->assertTrue(true); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | set('database.default', 'testing'); 28 | $app['config']->set('database.connections.testing', [ 29 | 'driver' => 'sqlite', 30 | 'database' => ':memory:', 31 | 'prefix' => '', 32 | ]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/User.php: -------------------------------------------------------------------------------- 1 |