全部产品
云市场

PHP

更新时间:2019-10-22 11:44:11

PHP SDK

准备工作

  1. 在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问访问密钥(AccessKey)。详情参考创建AccessKey
  2. 安装PHP SDK核心库
    1. 下载并安装Composer: curl -sS https://getcomposer.org/installer | php
    2. 执行以下命令生成类映射: composer dump-autoload --optimize
    3. 执行Composer命令安装Alibaba Cloud SDK for PHP的最新版本: php -d memory_limit=-1 composer.phar require alibabacloud/sdk
    4. 安装本产品SDK:composer require alibabacloud/ivpd
    5. 在代码中引入Composer自动加载工具: <?php require __DIR__ . '/vendor/autoload.php';

完整代码示例

抠图代码示例,其他功能请查看具体API文档和参考NodeJS示例代码

  1. <?php
  2. use AlibabaCloud\Client\AlibabaCloud;
  3. use AlibabaCloud\Client\Exception\ClientException;
  4. use AlibabaCloud\Client\Exception\ServerException;
  5. // Download:https://github.com/aliyun/openapi-sdk-php
  6. // Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
  7. AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
  8. ->regionId('cn-shanghai')
  9. ->asDefaultClient();
  10. try {
  11. $result = AlibabaCloud::rpc()
  12. ->product('Ivpd')
  13. // ->scheme('https') // https | http
  14. ->version('2019-06-25')
  15. ->action('SegmentImage')
  16. ->method('POST')
  17. ->host('ivpd.cn-shanghai.aliyuncs.com')
  18. ->options([
  19. 'query' => [
  20. 'Url' => "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/aliyun-doc/pop/images/segment-image-src.jpg",
  21. ],
  22. ])
  23. ->request();
  24. print_r($result->toArray());
  25. } catch (ClientException $e) {
  26. echo $e->getErrorMessage() . PHP_EOL;
  27. } catch (ServerException $e) {
  28. echo $e->getErrorMessage() . PHP_EOL;
  29. }

参考: