haistar / shopee-php-sdk
Shopee 开放API的PHP SDK
v3.1.1
2023-04-07 13:14 UTC
Requires
- guzzlehttp/guzzle: ^6.5 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^7
- vlucas/phpdotenv: ^5.3
README
这是一个Shopee PHP客户端,目前支持在 Shopee开放平台 中的 API V2
Composer 安装
composer require haistar/shopee-php-sdk
使用方法
$shopeeClient = new ShopApiClient();
$apiConfig = new ShopeeApiConfig();
$apiConfig->setPartnerId((int) $_ENV["SHOPEE_PARTNER_ID"]);
$apiConfig->setShopId((int) $_ENV["SHOPEE_SHOP_ID"]);
$apiConfig->setAccessToken($_ENV["SHOPEE_ACCESS_TOKEN"]);
$apiConfig->setSecretKey($_ENV["SHOPEE_SECRET_KEY"]);
$baseUrl = "https://partner.test-stable.shopeemobile.com";
$apiPath = "/api/v2/product/get_item_list";
$params = array();
$productList = $shopeeClient->httpCallGet($baseUrl, $apiPath, $params, $apiConfig);
运行测试
composer test
运行所有测试
对于laravel 8
运行 composer require haistar/shopee-php-sdk
然后 composer update
添加到 .Env 文件中
SHOPEE_PARTNER_ID={partner_id}
SHOPEE_SHOP_ID= {shop_id}
SHOPEE_ACCESS_TOKEN={access_token}
SHOPEE_SECRET_KEY={partner_key}
在控制器上添加
use Haistar\ShopeePhpSdk\request\shop\ShopApiClient;
use Haistar\ShopeePhpSdk\client\ShopeeApiConfig;
尝试
public function index()
{
$shopeeClient = new ShopApiClient();
$apiConfig = new ShopeeApiConfig();
$apiConfig->setPartnerId((int) $_ENV["SHOPEE_PARTNER_ID"]);
$apiConfig->setShopId((int) $_ENV["SHOPEE_SHOP_ID"]);
$apiConfig->setAccessToken($_ENV["SHOPEE_ACCESS_TOKEN"]);
$apiConfig->setSecretKey($_ENV["SHOPEE_SECRET_KEY"]);
$baseUrl = "https://partner.test-stable.shopeemobile.com";
$apiPath = "/api/v2/product/get_item_list";
$params = ["offset"=>0,"item_status"=>"NORMAL","page_size" => 10,];
$productList = $shopeeClient->httpCallGet($baseUrl, $apiPath, $params, $apiConfig);
return response()->json($productList);
}