GithubHelp home page GithubHelp logo

qcloudapi-sdk-php's Introduction

qcloudapi-sdk-php

qcloudapi-sdk-php是为了让PHP开发者能够在自己的代码里更快捷方便的使用腾讯云的API而开发的SDK工具包。

更新历史

  • [12/30] 添加CDN模块

资源

入门

  1. 申请安全凭证。 在第一次使用云API之前,用户首先需要在腾讯云网站上申请安全凭证,安全凭证包括 SecretId 和 SecretKey, SecretId 是用于标识 API 调用者的身份,SecretKey是用于加密签名字符串和服务器端验证签名字符串的密钥。SecretKey 必须严格保管,避免泄露。

  2. 下载SDK,放入到您的程序目录。 使用方法请参考下面的例子。

例子

<?php
require_once './src/QcloudApi/QcloudApi.php';

$config = array('SecretId'       => '你的secretId',
                'SecretKey'      => '你的secretKey',
                'RequestMethod'  => 'GET',
                'DefaultRegion'  => '区域参数');

// 第一个参数表示使用哪个域名
// 已有的模块列表:
// QcloudApi::MODULE_CVM      对应   cvm.api.qcloud.com
// QcloudApi::MODULE_CDB      对应   cdb.api.qcloud.com
// QcloudApi::MODULE_LB       对应   lb.api.qcloud.com
// QcloudApi::MODULE_TRADE    对应   trade.api.qcloud.com
// QcloudApi::MODULE_SEC      对应   csec.api.qcloud.com
// QcloudApi::MODULE_IMAGE    对应   image.api.qcloud.com
// QcloudApi::MODULE_MONITOR  对应   monitor.api.qcloud.com
// QcloudApi::MODULE_CDN      对应   cdn.api.qcloud.com
$service = QcloudApi::load(QcloudApi::MODULE_CVM, $config);

// 请求参数,请参考wiki文档上对应接口的说明
$package = array('offset' => 0,
                 'limit' => 3,
                 // 'Region' => 'gz' // 当Region不是上面配置的DefaultRegion值时,可以重新指定请求的Region
                );


// 请求前可以通过下面四个方法重新设置请求的secretId/secretKey/region/method参数
// 重新设置secretId
$secretId = '你的secretId';
$service->setConfigSecretId($secretId);
// 重新设置secretKey
$secretKey = '你的secretKey';
$service->setConfigSecretKey($secretKey);
// 重新设置region
$region = 'sh';
$service->setConfigDefaultRegion($region);
// 重新设置method
$method = 'POST';
$service->setConfigRequestMethod($method);

// 请求方法为对应接口的接口名,请参考wiki文档上对应接口的接口名
$a = $service->DescribeInstances($package);

// 生成请求的URL,不发起请求
$a = $service->generateUrl('DescribeInstances', $package);

if ($a === false) {
    // 请求失败,解析错误信息
    $error = $service->getError();
    echo "Error code:" . $error->getCode() . ' message:' . $error->getMessage();

    // 对于异步任务接口,可以通过下面的方法获取对应任务执行的信息
    $detail = $error->getExt();
} else {
    // 请求成功
    var_dump($a);
}

qcloudapi-sdk-php's People

Contributors

qcloudapi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.