百度智能云

All Product Document

          Elastic IP

          Initialization

          Confirm Endpoint

          When confirming the Endpoint configured when using SDK, you can read the part in API reference regarding API Service Domain Name, and understand Endpoint related concept. Baidu AI Cloud enables multi-region support currently, please see the description of Region Selection.

          The corresponding information is:

          Access region Corresponding Endpoint
          Beijing eip.bj.baidubce.com
          Guangzhou eip.gz.baidubce.com
          Suzhou eip.su.baidubce.com
          HongKong eip.hkg.baidubce.com
          WuHan eip.fwh.baidubce.com
          BaoDing eip.bd.baidubce.com

          Get the Key

          To use Baidu AI Cloud EIP, you need to have a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK is assigned by the system to users, both of which are strings, used to identify users, and perform signature authentication for accessing EIP. You can obtain and understand your AK/SK information through the following steps: Register Baidu AI Cloud Account Create AK/SK

          Create EipClient/EipGroupClient/EipBpClient

          EipClient/EipGroupClient/EipBpClient is the PHP client of Eip/EipGroup/EipBp service and provides a series of methods for developers to interact with PHP client services of Eip/EipGroup/EipBp services.

          Before creating EipClient/EipGroupClient/EipBpClient, you need to create a configuration file to configure EipClient/EipGroupClient/EipBpClient, and in the following, the configuration file is named as YourConf.php, and the specific configuration information is as follows:

          // Report all PHP errors 
          error_reporting(-1);
          
          define('__EIP_CLIENT_ROOT', dirname(__DIR__));
          
          // Set access Key ID, Secret Access Key and ENDPOINT of EipClient 
          $EIP_TEST_CONFIG =
              array(
                  'credentials' => array(
                      'accessKeyId' => 'your ak',
                      'secretAccessKey' => 'your sk',
                      'sessionToken' => 'your session token'
                  ),
                  'endpoint' => 'http://eip.bj.baidubce.com',
                  'stsEndpoint' => 'http://sts.bj.baidubce.com',
              );
          
          // Set format and level of log 
          $__handler = new \Monolog\Handler\StreamHandler(STDERR, \Monolog\Logger:DEBUG);
          $__handler->setFormatter(
              new \Monolog\Formatter\LineFormatter(null, null, false, true)
          );
          \BaiduBce\Log\LogFactory:setInstance(
              new \BaiduBce\Log\MonoLogFactory(array($__handler))
          );
          \BaiduBce\Log\LogFactory:setLogLevel(\Psr\Log\LogLevel:DEBUG);

          Note:

          1.In the codes above, accessKeyId corresponds to "Access Key ID" in the console, secretAccessKey corresponds to "Access Key Secret" in the console, for the way of obtaining, please see "Operation Guideline Manage ACCESSKEY".
          2.If you need to specify the domain name by yourself, you can specify it by introducing ENDPOINT parameter, which needs to be defined with the domain name of specified region, for example, if the service region is Beijing, the domain name is http://eip.bj.baidubce.com.
          3.If STS verification mode is not used, stsEndpoint and sessionToken can be null or deleted.

          Create EipClient/EipGroupClient/EipBpClient with AK/SK

          Access to EIP via AK/SK, and you can create an EipClient by reference to the following codes.

          // Use PHP SDK, and use customized configuration file. 
          include 'BaiduBce.phar';
          require 'YourConf.php';
          
          use BaiduBce\BceClientConfigOptions;
          use BaiduBce\Util\Time;
          use BaiduBce\Util\MimeTypes;
          use BaiduBce\Http\HttpHeaders;
          use BaiduBce\Services\Eip\EipClient;
          use BaiduBce\Services\EipGroup\EipGroupClient;
          
          // Call parameters in configuration file. 
          global $EIP_TEST_CONFIG;
          //Create EipClient 
          $eipClient = new EipClient($EIP_TEST_CONFIG);
          // Create EipGroupClient 
          $eipGroupClient = new EipGroupClient($EIP_TEST_CONFIG);
          //Create EipBpClient
          $eipBpClient = new EipBpClient($EIP_TEST_CONFIG);

          Create EipClient/EipGroupClient/EipBpClient with STS

          Apply for STS token

          EIP can implement temporary authorized access by a third party through the STS mechanism. STS (Security Token Service) is a temporary authorization service provided by Baidu AI Cloud. With STS, you can issue a third-party user with a custom time-based and privileged access credential. The third-party user can use the access credential to directly call API or SDK of Baidu AI Cloud to access its resources.

          To access to EIP via STS, you need to apply for an authentication string via client of STS, for the application method, please see Introduction to Use of Baidu AI Cloud STS.

          Create EipClient with STS token

          After applying for STS, you can configure STStoken to EipClient/EipGroupClient, and you can create an EipClient/EipGroupClient by reference to the following codes:

          1.First perform endpoint configuration for STS. The configuration example of STS is as follows.

          $EIP_TEST_CONFIG =
              array(
                  'credentials' => array(
                      'accessKeyId' => 'your ak',
                      'secretAccessKey' => 'your sk',
                  ),
          	'stsEndpoint' => 'http://sts.bj.baidubce.com',
              );

          2.The sample code of StsClient is as follows.

          //Create StsClient 
          $client = new StsClient($EIP_TEST_CONFIG);
          $request =
              array(
                  'acl' => $aclArray, // user-defined acl 
                  'durationSeconds' => 43200, // effective time of STS certificate 
              );
          $response = $client->getSessionToken($request);
          $accessKeyID= $response->accessKeyId;
          $secretAccessKey= $response->secretAccessKey;
          $sessionToken = $response->sessionToken;

          Note: Where acl refers to the user defined acl, for the Syntax, please see Access Management.

          3.Write the accessKeyID/secretAccessKey/sessionToken obtained to configuration file YourConf.php, and create EipClient.

          $EIP_TEST_CONFIG =
              array(
                  'credentials' => array(
                      'accessKeyId' => 'your ak',
                      'secretAccessKey' => 'your sk',
                      'sessionToken' => 'your session token'
                  ),
                  'endpoint' => 'http://eip.bj.baidubce.com',
              );
          
              //Create EipClient 
              $eipClient = new EipClient($EIP_TEST_CONFIG);
              // Create EipGroupClient 
              $eipGroupClient = new EipGroupClient($EIP_TEST_CONFIG);
              //Create EipBpClient
              $eipBpClient = new EipBpClient($EIP_TEST_CONFIG);

          Note: When you configure client with STS currently, wherever the endpoint in the corresponding EIP service is, endpoint needs to be configured as http://sts.bj.baidubce.com.

          Configure HTTPS Protocol to Access to EIP/EipGroup//EipBp

          EIP supports HTTPS transport protocol, and you can access to EIP/EipGroup service with HTTPS in EIP PHP SDK in the following 2 ways.

          • Specify HTTPS in endpoint
          $EIP_CONFIG =
            array(
                'credentials' => array(
                    'ak' => 'your-ak',
                    'sk' => 'your-sk',
                ),
                'endpoint' => 'https://eip.bj.baidubce.com',
            );
            $eipClient = new EipClient($EIP_CONFIG);
            $eipGroupClient = new EipGroupClient($EIP_CONFIG);
            $eipBpClient = new EipBpClient($EIP_CONFIG);
          • Set HTTPS protocol by specifying https in protocol
          $EIP_CONFIG =
            array(
                'credentials' => array(
                    'ak' => 'your-ak',
                    'sk' => 'your-sk',
                ),
                'endpoint' => 'eip.bj.baidubce.com',
                'protocol' => 'https',
            );
            $eipClient = new EipClient($EIP_CONFIG);
            $eipGroupClient = new EipGroupClient($EIP_CONFIG);
            $eipBpClient = new EipBpClient($EIP_CONFIG);

          Note: If you specify scheme of endpoint while specifying protocol parameter, endpoint should prevail.

          $EIP_CONFIG =
            array(
                'credentials' => array(
                    'ak' => 'your-ak',
                    'sk' => 'your-sk',
                ),
                'endpoint' => 'http://eip.bj.baidubce.com',
                'protocol' => 'https',
            );
            $eipClient = new EipClient($EIP_CONFIG); // access to eip in http 
            $eipGroupClient = new EipGroupClient($EIP_CONFIG); // access to eipgroup in http 
            $eipBpClient = new EipBpClient($EIP_CONFIG); //access to eipBp in http 

          Access to EIP/EipGroup/EipBp with Customized Domain Name

          You can access to EIP service with customized domain name in EIP PHP SDK in the following way.

          Specify custom domain name in endpoint, and specify custom field as true, indicating the use of custom domain name.

          $EIP_CONFIG =
            array(
                'credentials' => array(
                    'ak' => 'your-ak',
                    'sk' => 'your-sk',
                ),
                'endpoint' => 'http://custom-domain.com',
                'custom' => true,
            );
            $eipClient = new EipClient($EIP_CONFIG);
            $eipGroupClient = new EipGroupClient($EIP_CONFIG);
            $eipBpClient = new EipBpClient($EIP_CONFIG);

          Configure EipClient/EipGroupClient/EipBpClient

          Set Custom Parameters

          PHP SDK sets some basic parameters in \BaiduBce\Bce.php by default, and if you want to modify the parameter value, you can create your own parameter configuration feature by reference to this file, and transmit it when creating EipClient, with transmission code as follows.

          public feature CustomizedConfig() {
                  $customizedConfig = array(
                      BceClientConfigOptions:PROTOCOL => 'http',
                      BceClientConfigOptions:REGION => 'bj',
                      BceClientConfigOptions:CONNECTION_TIMEOUT_IN_MILLIS => 120 * 1000,
                      BceClientConfigOptions:SOCKET_TIMEOUT_IN_MILLIS => 300 * 1000,
                      BceClientConfigOptions:SEND_BUF_SIZE => 5 * 1024 * 1024,
                      BceClientConfigOptions:RECV_BUF_SIZE => 5 * 1024 * 1024,
                      BceClientConfigOptions:CREDENTIALS => array(
                          'ak' => 'your-access-key-id',
                          'sk' => 'your-secret-access-key',
                      ),
                      'endpoint' => 'your-endpoint',
                  );
          
                  //Create EipClient with customized configuration. 
                  $customizedEipClient = new EipClient($customizedConfig);
                  // Create EipGroupClient with customized configuration 
                  $customizedEipGroupClient = new EipGroupClient($customizedConfig);
                   //Create EipBpClient with customized configuration 
                  $customizedEipBpClient = new EipBpClient($customizedConfig);
              }

          The parameters are described as follows.

          Parameter Description Default value
          PROTOCOL Protocol http
          REGION Region bj
          CONNECTION_TIMEOUT_IN_MILLIS Request timeout (unit: millisecond) 50 * 1000
          SOCKET_TIMEOUT_IN_MILLIS Timeout for transmitting data over open connections (unit: millisecond) 0 refers to infinite waiting; if you set a non-zero value, you need to evaluate the file size and network speed, otherwise timeouts will occur when large files are uploaded)
          SEND_BUF_SIZE Send buffer size 1024 * 1024
          RECV_BUF_SIZE Receive buffer size 10 1024 1024
          Previous
          SDK Installation
          Next
          EIP Instance