PHP code example of awei1601 / taobaosdk
1. Go to this page and download the library: Download awei1601/taobaosdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
awei1601 / taobaosdk example snippets
// taobao.mtop.upload.token.get( 获取文件上传授权 )
$appkey = ".........";
$secret = ".........";
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new MtopUploadTokenGetRequest;
$param_upload_token_request = new UploadTokenRequestV;
$param_upload_token_request->file_size="1024";
$param_upload_token_request->private_data="{\"appkey\": \"1234\"}";
$param_upload_token_request->upload_type="resumable";
$param_upload_token_request->crc="12345678";
$param_upload_token_request->client_net_type="wifi";
$param_upload_token_request->file_name="/tmp/image.jpg";
$param_upload_token_request->biz_code="mtopupload";
$req->setParamUploadTokenRequest(json_encode($param_upload_token_request));
$resp = $c->execute($req);
//taobao.baichuan.user.login( 百川H5登录 )
$appkey = ".........";
$secret = ".........";
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new BaichuanUserLoginRequest;
$req->setName("name");
$resp = $c->execute($req);
//taobao.time.get( 获取淘宝系统当前时间 )
$appkey = ".........";
$secret = ".........";
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new TimeGetRequest;
$resp = $c->execute($req);
$appkey = ".........";
$secret = ".........";
//alibaba.ailabs.iot.device.status.update( ailabs iot 设备状态更新 )
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new AlibabaAilabsIotDeviceStatusUpdateRequest;
$device_status_d_t_o = new DeviceStatusDto;
$payload = new Payload;
$payload->token="e5d0220c162e4a43a4b2b9435e35273d";
$device_info_list = new DeviceInfo;
$device_info_list->dev_id="780f77814dc5";
$status = new Status;
$status->powerstate="on";
$status->mode="cold";
$status->temperature="25";
$status->brightness="50";
$status->windspeed="2";
$device_info_list->status = $status;
$payload->device_info_list = $device_info_list;
$payload->skill_id="123";
$payload->type="1";
$device_status_d_t_o->payload = $payload;
$header = new IotCommonHeader;
$header->pay_load_version="1";
$header->name="Update";
$header->message_id="xxxx";
$header->namespace="AliGenie.Iot.Device.Status";
$device_status_d_t_o->header = $header;
$req->setDeviceStatusDTO(json_encode($device_status_d_t_o));
$resp = $c->execute($req);
// alibaba.ailabs.iot.device.list.update.notify( 设备列表更新通知 )
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new AlibabaAilabsIotDeviceListUpdateNotifyRequest;
$req->setToken("xxx");
$req->setSkillId("xxx");
$req->setType("1");
$resp = $c->execute($req);
// alibaba.ailabs.iot.cloud.device.report( 天猫精灵云云接入设备状态、事件上报接口 )
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$req = new AlibabaAilabsIotCloudDeviceReportRequest;
$cloud_report_param = new CloudReportParam;
$cloud_report_param->payload="{ \"onlinestate\": 1 }";
$cloud_report_param->device_id="devId_1233";
$cloud_report_param->user_access_token="token_123";
$cloud_report_param->open_user_id="1234561232";
$cloud_report_param->account_type="1";
$cloud_report_param->skill_id="513";
$cloud_report_param->time_stamp="4325435435";
$cloud_report_param->message_id="messageId_123";
$cloud_report_param->payload_version="2";
$cloud_report_param->report_type="1";
$req->setCloudReportParam(json_encode($cloud_report_param));
$resp = $c->execute($req);
PHP SDK 需要依赖 PHP 5及以上