├── .editorconfig ├── src ├── Youzan.php ├── config.php ├── YouzanServiceProvider.php └── Manager.php ├── composer.json └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false 10 | 11 | [*.{vue,js,scss}] 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 2 15 | end_of_line = lf 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /src/Youzan.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Overtrue\LaravelYouzan; 13 | 14 | use Illuminate\Support\Facades\Facade; 15 | 16 | /** 17 | * Class Youzan. 18 | * 19 | * @author overtrue 20 | */ 21 | class Youzan extends Facade 22 | { 23 | public static function getFacadeAccessor() 24 | { 25 | return Manager::class; 26 | } 27 | 28 | public static function app($name) 29 | { 30 | return app('youzan')->app($name); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "overtrue/laravel-youzan", 3 | "description": "Youzan wrapper for Laravel.", 4 | "type": "library", 5 | "require": { 6 | "overtrue/youzan": "~1.0" 7 | }, 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "overtrue", 12 | "email": "anzhengchao@gmail.com" 13 | } 14 | ], 15 | "autoload": { 16 | "psr-4": { 17 | "Overtrue\\LaravelYouzan\\": "src/" 18 | } 19 | }, 20 | "extra": { 21 | "laravel": { 22 | "aliases": { 23 | "Youzan": "Overtrue\\LaravelYouzan\\Youzan" 24 | }, 25 | "providers": ["Overtrue\\LaravelYouzan\\YouzanServiceProvider"] 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/config.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | return [ 13 | // Default app name 14 | 'default_app' => 'default', 15 | 16 | // Base configuration 17 | 'base' => [ 18 | 'debug' => true, 19 | ], 20 | 21 | // Applications 22 | 'apps' => [ 23 | 'default' => [ 24 | 'client_id' => 'XXXXXXXXX', 25 | 'client_secret' => 'XXXXXXXXX', 26 | 'kdt_id' => '10000000', // store_id 27 | ], 28 | // 'another_app' => [ 29 | // 'client_id' => 'XXXXXXXXX', 30 | // 'client_secret' => 'XXXXXXXXX', 31 | // 'redirect_uri' => 'http://YOURSITE.com/', 32 | // ], 33 | // 34 | // 'platform_app' => [ 35 | // 'client_id' => '', 36 | // 'client_secret' => '', 37 | // 'type' => \Hanson\Youzan\Youzan::PLATFORM, 38 | // ], 39 | ], 40 | ]; 41 | -------------------------------------------------------------------------------- /src/YouzanServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Overtrue\LaravelYouzan; 13 | 14 | use Illuminate\Support\ServiceProvider; 15 | 16 | /** 17 | * Class YouzanServiceProvider. 18 | */ 19 | class YouzanServiceProvider extends ServiceProvider 20 | { 21 | /** 22 | * @var bool 23 | */ 24 | protected $defer = true; 25 | 26 | public function boot() 27 | { 28 | $this->publishes([ 29 | __DIR__.'/config.php' => config_path('youzan.php'), 30 | ], 'config'); 31 | } 32 | 33 | public function register() 34 | { 35 | $this->app->singleton(Manager::class, function ($app) { 36 | return new Manager(); 37 | }); 38 | 39 | $this->app->alias(Manager::class, 'youzan'); 40 | } 41 | 42 | /** 43 | * @return array 44 | */ 45 | public function provides() 46 | { 47 | return [Manager::class, 'youzan']; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Youzan 2 | 3 | Youzan wrapper for Laravel. 4 | 5 | > 🚧警告!此 SDK 目前仅支持自用型应用,不支持其它类型的应用接入。 由于有赞的不人道的 996 策略,以及在没有通知用户的情况下关闭了个人收款渠道,现决定不再维护他们家任何相关 SDK,谢谢! 6 | 7 | ## Installing 8 | 9 | 1. require package. 10 | ```shell 11 | $ composer require overtrue/laravel-youzan -vvv 12 | ``` 13 | 14 | 2. config you apps 15 | 16 | ```php 17 | $ ./artisan vendor:publish 18 | # select Overtrue\LaravelYouzan\YouzanServiceProvider and enter. 19 | ``` 20 | 21 | Edit the `config/youzan.php` with right content. 22 | 23 | ## Usage 24 | 25 | 1. Use Facade 26 | 27 | ```php 28 | # default app 29 | Youzan::post('youzan.shop.create', ['name' => 'Test store']); 30 | 31 | # specify app name 32 | Youzan::app('pet-store')->get('youzan.trade.get', ['tid' => 'xxxxxxx']); 33 | ``` 34 | 35 | 2. Use `app()` function helper. 36 | 37 | ```php 38 | # default app 39 | app('youzan')->post('youzan.shop.create', ['name' => 'Test store']); 40 | 41 | # specify app name 42 | app('youzan')->app('pet-store')->get('youzan.trade.get', ['tid' => 'xxxxxxx']); 43 | ``` 44 | 45 | [More usage](https://github.com/overtrue/youzan) 46 | 47 | ## PHP 扩展包开发 48 | 49 | > 想知道如何从零开始构建 PHP 扩展包? 50 | > 51 | > 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) 52 | 53 | ## License 54 | 55 | MIT 56 | -------------------------------------------------------------------------------- /src/Manager.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Overtrue\LaravelYouzan; 13 | 14 | use Overtrue\Youzan\Client; 15 | 16 | /** 17 | * Class Manager. 18 | */ 19 | class Manager 20 | { 21 | /** 22 | * Manager constructor. 23 | */ 24 | public function __construct() 25 | { 26 | $baseConfig = config('youzan.base'); 27 | foreach (config('youzan.apps') as $name => $config) { 28 | app()->singleton('youzan.'.$name, function () use ($config, $baseConfig) { 29 | $config = array_merge($baseConfig, $config); 30 | 31 | return new Client($config['client_id'], $config['client_secret'], $config['kdt_id'], $config); 32 | }); 33 | } 34 | } 35 | 36 | /** 37 | * @param string $name 38 | * 39 | * @return \Overtrue\Youzan\Client 40 | */ 41 | public function app(string $name) 42 | { 43 | if (empty(config('youzan.apps.'.$name))) { 44 | throw new Exception(sprintf("No youzan app named '%s' found.", $name)); 45 | } 46 | 47 | return app('youzan.'.$name); 48 | } 49 | 50 | /** 51 | * @param string $method 52 | * @param array $args 53 | * 54 | * @return mixed 55 | */ 56 | public function __call($method, $args) 57 | { 58 | return call_user_func_array([app('youzan.'.config('youzan.default_app')), $method], $args); 59 | } 60 | } 61 | --------------------------------------------------------------------------------