PHP code example of cloudycity / uc-marketing-sdk

1. Go to this page and download the library: Download cloudycity/uc-marketing-sdk 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/ */

    

cloudycity / uc-marketing-sdk example snippets


use CloudyCity\UCMarketingSDK\Client;
use CloudyCity\UCMarketingSDK\Kernel\Contracts\UcService;

$accounts = UcService::getAccounts();  // 仅提供Interface,需自行实现

// 遍历广告账号
foreach ($accounts as $account) {
    // 第四个参数为可选参数,默认为数组,客户端会自动将响应转为该格式,下载报表的csv文件也会自动转换成该格式
    // 支持的格式有: array、object、collection、raw、实现\CloudyCity\UCMarketingSDK\Kernel\Contracts\Arrayable的自定义类
    $client = new Client($account['username'], $account['password'], $account['token']);

    try {
        $result = $client->account->get();
    } catch (\CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException $e) {
        // 阿里汇川接口未提示成功
    } catch (\CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException $e) {
        // 实例化客户端时配置的响应格式有误
    } catch (\GuzzleHttp\Exception\GuzzleException $e) {
        // Guzzle工具请求异常
    }
}