All Products
Search
Document Center

:PHP-SDK

Last Updated:Apr 09, 2018
  • Environment requirements

    PHP 5.3+

  • Installation

    • Download the sourcecode of the SDK forPHP from GitHub.

    • Copy the aliyun-php-sdk-core and aliyun-php-sdk-mts folders to your project, and place them in the same directory.

    • Edit aliyun-php-sdk-core/Config.php.

      Locate “//config sdk auto load path.” and add the following content following this line:

      Autoloader::addAutoloadPath("aliyun-php-sdk-mts");

  • Multi-region support

    Edit aliyun-php-sdk-core/Regions/endpoints.xml, and add the Beijing region before the last line (</Endpoints>) (add other regions in a similar way).

    1. <Endpoint name="mts-cn-beijing">
    2. <RegionIds>
    3. <RegionId>mts-cn-beijing</RegionId>
    4. </RegionIds>
    5. <Products>
    6. <Product>
    7. <ProductName>Mts</ProductName>
    8. <DomainName>mts.cn-beijing.aliyuncs.com</DomainName>
    9. </Product>
    10. </Products>
    11. </Endpoint>
    • API call example

      The following calls SearchMediaWorkflow as an example. The most important is to set the attribute of RegionId of $request. The setting for other API calls is similar.

      1. include_once 'aliyun-php-sdk-core/Config.php';
      2. use Mts\Request\V20140618 as Mts;
      1. function search_media_workflow($client, $regionId)
      2. {
      3. $request = new Mts\SearchMediaWorkflowRequest();
      4. $request->setAcceptFormat('JSON');
      5. $request->setRegionId($regionId); //Important
      6. $response = $client->getAcsResponse($request);
      7. return $response;
      8. }
    • Call examples of APIs in the Hangzhou region

      1. include_once 'aliyun-php-sdk-core/Config.php';
      1. $profile = DefaultProfile::getProfile('cn-hangzhou',
      2. $access_key_id,
      3. $access_key_secret);
      4. $client = new DefaultAcsClient($profile);
      5. search_media_workflow($client, 'cn-hangzhou');
    • Call examples of APIs in the Beijing region

      1. include_once 'aliyun-php-sdk-core/Config.php';
      1. $profile = DefaultProfile::getProfile('mts-cn-beijing',
      2. $access_key_id,
      3. $access_key_secret);
      4. $client = new DefaultAcsClient($profile);
      5. search_media_workflow($client, 'mts-cn-beijing');