Awesome Open Source
Awesome Open Source

open-sdk-php

Latest Version on Packagist Software License Total Downloads Build Status

YouzanYun SDK

安装

  1. 使用 composer

推荐使用该方式安装, 更优雅

$ composer require youzanyun/open-sdk
  1. 不使用 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.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
php (15,953
php-sdk (15

Find Open Source By Browsing 7,000 Topics Across 59 Categories