yd/ydsdk

There is no license information available for the latest version (v1.0.6) of this package.

YUNDUN SDK

v1.0.6 2020-10-13 08:03 UTC

This package is auto-updated.

Last update: 2024-10-29 05:47:12 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

YUNDUN API PHP SDK legend

  • 接口基地址: 'https://apiv4.yundun.com/V4/';
  • 接口遵循RESTful,默认请求体json,接口默认返回json
  • app_id, app_secret 联系技术客服,先注册一个云盾的账号,用于申请绑定api身份
  • 签名
    • 每次请求都签名,保证传输过程数据不被篡改
    • 客户端:sha256签名算法,将参数base64编码+app_secret用sha256签名,每次请求带上签名
    • 服务端:拿到参数用相同的算法签名,对比签名是否正确
  • 环境要求:php >=5.5
  • 依赖composer

安装

composer require yd/ydsdk

使用

error_reporting(E_ALL);
ini_set('display_errors', 'on');

require './vendor/autoload.php';

try {
    $config = [
        'app_id'       => getenv('SDK_APP_ID'),
        'app_secret'   => getenv('SDK_APP_SECERT'),
        'base_api_url' => getenv('SDK_API_PRE'),
        //'log'          => true,           //是否记录sdk相关日志
        //'logfileLinux' => '/tmp/sdk.log', //linux日志路径
    ];
    $sdk = new \YunDunSdk\YunDunSdk($config);


    // GET 请求
    $request = [
        'url' => 'test.sdk.get',
        'query' => [
            "page" => 1,
            "pagesize" => 10,
            "data" => [
                "name" => "name名称",
                "domain" => "baidu.com",
            ],
        ],
        'body' => [],
    ];
    $result = $sdk->get($request);
    $jsonData = json_decode($result, 1);
    print_r("api: ".$request['url']."\n");
    print_r("raw: ".$result."\n");
    print_r($jsonData);
    print_r("\n");

    // POST 请求
    $request = [
        'url' => 'test.sdk.post',
        'query' => [],
        'body' => [
            "page" => 1,
            "pagesize" => 10,
            "data" => [
                "name" => "name名称",
                "domain" => "baidu.com",
            ],
        ],
    ];
    $result = $sdk->post($request);
    $jsonData = json_decode($result, 1);
    print_r("api: ".$request['url']."\n");
    print_r("raw: ".$result."\n");
    print_r($jsonData);
    print_r("\n");

    // PATCH 请求
    $request = [
        'url' => 'test.sdk.patch',
        'query' => [],
        'body' => [
            "page" => 1,
            "pagesize" => 10,
            "data" => [
                "name" => "name名称",
                "domain" => "baidu.com",
            ],
        ],
    ];
    $result = $sdk->patch($request);
    $jsonData = json_decode($result, 1);
    print_r("api: ".$request['url']."\n");
    print_r("raw: ".$result."\n");
    print_r($jsonData);
    print_r("\n");

    // PUT 请求
    $request = [
        'url' => 'test.sdk.put',
        'query' => [],
        'body' => [
            "page" => 1,
            "pagesize" => 10,
            "data" => [
                "name" => "name名称",
                "domain" => "baidu.com",
            ],
        ],
    ];
    $result = $sdk->put($request);
    $jsonData = json_decode($result, 1);
    print_r("api: ".$request['url']."\n");
    print_r("raw: ".$result."\n");
    print_r($jsonData);
    print_r("\n");

    // DELETE 请求
    $request = [
        'url' => 'test.sdk.delete',
        'query' => [],
        'body' => [
            "page" => 1,
            "pagesize" => 10,
            "data" => [
                "name" => "name名称",
                "domain" => "baidu.com",
            ],
        ],
    ];
    $result = $sdk->delete($request);
    $jsonData = json_decode($result, 1);
    print_r("api: ".$request['url']."\n");
    print_r("raw: ".$result."\n");
    print_r($jsonData);
} catch(\Exception $e) {
    var_dump("code: " + $e->getCode() + " message: " + $e->getMessage());
}

demo 获取友情链接,如果可以获取到数据,说明api接口可以调通

curl http://apiv4.yundun.com/V4/site.friendlink