PHP code example of alibabacloud / eventbridge

1. Go to this page and download the library: Download alibabacloud/eventbridge 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/ */

    

alibabacloud / eventbridge example snippets



namespace demo;

EventBridge\Eventbridge;
use AlibabaCloud\SDK\EventBridge\Models\Config;
use AlibabaCloud\SDK\EventBridge\Models\CloudEvent;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;

$config                  = new Config();
$config->accessKeyId     = "<Access-Key-Id>";
$config->accessKeySecret = "<Access-Key-Secret>";
$config->endpoint        = "<Endpoint>";
$client                  = new Eventbridge($config);
$request                 = new CloudEvent();
$request->datacontenttype = 'application/json';
$request->data = 'test';
$request->id= 'id';
$request->source = 'source';
$request->time = '2020-08-24T13:54:05.965Asia/Shanghai';
$request->subject = '1.0';
$request->type = 'type';
$request->extensions = [
  "aliyuneventbusname"=> "BusName"
];

try {
    $response = $client->putEvents([$request]);
    var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
    var_dump($e->getMessage());
    var_dump($e->getErrorInfo());
    var_dump($e->getLastException());
    var_dump($e->getLastRequest());
}



/**
 * Model for initing client
 * @package AlibabaCloud\SDK\EventBridge\Models
 */
class Config {
    /**
     * @description accesskey id
     * @var string
     */
    public $accessKeyId;

    /**
     * @description accesskey secret
     * @var string
     */
    public $accessKeySecret;

    /**
     * @description security token
     * @var string
     */
    public $securityToken;

    /**
     * @description http protocol
     * @example http
     * @var string
     */
    public $protocol;

    /**
     * @description region id
     * @example cn-hangzhou
     * @var string
     */
    public $regionId;

    /**
     * @description read timeout
     * @example 10
     * @var int
     */
    public $readTimeout;

    /**
     * @description connect timeout
     * @example 10
     * @var int
     */
    public $connectTimeout;

    /**
     * @description http proxy
     * @example http://localhost
     * @var string
     */
    public $httpProxy;

    /**
     * @description https proxy
     * @example https://localhost
     * @var string
     */
    public $httpsProxy;

    /**
     * @description credential
     * @example 
     * @var Credential
     */
    public $credential;

    /**
     * @description endpoint
     * @example cs.aliyuncs.com
     * @var string
     */
    public $endpoint;

    /**
     * @description proxy white list
     * @example http://localhost
     * @var string
     */
    public $noProxy;

    /**
     * @description max idle conns
     * @example 3
     * @var int
     */
    public $maxIdleConns;

}

/**
 * The common runtime options model
 */
class RuntimeOptions {
    /**
     * @description whether to try again
     * @var bool
     */
    public $autoretry;

    /**
     * @description ignore SSL validation
     * @var bool
     */
    public $ignoreSSL;

    /**
     * @description maximum number of retries
     * @var int
     */
    public $maxAttempts;

    /**
     * @description backoff policy
     * @var string
     */
    public $backoffPolicy;

    /**
     * @description backoff period
     * @var int
     */
    public $backoffPeriod;

    /**
     * @description read timeout
     * @var int
     */
    public $readTimeout;

    /**
     * @description connect timeout
     * @var int
     */
    public $connectTimeout;

    /**
     * @description http proxy url
     * @var string
     */
    public $httpProxy;

    /**
     * @description https Proxy url
     * @var string
     */
    public $httpsProxy;

    /**
     * @description agent blacklist
     * @var string
     */
    public $noProxy;

    /**
     * @description maximum number of connections
     * @var int
     */
    public $maxIdleConns;

    /**
     * @description local addr
     * @var string
     */
    public $localAddr;

    /**
     * @description SOCKS5 proxy
     * @var string
     */
    public $socks5Proxy;

    /**
     * @description SOCKS5 netWork
     * @var string
     */
    public $socks5NetWork;

}