百度智能云

All Product Document

          Reference

          PHP-SDK Getting Started Guide

          Precondition

          This article aims to help you quickly get the Baidu AI Cloud PHP SDK and start calling.

          Precondition

          Before development, make sure the following prerequisites are ready:

          • The PHP SDK package requires an operating environment of at least PHP 5.3.2.
          • **AK/SK**: AK/SK parameters must be passed in for SDK authentication, and the Access Key and Secret Key can be obtained at Security Authentication Page.

            You can interact with Baidu AI Cloud by two means, including authentication method and anonymous method. For authentication method, you need to verify the identity of a request sender by using Access Key Id / Secret Access Key encryption method. Access Key Id (AK) is used to identify users, and Secret Access Key (SK) is a key used by users to encrypt authentication string and by Baidu AI Cloud to verify the authentication string, where SK must be confidential, which can only be known by users and Baidu AI Cloud.

          Install SDK Package

          1. Download the PHP SDK compression toolkit at Baidu AI Cloud Official Website.
          2. Unzip the ZIP package:

            BaiduBce.phar            //PHP SDK
            BosClientSample.php          //  Example 
            SampleConf.php             //  See configuration file; see below for details 

            Note: After configuring AK/SK and Host, you can run Sample with phpunit --debug BosClientSample.php.

          3. Add the following code to the script file and you can use the SDK package:

            include 'BaiduBce.phar'
            require 'YourConf.php'

            For the reference of the configuration file, please see the configuration client in the PHP SDK help manual of each product.

          SDK's directory structure

          BaiduBce.phar
          ├──src
          │   └── BaiduBce
          │       ├── Auth                //BCE signature related
          │       ├── Exception           //BCE client exception
          │       ├── Http                //BCE's Http communication related 
          │       ├── Log                 // BCE log 
          │       ├── Services
          │       │   └── Bos                   //Take object storage BOS as an example, BOS home directory must be kept 
          │       │       ├── BosClient.php     //BOS operation class, all operations can be completed via BosClient class
          │       │       ├── BosOptions.php    //BOS custom configuration
          │       │       └── CannedAcl.php     //CannedAcl module
          │       └── Util                //BCE utility 
          └──vendor                       // Third-party libraries

          Use PHP SDK

          3 main steps to call PHP SDK:

          • Create and initialize xxxClient. Baidu AI Cloud Service is configured with a detailed PHP SDK help guide. For details, please see the product guide.
          • Create an API request and set parameters.
          • Initiate a request and handle a response or exception.
          Previous
          Java-SDK Getting Started Guide
          Next
          Python-SDK Help Guide