zhuxiaojin / zx-yz-sdk
有赞云服务端SDK
v1.0
2021-03-03 10:14 UTC
Requires
- ext-curl: *
- ext-json: *
- ext-openssl: *
- guzzlehttp/guzzle: ^6.3|^7.0
This package is not auto-updated.
Last update: 2025-03-28 01:38:15 UTC
README
YouzanYun SDK
安装
- 使用
composer
推荐使用该方式安装, 更优雅
$ composer require youzanyun/open-sdk
- 不使用
composer
管理
如果你的项目不使用composer
管理, 可以直接下载 Release包 并解压, 然后在项目中添加如下代码:
require_once '/YOUR_SDK_PATH/youzanyun-open-sdk/open-sdk/vendor/autoload.php';
请注意, 需要下载的是最新的 youzanyun-open-sdk.zip
压缩包, 而不是 Source code
压缩包, YOUR_SDK_PATH
需更改为项目实际路径.
使用
详情参考 examples
1. 获取及刷新access_token
工具型应用 获取access_token
require_once './vendor/autoload.php'; $clientId = "YOUR_CLIENT_ID"; $clientSecret = "YOUR_CLIENT_SECRET"; $resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getToolAppToken('YOUR_CODE'); var_dump($resp);
自用型应用 获取access_token
require_once './vendor/autoload.php'; $clientId = "YOUR_CLIENT_ID"; $clientSecret = "YOUR_CLIENT_SECRET"; // 1. 不获取refresh_token $resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getSelfAppToken('YOUR_KDT_ID'); var_dump($resp); // 2. 获取refresh_token $config['refresh'] = true; //是否获取refresh_token(可通过refresh_token刷新token) $resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getSelfAppToken('YOUR_KDT_ID', $config); var_dump($resp);
工具型应用及自用型应用 刷新access_token
require_once './vendor/autoload.php'; $clientId = "YOUR_CLIENT_ID"; $clientSecret = "YOUR_CLIENT_SECRET"; $resp = (new \Youzan\Open\Token($clientId, $clientSecret))->refreshToken('YOUR_REFRESH_TOKEN'); var_dump($resp);
2. 接口调用
Token方式
require_once './vendor/autoload.php'; $accessToken = 'YOUR_TOKEN'; $client = new \Youzan\Open\Client($accessToken); $method = 'youzan.item.get'; $apiVersion = '3.0.0'; $params = [ 'alias' => 'fa8989ad342k', ]; $response = $client->post($method, $apiVersion, $params); var_dump($response);
免鉴权方式 (仅支持免鉴权接口)
require_once './vendor/autoload.php'; $client = new \Youzan\Open\Client(); $method = 'youzan.item.get'; $apiVersion = '3.0.0'; $params = [ 'alias' => 'fa8989ad342k', ]; $response = $client->post($method, $apiVersion, $params); var_dump($response);
3. 加密消息解密
参考 examples/crypto/decrypt.php
License
The MIT License. Please see License File for more information.