Step By Step
1、PHP SDK安装
2、控制台实例创建及状态查看
3、SDK Code Sample
4、数据查看
一、PHP SDK安装
composer require alibabacloud/sdk
二、控制台实例创建及状态查看
注意:只有状态处于运行中的实例,才能导入数据。
三、SDK Code Sample
- 3.1 add item
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
require_once 'vendor\autoload.php';
// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
AlibabaCloud::accessKeyClient('<ak>', '<sk>')
->regionId('cn-shenzhen')
->asDefaultClient();
try {
$result = AlibabaCloud::roa()
->product('Airec')
// ->scheme('https') // https | http
->version('2018-10-12')
->pathPattern('/openapi/instances/<instanceid>/tables/item/actions/bulk')
->method('POST')
->body('[
{
"cmd": "add",
"fields": {
"item_id": "6",
"item_type": "article",
"title": "感动中国的大学生,今成副书记",
"content": "内容测试",
"pub_time": "1634613280",
"status":"1",
"scene_id":"test01",
"weight":"100",
"tags":"新闻,感动中国"
}
}]')
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
- 3.2 add user
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
require_once 'vendor\autoload.php';
// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
AlibabaCloud::accessKeyClient('<ak>', '<sk>')
->regionId('cn-shenzhen')
->asDefaultClient();
try {
$result = AlibabaCloud::roa()
->product('Airec')
// ->scheme('https') // https | http
->version('2018-10-12')
->pathPattern('/openapi/instances/<instanceid>/tables/user/actions/bulk')
->method('POST')
->body('[{
"cmd": "add",
"fields": {
"user_id": "wangbo",
"user_id_type": "iphone3"
}
}]')
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
- 3.3 add behavior
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
require_once 'vendor\autoload.php';
// Download:https://github.com/aliyun/openapi-sdk-php
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
AlibabaCloud::accessKeyClient('<ak>', '<sk>')
->regionId('cn-shenzhen')
->asDefaultClient();
try {
$result = AlibabaCloud::roa()
->product('Airec')
// ->scheme('https') // https | http
->version('2018-10-12')
->pathPattern('/openapi/instances/<instanceid>/tables/behavior/actions/bulk')
->method('POST')
->body('[{
"cmd": "add",
"fields": {
"item_id": "6",
"item_type": "article",
"bhv_type": "expose",
"bhv_value": "1",
"trace_id": "Alibaba",
"trace_info": "1007.5911.12351.1002000:::::::",
"scene_id": "test01",
"bhv_time": "1634613280",
"user_id": "wangbo"
}
}
]')
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}