作者 lackoxygen

feat:Multi-application

1 <?php 1 <?php
2 2
3 return [ 3 return [
4 - 'app_key' => env('TIKTOK_APP_KEY', ''),  
5 - 'app_secret' => env('TIKTOK_APP_SECRET', ''),  
6 - 'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),  
7 - 'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),  
8 - 'timeout' => env('TIKTOK_TIMEOUT', 30), 4 + 'default' => [
  5 + 'app_key' => env('TIKTOK_APP_KEY', ''), 'app_secret' => env('TIKTOK_APP_SECRET', ''),
  6 + 'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),
  7 + 'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
  8 + 'timeout' => env('TIKTOK_TIMEOUT', 30),
  9 + ]
9 ]; 10 ];
@@ -31,26 +31,34 @@ class TiktokShop @@ -31,26 +31,34 @@ class TiktokShop
31 * @var array|string[] 31 * @var array|string[]
32 */ 32 */
33 protected static array $passages = [ 33 protected static array $passages = [
34 - 'order' => Passage\Order\Order::class,  
35 - 'shop' => Passage\Shop\Shop::class,  
36 - 'product' => Passage\Product\Product::class,  
37 - 'authorize' => Authorize::class,  
38 - 'verify' => Verify::class, 34 + 'order' => Passage\Order\Order::class, 'shop' => Passage\Shop\Shop::class,
  35 + 'product' => Passage\Product\Product::class, 'authorize' => Authorize::class, 'verify' => Verify::class,
39 'alliance' => Alliance::class 36 'alliance' => Alliance::class
40 ]; 37 ];
41 38
42 /** 39 /**
43 - * @param $config 40 + * @param $options
44 */ 41 */
45 - public function __construct($config = null) 42 + public function __construct($options = null)
46 { 43 {
47 - if (!$config instanceof Config) {  
48 - $default = \config(TiktokShopProvider::$name);  
49 - if (!is_array($default)) {  
50 - return; 44 + if (!$options instanceof Config) {
  45 + if (is_array($options)) {
  46 + $config = static::newConfig($options);
  47 + goto next;
51 } 48 }
52 - $config = static::newConfig($default); 49 +
  50 + $app = $options ?: 'default';
  51 +
  52 + $config = \config(TiktokShopProvider::$name.'.'.$app);
  53 +
  54 + if (!is_array($config)) {
  55 + throw new \InvalidArgumentException('config file not found');
  56 + }
  57 + $config = static::newConfig($config);
  58 + } else {
  59 + $config = $options;
53 } 60 }
  61 + next:
54 $this->config = $config; 62 $this->config = $config;
55 } 63 }
56 64