vanthao03596 / laravel-ghtk
这是我创建的包 LaravelGhtk
Requires
- php: ^7.3|^8.0
- graham-campbell/manager: ^4.5
- illuminate/contracts: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
- vanthao03596/ghtk-sdk: ^0.0.2
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- http-interop/http-factory-guzzle: ^1.0
- mockery/mockery: ^1.4.1
- nunomaduro/collision: ^3.0|^5.3
- orchestra/testbench: ^4.8|^5.2|^6.0
- phpunit/phpunit: ^9.3
README
要获取最新版本,只需使用 Composer 需求此项目。您需要安装任何提供 psr/http-client-implementation 和 psr/http-factory-implementation 的包。大多数用户会想要
例如,要使用 Guzzle 7
$ composer require "vanthao03596/laravel-ghtk" "guzzlehttp/guzzle:^7.2" "http-interop/http-factory-guzzle:^1.1.0"
安装后,如果您没有使用自动包发现,则需要将 Vanthao03596\LaravelGhtk\GhtkServiceProvider 服务提供者注册到您的 config/app.php 文件中。
您还可以选择性地为我们的外观
'Ghtk' => Vanthao03596\LaravelGhtk\Facades\Ghtk::class,
配置
Laravel GHTK 需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将创建一个您可以在其中修改以设置配置的 config/ghtk.php 文件。另外,请确保检查此包中原始配置文件之间的更改。
有两个配置选项
默认连接名称
此选项('default')是您指定以下哪个连接作为您所有工作的默认连接的地方。当然,您可以使用管理器类同时使用多个连接。此设置的默认值是 'main'。
Ghtk 连接
此选项('connections')是您为应用程序设置的每个连接。已包括示例配置,但您可以添加您想要的任何数量的连接。
用法
GhtkManager
这是最有趣的类。它绑定到 ioc 容器为 'ghtk',并可以使用 Facades\Ghtk 外观访问。该类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是我 Laravel Manager 包的一部分,因此您可能想去查看有关如何使用管理器类的文档在这个存储库中。请注意,返回的连接类始终是 Vanthao03596\GhtkSdk\Client 的实例。
Facades\Ghtk
此外观将动态地将静态方法调用传递到 ioc 容器中的 'ghtk' 对象,默认情况下是 GhtkManager 类。
GhtkServiceProvider
此类不包含任何有趣的公共方法。应将此类添加到 config/app.php 中的提供者数组。此类将设置 ioc 绑定。
实际示例
在这里,您可以看到如何使用此包的示例。默认情况下,默认适配器是 main。在配置文件中输入您的认证详细信息后,它就会正常工作
use Vanthao03596\LaravelGhtk\Facades\Ghtk; // you can alias this in config/app.php if you like Ghtk::shipment() ->calculateFee([ 'pick_province' => 'Hà Nội', 'pick_district' => 'Quận Hai Bà Trưng', 'province' => 'Hà nội', 'district' => 'Quận Cầu Giấy', 'address' => 'P.503 tòa nhà Auu Việt, số 1 Lê Đức Thọ', 'weight' => 1000, 'value' => 3000000, 'transport' => 'fly', 'deliver_option' => 'xteam', 'tags' => [1] ]); // we're done here - how easy was that, it just works! Ghtk::order()->createOrder([ 'products' => [ [ 'name' => 'bút', 'weight' => 0.1, 'quantity' => 1, 'product_code' => '23304A3MHLMVMXX625' ], [ 'name' => 'tẩy', 'weight' => 0.2, 'quantity' => 1, 'product_code' => '' ] ], 'order' => [ 'id' => 'a9', 'pick_name' => 'HCM-nội thành', 'pick_address' => '590 CMT8 P.11', 'pick_province' => 'TP. Hồ Chí Minh', 'pick_district' => 'Quận 3', 'pick_ward' => 'Phường 1', 'pick_tel' => '0911222333', 'tel' => '0911222333', 'name' => 'GHTK - HCM - Noi Thanh', 'address' => '123 nguyễn chí thanh', 'province' => 'TP. Hồ Chí Minh', 'district' => 'Quận 1', 'ward' => 'Phường Bến Nghé', 'hamlet' => 'Khác', 'is_freeship' => 1, 'pick_date' => '2016-09-30', 'pick_money' => 47000, 'note' => 'Khối lượng tính cước tối đa: 1.00 kg', 'value' => 3000000, 'transport' => 'fly', 'pick_option' =>'cod', 'deliver_option' => 'xteam', 'pick_session' => '2', 'tags' => [ 1], 'email' => 'thao@123.com', 'use_return_address' => 1 ] ]); // this example is simple, and there are far more methods available
ghtk 管理器将表现得像 Vanthao03596\GhtkSdk\Client 类。如果您想调用特定的连接,可以使用 connection 方法
use Vanthao03596\LaravelGhtk\Facades\Ghtk; // select the your_connection_name connection, then get going Ghtk::connection('your_connection_name')shipment() ->calculateFee([ 'pick_province' => 'Hà Nội', 'pick_district' => 'Quận Hai Bà Trưng', 'province' => 'Hà nội', 'district' => 'Quận Cầu Giấy', 'address' => 'P.503 tòa nhà Auu Việt, số 1 Lê Đức Thọ', 'weight' => 1000, 'value' => 3000000, 'transport' => 'fly', 'deliver_option' => 'xteam', 'tags' => [1] ]);
考虑到这一点,请注意
use Vanthao03596\LaravelGhtk\Facades\Ghtk; // writing this: Ghtk::connection('main')->order()->checkStatus('S1.A1.17373471'); // is identical to writing this: Ghtk::order()->checkStatus('S1.A1.17373471'); // and is also identical to writing this: Ghtk::connection()->order()->checkStatus('S1.A1.17373471'); // this is because the main connection is configured to be the default Ghtk::getDefaultConnection(); // this will return main // we can change the default connection Ghtk::setDefaultConnection('alternative'); // the default is now alternative
如果您像我一样更喜欢使用依赖注入而不是外观,则可以轻松地将管理器注入如下
use Vanthao03596\LaravelGhtk\GhtkManager; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $ghtk; public function __construct(GhtkManager $ghtk) { $this->ghtk = $ghtk; } public function bar() { $this->ghtk->order()->checkStatus('S1.A1.17373471'); } } App::make('Foo')->bar();
有关如何使用我们幕后调用的 Vanthao03596\GhtkSdk\Client 类的更多信息,请参阅https://github.com/vanthao03596/ghtk-sdk 上的文档,以及https://github.com/GrahamCampbell/Laravel-Manager#usage 上的管理类。
测试
composer test
变更日志
有关最近更改的详细信息,请参阅CHANGELOG。
贡献
有关详细信息,请参阅CONTRIBUTING。
安全漏洞
请查阅我们的安全策略了解如何报告安全漏洞。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。