PHP

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';

说明

php: >=5.5 alibabacloud/client: ^1.5 ,PHP源码

完整代码示例

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

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md

AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
                        ->regionId('cn-shanghai')
                        ->asDefaultClient();

try {
    $result = AlibabaCloud::rpc()
                          ->product('Ivpd')
                          // ->scheme('https') // https | http
                          ->version('2019-06-25')
                          ->action('SegmentImage')
                          ->method('POST')
                          ->host('ivpd.cn-shanghai.aliyuncs.com')
                          ->options([
                                        'query' => [
                                          'Url' => "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/aliyun-doc/pop/images/segment-image-src.jpg",
                                        ],
                                    ])
                          ->request();
    print_r($result->toArray());
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
}

参考:

阿里云首页 智能视觉生产(文档停止维护) 相关技术圈