增加docke部署
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "aliyuncs/aliyun-dysms-msg-php-sdk",
|
||||
"description": "Aliyun SMS message SDK for PHP",
|
||||
"keywords": [ "aliyun", "SMS", "sdk" ],
|
||||
"type": "library",
|
||||
"license": "Apache-2.0",
|
||||
"homepage": "https://www.aliyun.com/product/sms",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aliyuncs",
|
||||
"homepage": "https://www.aliyun.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.0",
|
||||
"guzzlehttp/guzzle": "~6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Aliyun\\": "lib/",
|
||||
"Aliyun\\Test\\": "tests/",
|
||||
"AliyunMNS\\": "lib/MNS"
|
||||
}
|
||||
}
|
||||
}
|
||||
1368
codes/agent/game-docker/dlweb/api/third/dysms/msg_sdk/composer.lock
generated
Normal file
1368
codes/agent/game-docker/dlweb/api/third/dysms/msg_sdk/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Api\Msg\Request\V20170525;
|
||||
use Aliyun\Core\RpcAcsRequest;
|
||||
|
||||
class QueryTokenForMnsQueueRequest extends RpcAcsRequest
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct("Dybaseapi", "2017-05-25", "QueryTokenForMnsQueue");
|
||||
}
|
||||
|
||||
private $ownerId;
|
||||
|
||||
private $resourceOwnerId;
|
||||
|
||||
private $resourceOwnerAccount;
|
||||
|
||||
private $messageType;
|
||||
|
||||
public function getOwnerId() {
|
||||
return $this->ownerId;
|
||||
}
|
||||
|
||||
public function setOwnerId($ownerId) {
|
||||
$this->ownerId = $ownerId;
|
||||
$this->queryParameters["OwnerId"]=$ownerId;
|
||||
}
|
||||
|
||||
public function getResourceOwnerId() {
|
||||
return $this->resourceOwnerId;
|
||||
}
|
||||
|
||||
public function setResourceOwnerId($resourceOwnerId) {
|
||||
$this->resourceOwnerId = $resourceOwnerId;
|
||||
$this->queryParameters["ResourceOwnerId"]=$resourceOwnerId;
|
||||
}
|
||||
|
||||
public function getResourceOwnerAccount() {
|
||||
return $this->resourceOwnerAccount;
|
||||
}
|
||||
|
||||
public function setResourceOwnerAccount($resourceOwnerAccount) {
|
||||
$this->resourceOwnerAccount = $resourceOwnerAccount;
|
||||
$this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount;
|
||||
}
|
||||
|
||||
public function getMessageType() {
|
||||
return $this->messageType;
|
||||
}
|
||||
|
||||
public function setMessageType($messageType) {
|
||||
$this->messageType = $messageType;
|
||||
$this->queryParameters["MessageType"]=$messageType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
|
||||
abstract class AcsRequest
|
||||
{
|
||||
protected $version;
|
||||
protected $product;
|
||||
protected $actionName;
|
||||
protected $regionId;
|
||||
protected $acceptFormat;
|
||||
protected $method;
|
||||
protected $protocolType = "http";
|
||||
protected $content;
|
||||
|
||||
protected $queryParameters = array();
|
||||
protected $headers = array();
|
||||
|
||||
function __construct($product, $version, $actionName)
|
||||
{
|
||||
$this->headers["x-sdk-client"] = "php/2.0.0";
|
||||
$this->product = $product;
|
||||
$this->version = $version;
|
||||
$this->actionName = $actionName;
|
||||
}
|
||||
|
||||
public abstract function composeUrl($iSigner, $credential, $domain);
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function getProduct()
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct($product)
|
||||
{
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
public function getActionName()
|
||||
{
|
||||
return $this->actionName;
|
||||
}
|
||||
|
||||
public function setActionName($actionName)
|
||||
{
|
||||
$this->actionName = $actionName;
|
||||
}
|
||||
|
||||
public function getAcceptFormat()
|
||||
{
|
||||
return $this->acceptFormat;
|
||||
}
|
||||
|
||||
public function setAcceptFormat($acceptFormat)
|
||||
{
|
||||
$this->acceptFormat = $acceptFormat;
|
||||
}
|
||||
|
||||
public function getQueryParameters()
|
||||
{
|
||||
return $this->queryParameters;
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
public function getProtocol()
|
||||
{
|
||||
return $this->protocolType;
|
||||
}
|
||||
|
||||
public function setProtocol($protocol)
|
||||
{
|
||||
$this->protocolType = $protocol;
|
||||
}
|
||||
|
||||
public function getRegionId()
|
||||
{
|
||||
return $this->regionId;
|
||||
}
|
||||
public function setRegionId($region)
|
||||
{
|
||||
$this->regionId = $region;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
|
||||
public function addHeader($headerKey, $headerValue)
|
||||
{
|
||||
$this->headers[$headerKey] = $headerValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
|
||||
class AcsResponse
|
||||
{
|
||||
private $code;
|
||||
private $message;
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Auth;
|
||||
|
||||
class Credential
|
||||
{
|
||||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
|
||||
private $refreshDate;
|
||||
private $expiredDate;
|
||||
private $accessKeyId;
|
||||
private $accessSecret;
|
||||
private $securityToken;
|
||||
|
||||
function __construct($accessKeyId, $accessSecret)
|
||||
{
|
||||
$this->accessKeyId = $accessKeyId;
|
||||
$this->accessSecret = $accessSecret;
|
||||
$this->refreshDate = date($this->dateTimeFormat);
|
||||
}
|
||||
|
||||
public function isExpired()
|
||||
{
|
||||
if($this->expiredDate == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(strtotime($this->expiredDate)>date($this->dateTimeFormat))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRefreshDate()
|
||||
{
|
||||
return $this->refreshDate;
|
||||
}
|
||||
|
||||
public function getExpiredDate()
|
||||
{
|
||||
return $this->expiredDate;
|
||||
}
|
||||
|
||||
public function setExpiredDate($expiredHours)
|
||||
{
|
||||
if($expiredHours>0)
|
||||
{
|
||||
return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
public function setAccessKeyId($accessKeyId)
|
||||
{
|
||||
$this->accessKeyId = $accessKeyId;
|
||||
}
|
||||
|
||||
public function getAccessSecret()
|
||||
{
|
||||
return $this->accessSecret;
|
||||
}
|
||||
|
||||
public function setAccessSecret($accessSecret)
|
||||
{
|
||||
$this->accessSecret = $accessSecret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Auth;
|
||||
|
||||
interface ISigner
|
||||
{
|
||||
public function getSignatureMethod();
|
||||
|
||||
public function getSignatureVersion();
|
||||
|
||||
public function signString($source, $accessSecret);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Auth;
|
||||
|
||||
class ShaHmac1Signer implements ISigner
|
||||
{
|
||||
public function signString($source, $accessSecret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true));
|
||||
}
|
||||
|
||||
public function getSignatureMethod() {
|
||||
return "HMAC-SHA1";
|
||||
}
|
||||
|
||||
public function getSignatureVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Auth;
|
||||
|
||||
class ShaHmac256Signer implements ISigner
|
||||
{
|
||||
public function signString($source, $accessSecret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha256', $source, $accessSecret, true));
|
||||
}
|
||||
|
||||
public function getSignatureMethod() {
|
||||
return "HMAC-SHA256";
|
||||
}
|
||||
|
||||
public function getSignatureVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
|
||||
use Aliyun\Core\Regions\EndpointConfig;
|
||||
|
||||
//config http proxy
|
||||
define('ENABLE_HTTP_PROXY', FALSE);
|
||||
define('HTTP_PROXY_IP', '127.0.0.1');
|
||||
define('HTTP_PROXY_PORT', '8888');
|
||||
|
||||
|
||||
class Config
|
||||
{
|
||||
private static $loaded = false;
|
||||
public static function load(){
|
||||
if(self::$loaded) {
|
||||
return;
|
||||
}
|
||||
EndpointConfig::load();
|
||||
self::$loaded = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
use Aliyun\Core\Exception\ClientException;
|
||||
use Aliyun\Core\Exception\ServerException;
|
||||
use Aliyun\Core\Regions\EndpointProvider;
|
||||
use Aliyun\Core\Http\HttpHelper;
|
||||
|
||||
class DefaultAcsClient implements IAcsClient
|
||||
{
|
||||
public $iClientProfile;
|
||||
public $__urlTestFlag__;
|
||||
|
||||
function __construct($iClientProfile)
|
||||
{
|
||||
$this->iClientProfile = $iClientProfile;
|
||||
$this->__urlTestFlag__ = false;
|
||||
}
|
||||
|
||||
public function getAcsResponse($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3)
|
||||
{
|
||||
$httpResponse = $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber);
|
||||
$respObject = $this->parseAcsResponse($httpResponse->getBody(), $request->getAcceptFormat());
|
||||
if(false == $httpResponse->isSuccess())
|
||||
{
|
||||
$this->buildApiException($respObject, $httpResponse->getStatus());
|
||||
}
|
||||
return $respObject;
|
||||
}
|
||||
|
||||
private function doActionImpl($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3)
|
||||
{
|
||||
if(null == $this->iClientProfile && (null == $iSigner || null == $credential
|
||||
|| null == $request->getRegionId() || null == $request->getAcceptFormat()))
|
||||
{
|
||||
throw new ClientException("No active profile found.", "SDK.InvalidProfile");
|
||||
}
|
||||
if(null == $iSigner)
|
||||
{
|
||||
$iSigner = $this->iClientProfile->getSigner();
|
||||
}
|
||||
if(null == $credential)
|
||||
{
|
||||
$credential = $this->iClientProfile->getCredential();
|
||||
}
|
||||
$request = $this->prepareRequest($request);
|
||||
$domain = EndpointProvider::findProductDomain($request->getRegionId(), $request->getProduct());
|
||||
|
||||
if(null == $domain)
|
||||
{
|
||||
throw new ClientException("Can not find endpoint to access.", "SDK.InvalidRegionId");
|
||||
}
|
||||
$requestUrl = $request->composeUrl($iSigner, $credential, $domain);
|
||||
|
||||
if ($this->__urlTestFlag__) {
|
||||
throw new ClientException($requestUrl, "URLTestFlagIsSet");
|
||||
}
|
||||
|
||||
if(count($request->getDomainParameter())>0){
|
||||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders());
|
||||
} else {
|
||||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(),$request->getContent(), $request->getHeaders());
|
||||
}
|
||||
|
||||
$retryTimes = 1;
|
||||
while (500 <= $httpResponse->getStatus() && $autoRetry && $retryTimes < $maxRetryNumber) {
|
||||
$requestUrl = $request->composeUrl($iSigner, $credential,$domain);
|
||||
|
||||
if(count($request->getDomainParameter())>0){
|
||||
$httpResponse = HttpHelper::curl($requestUrl, $request->getDomainParameter(), $request->getHeaders());
|
||||
} else {
|
||||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders());
|
||||
}
|
||||
$retryTimes ++;
|
||||
}
|
||||
return $httpResponse;
|
||||
}
|
||||
|
||||
public function doAction($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3)
|
||||
{
|
||||
trigger_error("doAction() is deprecated. Please use getAcsResponse() instead.", E_USER_NOTICE);
|
||||
return $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber);
|
||||
}
|
||||
|
||||
private function prepareRequest($request)
|
||||
{
|
||||
if(null == $request->getRegionId())
|
||||
{
|
||||
$request->setRegionId($this->iClientProfile->getRegionId());
|
||||
}
|
||||
if(null == $request->getAcceptFormat())
|
||||
{
|
||||
$request->setAcceptFormat($this->iClientProfile->getFormat());
|
||||
}
|
||||
if(null == $request->getMethod())
|
||||
{
|
||||
$request->setMethod("GET");
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
|
||||
|
||||
private function buildApiException($respObject, $httpStatus)
|
||||
{
|
||||
throw new ServerException($respObject->Message, $respObject->Code, $httpStatus, $respObject->RequestId);
|
||||
}
|
||||
|
||||
private function parseAcsResponse($body, $format)
|
||||
{
|
||||
if ("JSON" == $format)
|
||||
{
|
||||
$respObject = json_decode($body);
|
||||
}
|
||||
else if("XML" == $format)
|
||||
{
|
||||
$respObject = @simplexml_load_string($body);
|
||||
}
|
||||
else if("RAW" == $format)
|
||||
{
|
||||
$respObject = $body;
|
||||
}
|
||||
return $respObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Exception;
|
||||
|
||||
class ClientException extends \Exception
|
||||
{
|
||||
function __construct($errorMessage, $errorCode)
|
||||
{
|
||||
parent::__construct($errorMessage);
|
||||
$this->errorMessage = $errorMessage;
|
||||
$this->errorCode = $errorCode;
|
||||
$this->setErrorType("Client");
|
||||
}
|
||||
|
||||
private $errorCode;
|
||||
private $errorMessage;
|
||||
private $errorType;
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function setErrorCode($errorCode)
|
||||
{
|
||||
$this->errorCode = $errorCode;
|
||||
}
|
||||
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
public function setErrorMessage($errorMessage)
|
||||
{
|
||||
$this->errorMessage = $errorMessage;
|
||||
}
|
||||
|
||||
public function getErrorType()
|
||||
{
|
||||
return $this->errorType;
|
||||
}
|
||||
|
||||
public function setErrorType($errorType)
|
||||
{
|
||||
$this->errorType = $errorType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Aliyun\Core\Exception;
|
||||
|
||||
class ServerException extends ClientException
|
||||
{
|
||||
private $httpStatus;
|
||||
private $requestId;
|
||||
|
||||
function __construct($errorMessage, $errorCode, $httpStatus, $requestId)
|
||||
{
|
||||
$messageStr = $errorCode . " " . $errorMessage . " HTTP Status: " . $httpStatus . " RequestID: " . $requestId;
|
||||
parent::__construct($messageStr, $errorCode);
|
||||
$this->setErrorMessage($errorMessage);
|
||||
$this->setErrorType("Server");
|
||||
$this->httpStatus = $httpStatus;
|
||||
$this->requestId = $requestId;
|
||||
}
|
||||
|
||||
public function getHttpStatus()
|
||||
{
|
||||
return $this->httpStatus;
|
||||
}
|
||||
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Http;
|
||||
use Aliyun\Core\Exception\ClientException;
|
||||
|
||||
class HttpHelper
|
||||
{
|
||||
public static $connectTimeout = 30;//30 second
|
||||
public static $readTimeout = 80;//80 second
|
||||
|
||||
public static function curl($url, $httpMethod = "GET", $postFields = null,$headers = null)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
|
||||
if(ENABLE_HTTP_PROXY) {
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP);
|
||||
curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT);
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
|
||||
|
||||
if (self::$readTimeout) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
|
||||
}
|
||||
if (self::$connectTimeout) {
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
|
||||
}
|
||||
//https request
|
||||
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
if (is_array($headers) && 0 < count($headers))
|
||||
{
|
||||
$httpHeaders =self::getHttpHearders($headers);
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER,$httpHeaders);
|
||||
}
|
||||
$httpResponse = new HttpResponse();
|
||||
$httpResponse->setBody(curl_exec($ch));
|
||||
$httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
|
||||
if (curl_errno($ch))
|
||||
{
|
||||
throw new ClientException("Server unreachable: Errno: " . curl_errno($ch) . " " . curl_error($ch), "SDK.ServerUnreachable");
|
||||
}
|
||||
curl_close($ch);
|
||||
return $httpResponse;
|
||||
}
|
||||
static function getPostHttpBody($postFildes){
|
||||
$content = "";
|
||||
foreach ($postFildes as $apiParamKey => $apiParamValue)
|
||||
{
|
||||
$content .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
|
||||
}
|
||||
return substr($content, 0, -1);
|
||||
}
|
||||
static function getHttpHearders($headers)
|
||||
{
|
||||
$httpHeader = array();
|
||||
foreach ($headers as $key => $value)
|
||||
{
|
||||
array_push($httpHeader, $key.":".$value);
|
||||
}
|
||||
return $httpHeader;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Http;
|
||||
|
||||
class HttpResponse
|
||||
{
|
||||
private $body;
|
||||
private $status;
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function isSuccess()
|
||||
{
|
||||
if(200 <= $this->status && 300 > $this->status)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
interface IAcsClient
|
||||
{
|
||||
public function doAction($requst);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Profile;
|
||||
|
||||
use Aliyun\Core\Auth\Credential;
|
||||
use Aliyun\Core\Auth\ShaHmac1Signer;
|
||||
use Aliyun\Core\Regions\ProductDomain;
|
||||
use Aliyun\Core\Regions\Endpoint;
|
||||
use Aliyun\Core\Regions\EndpointProvider;
|
||||
|
||||
class DefaultProfile implements IClientProfile
|
||||
{
|
||||
private static $profile;
|
||||
private static $endpoints;
|
||||
private static $credential;
|
||||
private static $regionId;
|
||||
private static $acceptFormat;
|
||||
|
||||
private static $isigner;
|
||||
private static $iCredential;
|
||||
|
||||
private function __construct($regionId,$credential)
|
||||
{
|
||||
self::$regionId = $regionId;
|
||||
self::$credential = $credential;
|
||||
}
|
||||
|
||||
public static function getProfile($regionId, $accessKeyId, $accessSecret)
|
||||
{
|
||||
$credential =new Credential($accessKeyId, $accessSecret);
|
||||
self::$profile = new DefaultProfile($regionId, $credential);
|
||||
return self::$profile;
|
||||
}
|
||||
|
||||
public function getSigner()
|
||||
{
|
||||
if(null == self::$isigner)
|
||||
{
|
||||
self::$isigner = new ShaHmac1Signer();
|
||||
}
|
||||
return self::$isigner;
|
||||
}
|
||||
|
||||
public function getRegionId()
|
||||
{
|
||||
return self::$regionId;
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return self::$acceptFormat;
|
||||
}
|
||||
|
||||
public function getCredential()
|
||||
{
|
||||
if(null == self::$credential && null != self::$iCredential)
|
||||
{
|
||||
self::$credential = self::$iCredential;
|
||||
}
|
||||
return self::$credential;
|
||||
}
|
||||
|
||||
public static function getEndpoints()
|
||||
{
|
||||
if(null == self::$endpoints)
|
||||
{
|
||||
self::$endpoints = EndpointProvider::getEndpoints();
|
||||
}
|
||||
return self::$endpoints;
|
||||
}
|
||||
|
||||
public static function addEndpoint($endpointName, $regionId, $product, $domain)
|
||||
{
|
||||
if(null == self::$endpoints)
|
||||
{
|
||||
self::$endpoints = self::getEndpoints();
|
||||
}
|
||||
$endpoint = self::findEndpointByName($endpointName);
|
||||
if(null == $endpoint)
|
||||
{
|
||||
self::addEndpoint_($endpointName, $regionId, $product, $domain);
|
||||
}
|
||||
else
|
||||
{
|
||||
self::updateEndpoint($regionId, $product, $domain, $endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
public static function findEndpointByName($endpointName)
|
||||
{
|
||||
foreach (self::$endpoints as $key => $endpoint)
|
||||
{
|
||||
if($endpoint->getName() == $endpointName)
|
||||
{
|
||||
return $endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function addEndpoint_($endpointName,$regionId, $product, $domain)
|
||||
{
|
||||
$regionIds = array($regionId);
|
||||
$productDomains = array(new ProductDomain($product, $domain));
|
||||
$endpoint = new Endpoint($endpointName, $regionIds, $productDomains);
|
||||
array_push(self::$endpoints, $endpoint);
|
||||
}
|
||||
|
||||
private static function updateEndpoint($regionId, $product, $domain, $endpoint)
|
||||
{
|
||||
$regionIds = $endpoint->getRegionIds();
|
||||
if(!in_array($regionId,$regionIds))
|
||||
{
|
||||
array_push($regionIds, $regionId);
|
||||
$endpoint->setRegionIds($regionIds);
|
||||
}
|
||||
|
||||
$productDomains = $endpoint->getProductDomains();
|
||||
if(null == self::findProductDomain($productDomains, $product, $domain))
|
||||
{
|
||||
array_push($productDomains, new ProductDomain($product, $domain));
|
||||
}
|
||||
$endpoint->setProductDomains($productDomains);
|
||||
}
|
||||
|
||||
private static function findProductDomain($productDomains, $product, $domain)
|
||||
{
|
||||
foreach ($productDomains as $key => $productDomain)
|
||||
{
|
||||
if($productDomain->getProductName() == $product && $productDomain->getDomainName() == $domain)
|
||||
{
|
||||
return $productDomain;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Profile;
|
||||
|
||||
interface IClientProfile
|
||||
{
|
||||
public function getSigner();
|
||||
|
||||
public function getRegionId();
|
||||
|
||||
public function getFormat();
|
||||
|
||||
public function getCredential();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Regions;
|
||||
|
||||
class Endpoint
|
||||
{
|
||||
private $name;
|
||||
private $regionIds;
|
||||
private $productDomains;
|
||||
|
||||
function __construct($name, $regionIds, $productDomains)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->regionIds = $regionIds;
|
||||
$this->productDomains = $productDomains;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getRegionIds()
|
||||
{
|
||||
return $this->regionIds;
|
||||
}
|
||||
|
||||
public function setRegionIds($regionIds)
|
||||
{
|
||||
$this->regionIds = $regionIds;
|
||||
}
|
||||
|
||||
public function getProductDomains()
|
||||
{
|
||||
return $this->productDomains;
|
||||
}
|
||||
|
||||
public function setProductDomains($productDomains)
|
||||
{
|
||||
$this->productDomains = $productDomains;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Regions;
|
||||
|
||||
class EndpointConfig {
|
||||
|
||||
private static $loaded = false;
|
||||
|
||||
public static function load() {
|
||||
if(self::$loaded) {
|
||||
return;
|
||||
}
|
||||
$endpoint_filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "endpoints.xml";
|
||||
$xml = simplexml_load_string(file_get_contents($endpoint_filename));
|
||||
$json = json_encode($xml);
|
||||
$json_array = json_decode($json, TRUE);
|
||||
|
||||
$endpoints = array();
|
||||
|
||||
|
||||
foreach ($json_array["Endpoint"] as $json_endpoint) {
|
||||
# pre-process RegionId & Product
|
||||
if (!array_key_exists("RegionId", $json_endpoint["RegionIds"])) {
|
||||
$region_ids = array();
|
||||
} else {
|
||||
$json_region_ids = $json_endpoint['RegionIds']['RegionId'];
|
||||
if (!is_array($json_region_ids)) {
|
||||
$region_ids = array($json_region_ids);
|
||||
} else {
|
||||
$region_ids = $json_region_ids;
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists("Product", $json_endpoint["Products"])) {
|
||||
$products = array();
|
||||
|
||||
} else {
|
||||
$json_products = $json_endpoint["Products"]["Product"];
|
||||
|
||||
if (array() === $json_products or !is_array($json_products)) {
|
||||
$products = array();
|
||||
} else if (array_keys($json_products) !== range(0, count($json_products) - 1)) {
|
||||
# array is not sequential
|
||||
$products = array($json_products);
|
||||
} else {
|
||||
$products = $json_products;
|
||||
}
|
||||
}
|
||||
|
||||
$product_domains = array();
|
||||
foreach ($products as $product) {
|
||||
$product_domain = new ProductDomain($product['ProductName'], $product['DomainName']);
|
||||
array_push($product_domains, $product_domain);
|
||||
}
|
||||
|
||||
$endpoint = new Endpoint($region_ids[0], $region_ids, $product_domains);
|
||||
array_push($endpoints, $endpoint);
|
||||
}
|
||||
|
||||
EndpointProvider::setEndpoints($endpoints);
|
||||
self::$loaded = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Regions;
|
||||
|
||||
class EndpointProvider
|
||||
{
|
||||
private static $endpoints;
|
||||
|
||||
public static function findProductDomain($regionId, $product)
|
||||
{
|
||||
if(null == $regionId || null == $product || null == self::$endpoints)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (self::$endpoints as $key => $endpoint)
|
||||
{
|
||||
if(in_array($regionId, $endpoint->getRegionIds()))
|
||||
{
|
||||
return self::findProductDomainByProduct($endpoint->getProductDomains(), $product);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function findProductDomainByProduct($productDomains, $product)
|
||||
{
|
||||
if(null == $productDomains)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach ($productDomains as $key => $productDomain)
|
||||
{
|
||||
if($product == $productDomain->getProductName())
|
||||
{
|
||||
return $productDomain->getDomainName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function getEndpoints()
|
||||
{
|
||||
return self::$endpoints;
|
||||
}
|
||||
|
||||
public static function setEndpoints($endpoints)
|
||||
{
|
||||
self::$endpoints = $endpoints;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core\Regions;
|
||||
|
||||
class ProductDomain
|
||||
{
|
||||
private $productName;
|
||||
private $domainName;
|
||||
|
||||
function __construct($product, $domain) {
|
||||
$this->productName = $product;
|
||||
$this->domainName = $domain;
|
||||
}
|
||||
|
||||
public function getProductName() {
|
||||
return $this->productName;
|
||||
}
|
||||
public function setProductName($productName) {
|
||||
$this->productName = $productName;
|
||||
}
|
||||
public function getDomainName() {
|
||||
return $this->domainName;
|
||||
}
|
||||
public function setDomainName($domainName) {
|
||||
$this->domainName = $domainName;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
|
||||
abstract class RoaAcsRequest extends AcsRequest
|
||||
{
|
||||
protected $uriPattern;
|
||||
private $pathParameters = array();
|
||||
private $domainParameters = array();
|
||||
private $dateTimeFormat ="D, d M Y H:i:s \G\M\T";
|
||||
private static $headerSeparator = "\n";
|
||||
private static $querySeprator = "&";
|
||||
|
||||
function __construct($product, $version, $actionName)
|
||||
{
|
||||
parent::__construct($product, $version, $actionName);
|
||||
$this->setVersion($version);
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
$this->setMethod("RAW");
|
||||
}
|
||||
|
||||
public function composeUrl($iSigner, $credential, $domain)
|
||||
{
|
||||
$this->prepareHeader($iSigner);
|
||||
|
||||
$signString = $this->getMethod().self::$headerSeparator;
|
||||
if(isset($this->headers["Accept"]))
|
||||
{
|
||||
$signString = $signString.$this->headers["Accept"];
|
||||
}
|
||||
$signString = $signString.self::$headerSeparator;
|
||||
|
||||
if(isset($this->headers["Content-MD5"]))
|
||||
{
|
||||
$signString = $signString.$this->headers["Content-MD5"];
|
||||
}
|
||||
$signString = $signString.self::$headerSeparator;
|
||||
|
||||
if(isset($this->headers["Content-Type"]))
|
||||
{
|
||||
$signString = $signString.$this->headers["Content-Type"];
|
||||
}
|
||||
$signString = $signString.self::$headerSeparator;
|
||||
|
||||
if(isset($this->headers["Date"]))
|
||||
{
|
||||
$signString = $signString.$this->headers["Date"];
|
||||
}
|
||||
$signString = $signString.self::$headerSeparator;
|
||||
|
||||
$uri = $this->replaceOccupiedParameters();
|
||||
$signString = $signString.$this->buildCanonicalHeaders();
|
||||
$queryString = $this->buildQueryString($uri);
|
||||
$signString .= $queryString;
|
||||
$this->headers["Authorization"] = "acs ".$credential->getAccessKeyId().":"
|
||||
.$iSigner->signString($signString, $credential->getAccessSecret());
|
||||
$requestUrl = $this->getProtocol()."://".$domain.$queryString;
|
||||
return $requestUrl;
|
||||
}
|
||||
|
||||
private function prepareHeader($iSigner)
|
||||
{
|
||||
date_default_timezone_set("GMT");
|
||||
$this->headers["Date"] = date($this->dateTimeFormat);
|
||||
if(null == $this->acceptFormat)
|
||||
{
|
||||
$this->acceptFormat = "RAW";
|
||||
}
|
||||
$this->headers["Accept"] = $this->formatToAccept($this->getAcceptFormat());
|
||||
$this->headers["x-acs-signature-method"] = $iSigner->getSignatureMethod();
|
||||
$this->headers["x-acs-signature-version"] = $iSigner->getSignatureVersion();
|
||||
$this->headers["x-acs-region-id"] = $this->regionId;
|
||||
$content = $this->getDomainParameter();
|
||||
if ($content != null) {
|
||||
$this->headers["Content-MD5"] = base64_encode(md5(json_encode($content),true));
|
||||
}
|
||||
$this->headers["Content-Type"] = "application/octet-stream;charset=utf-8";
|
||||
}
|
||||
|
||||
private function replaceOccupiedParameters()
|
||||
{
|
||||
$result = $this->uriPattern;
|
||||
foreach ($this->pathParameters as $pathParameterKey => $apiParameterValue)
|
||||
{
|
||||
$target = "[".$pathParameterKey."]";
|
||||
$result = str_replace($target,$apiParameterValue,$result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function buildCanonicalHeaders()
|
||||
{
|
||||
$sortMap = array();
|
||||
foreach ($this->headers as $headerKey => $headerValue)
|
||||
{
|
||||
$key = strtolower($headerKey);
|
||||
if(strpos($key, "x-acs-") === 0)
|
||||
{
|
||||
$sortMap[$key] = $headerValue;
|
||||
}
|
||||
}
|
||||
ksort($sortMap);
|
||||
$headerString = "";
|
||||
foreach ($sortMap as $sortMapKey => $sortMapValue)
|
||||
{
|
||||
$headerString = $headerString.$sortMapKey.":".$sortMapValue.self::$headerSeparator;
|
||||
}
|
||||
return $headerString;
|
||||
}
|
||||
|
||||
private function splitSubResource($uri)
|
||||
{
|
||||
$queIndex = strpos($uri, "?");
|
||||
$uriParts = array();
|
||||
if(null != $queIndex)
|
||||
{
|
||||
array_push($uriParts, substr($uri,0,$queIndex));
|
||||
array_push($uriParts, substr($uri,$queIndex+1));
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($uriParts,$uri);
|
||||
}
|
||||
return $uriParts;
|
||||
}
|
||||
|
||||
private function buildQueryString($uri)
|
||||
{
|
||||
$uriParts = $this->splitSubResource($uri);
|
||||
$sortMap = $this->queryParameters;
|
||||
if(isset($uriParts[1]))
|
||||
{
|
||||
$sortMap[$uriParts[1]] = null;
|
||||
}
|
||||
$queryString = $uriParts[0];
|
||||
if(count($uriParts))
|
||||
{
|
||||
$queryString = $queryString."?";
|
||||
}
|
||||
ksort($sortMap);
|
||||
foreach ($sortMap as $sortMapKey => $sortMapValue)
|
||||
{
|
||||
$queryString = $queryString.$sortMapKey;
|
||||
if(isset($sortMapValue))
|
||||
{
|
||||
$queryString = $queryString."=".$sortMapValue;
|
||||
}
|
||||
$queryString = $queryString.$querySeprator;
|
||||
}
|
||||
if(null==count($sortMap))
|
||||
{
|
||||
$queryString = substr($queryString, 0, strlen($queryString)-1);
|
||||
}
|
||||
return $queryString;
|
||||
}
|
||||
|
||||
private function formatToAccept($acceptFormat)
|
||||
{
|
||||
if($acceptFormat == "JSON")
|
||||
{
|
||||
return "application/json";
|
||||
}
|
||||
elseif ($acceptFormat == "XML") {
|
||||
return "application/xml";
|
||||
}
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
public function getPathParameters()
|
||||
{
|
||||
return $this->pathParameters;
|
||||
}
|
||||
|
||||
public function putPathParameter($name, $value)
|
||||
{
|
||||
$this->pathParameters[$name] = $value;
|
||||
}
|
||||
|
||||
public function getDomainParameter()
|
||||
{
|
||||
return $this->domainParameters;
|
||||
}
|
||||
|
||||
public function putDomainParameters($name, $value)
|
||||
{
|
||||
$this->domainParameters[$name] = $value;
|
||||
}
|
||||
|
||||
public function getUriPattern()
|
||||
{
|
||||
return $this->uriPattern;
|
||||
}
|
||||
|
||||
public function setUriPattern($uriPattern)
|
||||
{
|
||||
return $this->uriPattern = $uriPattern;
|
||||
}
|
||||
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
$this->headers["x-acs-version"] = $version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Aliyun\Core;
|
||||
|
||||
abstract class RpcAcsRequest extends AcsRequest
|
||||
{
|
||||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
|
||||
private $domainParameters = array();
|
||||
|
||||
function __construct($product, $version, $actionName)
|
||||
{
|
||||
parent::__construct($product, $version, $actionName);
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
$this->setMethod("GET");
|
||||
$this->setAcceptFormat("JSON");
|
||||
}
|
||||
|
||||
|
||||
private function prepareValue($value)
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
if ($value) {
|
||||
return "true";
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function composeUrl($iSigner, $credential, $domain)
|
||||
{
|
||||
$apiParams = parent::getQueryParameters();
|
||||
foreach ($apiParams as $key => $value) {
|
||||
$apiParams[$key] = $this->prepareValue($value);
|
||||
}
|
||||
$apiParams["RegionId"] = $this->getRegionId();
|
||||
$apiParams["AccessKeyId"] = $credential->getAccessKeyId();
|
||||
$apiParams["Format"] = $this->getAcceptFormat();
|
||||
$apiParams["SignatureMethod"] = $iSigner->getSignatureMethod();
|
||||
$apiParams["SignatureVersion"] = $iSigner->getSignatureVersion();
|
||||
$apiParams["SignatureNonce"] = uniqid();
|
||||
date_default_timezone_set("GMT");
|
||||
$apiParams["Timestamp"] = date($this->dateTimeFormat);
|
||||
$apiParams["Action"] = $this->getActionName();
|
||||
$apiParams["Version"] = $this->getVersion();
|
||||
$apiParams["Signature"] = $this->computeSignature($apiParams, $credential->getAccessSecret(), $iSigner);
|
||||
if(parent::getMethod() == "POST") {
|
||||
|
||||
$requestUrl = $this->getProtocol()."://". $domain . "/";
|
||||
foreach ($apiParams as $apiParamKey => $apiParamValue)
|
||||
{
|
||||
$this->putDomainParameters($apiParamKey,$apiParamValue);
|
||||
}
|
||||
return $requestUrl;
|
||||
}
|
||||
else {
|
||||
$requestUrl = $this->getProtocol()."://". $domain . "/?";
|
||||
|
||||
foreach ($apiParams as $apiParamKey => $apiParamValue)
|
||||
{
|
||||
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
|
||||
}
|
||||
return substr($requestUrl, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private function computeSignature($parameters, $accessKeySecret, $iSigner)
|
||||
{
|
||||
ksort($parameters);
|
||||
$canonicalizedQueryString = '';
|
||||
foreach($parameters as $key => $value)
|
||||
{
|
||||
$canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value);
|
||||
}
|
||||
$stringToSign = parent::getMethod().'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
|
||||
$signature = $iSigner->signString($stringToSign, $accessKeySecret."&");
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
protected function percentEncode($str)
|
||||
{
|
||||
$res = urlencode($str);
|
||||
$res = preg_replace('/\+/', '%20', $res);
|
||||
$res = preg_replace('/\*/', '%2A', $res);
|
||||
$res = preg_replace('/%7E/', '~', $res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getDomainParameter()
|
||||
{
|
||||
return $this->domainParameters;
|
||||
}
|
||||
|
||||
public function putDomainParameters($name, $value)
|
||||
{
|
||||
$this->domainParameters[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace AliyunMNS;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
|
||||
class AsyncCallback
|
||||
{
|
||||
protected $succeedCallback;
|
||||
protected $failedCallback;
|
||||
|
||||
public function __construct(callable $succeedCallback, callable $failedCallback)
|
||||
{
|
||||
$this->succeedCallback = $succeedCallback;
|
||||
$this->failedCallback = $failedCallback;
|
||||
}
|
||||
|
||||
public function onSucceed(BaseResponse $result)
|
||||
{
|
||||
return call_user_func($this->succeedCallback, $result);
|
||||
}
|
||||
|
||||
public function onFailed(MnsException $e)
|
||||
{
|
||||
return call_user_func($this->failedCallback, $e);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
namespace AliyunMNS;
|
||||
|
||||
use AliyunMNS\Queue;
|
||||
use AliyunMNS\Config;
|
||||
use AliyunMNS\Http\HttpClient;
|
||||
use AliyunMNS\AsyncCallback;
|
||||
use AliyunMNS\Model\AccountAttributes;
|
||||
use AliyunMNS\Requests\CreateQueueRequest;
|
||||
use AliyunMNS\Responses\CreateQueueResponse;
|
||||
use AliyunMNS\Requests\ListQueueRequest;
|
||||
use AliyunMNS\Responses\ListQueueResponse;
|
||||
use AliyunMNS\Requests\DeleteQueueRequest;
|
||||
use AliyunMNS\Responses\DeleteQueueResponse;
|
||||
use AliyunMNS\Requests\CreateTopicRequest;
|
||||
use AliyunMNS\Responses\CreateTopicResponse;
|
||||
use AliyunMNS\Requests\DeleteTopicRequest;
|
||||
use AliyunMNS\Responses\DeleteTopicResponse;
|
||||
use AliyunMNS\Requests\ListTopicRequest;
|
||||
use AliyunMNS\Responses\ListTopicResponse;
|
||||
use AliyunMNS\Requests\GetAccountAttributesRequest;
|
||||
use AliyunMNS\Responses\GetAccountAttributesResponse;
|
||||
use AliyunMNS\Requests\SetAccountAttributesRequest;
|
||||
use AliyunMNS\Responses\SetAccountAttributesResponse;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&queue_operation
|
||||
* for more details
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Please refer to http://www.aliyun.com/product/mns for more details
|
||||
*
|
||||
* @param endPoint: the host url
|
||||
* could be "http://$accountId.mns.cn-hangzhou.aliyuncs.com"
|
||||
* accountId could be found in aliyun.com
|
||||
* @param accessId: accessId from aliyun.com
|
||||
* @param accessKey: accessKey from aliyun.com
|
||||
* @param securityToken: securityToken from aliyun.com
|
||||
* @param config: necessary configs
|
||||
*/
|
||||
public function __construct($endPoint, $accessId,
|
||||
$accessKey, $securityToken = NULL, Config $config = NULL)
|
||||
{
|
||||
$this->client = new HttpClient($endPoint, $accessId,
|
||||
$accessKey, $securityToken, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a queue reference for operating on the queue
|
||||
* this function does not create the queue automatically.
|
||||
*
|
||||
* @param string $queueName: the queue name
|
||||
* @param bool $base64: whether the message in queue will be base64 encoded
|
||||
*
|
||||
* @return Queue $queue: the Queue instance
|
||||
*/
|
||||
public function getQueueRef($queueName, $base64 = TRUE)
|
||||
{
|
||||
return new Queue($this->client, $queueName, $base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Queue and Returns the Queue reference
|
||||
*
|
||||
* @param CreateQueueRequest $request: the QueueName and QueueAttributes
|
||||
*
|
||||
* @return CreateQueueResponse $response: the CreateQueueResponse
|
||||
*
|
||||
* @throws QueueAlreadyExistException if queue already exists
|
||||
* @throws InvalidArgumentException if any argument value is invalid
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function createQueue(CreateQueueRequest $request)
|
||||
{
|
||||
$response = new CreateQueueResponse($request->getQueueName());
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Queue and Returns the Queue reference
|
||||
* The request will not be sent until calling MnsPromise->wait();
|
||||
*
|
||||
* @param CreateQueueRequest $request: the QueueName and QueueAttributes
|
||||
* @param AsyncCallback $callback: the Callback when the request finishes
|
||||
*
|
||||
* @return MnsPromise $promise: the MnsPromise instance
|
||||
*
|
||||
* @throws MnsException if any exception happends
|
||||
*/
|
||||
public function createQueueAsync(CreateQueueRequest $request,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$response = new CreateQueueResponse($request->getQueueName());
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the queues created by current account
|
||||
*
|
||||
* @param ListQueueRequest $request: define filters for quering queues
|
||||
*
|
||||
* @return ListQueueResponse: the response containing queueNames
|
||||
*/
|
||||
public function listQueue(ListQueueRequest $request)
|
||||
{
|
||||
$response = new ListQueueResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function listQueueAsync(ListQueueRequest $request,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$response = new ListQueueResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the specified queue
|
||||
* the request will succeed even when the queue does not exist
|
||||
*
|
||||
* @param $queueName: the queueName
|
||||
*
|
||||
* @return DeleteQueueResponse
|
||||
*/
|
||||
public function deleteQueue($queueName)
|
||||
{
|
||||
$request = new DeleteQueueRequest($queueName);
|
||||
$response = new DeleteQueueResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function deleteQueueAsync($queueName,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new DeleteQueueRequest($queueName);
|
||||
$response = new DeleteQueueResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
// API for Topic
|
||||
/**
|
||||
* Returns a topic reference for operating on the topic
|
||||
* this function does not create the topic automatically.
|
||||
*
|
||||
* @param string $topicName: the topic name
|
||||
*
|
||||
* @return Topic $topic: the Topic instance
|
||||
*/
|
||||
public function getTopicRef($topicName)
|
||||
{
|
||||
return new Topic($this->client, $topicName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Topic and Returns the Topic reference
|
||||
*
|
||||
* @param CreateTopicRequest $request: the TopicName and TopicAttributes
|
||||
*
|
||||
* @return CreateTopicResponse $response: the CreateTopicResponse
|
||||
*
|
||||
* @throws TopicAlreadyExistException if topic already exists
|
||||
* @throws InvalidArgumentException if any argument value is invalid
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function createTopic(CreateTopicRequest $request)
|
||||
{
|
||||
$response = new CreateTopicResponse($request->getTopicName());
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the specified topic
|
||||
* the request will succeed even when the topic does not exist
|
||||
*
|
||||
* @param $topicName: the topicName
|
||||
*
|
||||
* @return DeleteTopicResponse
|
||||
*/
|
||||
public function deleteTopic($topicName)
|
||||
{
|
||||
$request = new DeleteTopicRequest($topicName);
|
||||
$response = new DeleteTopicResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the topics created by current account
|
||||
*
|
||||
* @param ListTopicRequest $request: define filters for quering topics
|
||||
*
|
||||
* @return ListTopicResponse: the response containing topicNames
|
||||
*/
|
||||
public function listTopic(ListTopicRequest $request)
|
||||
{
|
||||
$response = new ListTopicResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the AccountAttributes
|
||||
*
|
||||
* @return GetAccountAttributesResponse: the response containing topicNames
|
||||
* @throws MnsException if any exception happends
|
||||
*/
|
||||
public function getAccountAttributes()
|
||||
{
|
||||
$request = new GetAccountAttributesRequest();
|
||||
$response = new GetAccountAttributesResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function getAccountAttributesAsync(AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new GetAccountAttributesRequest();
|
||||
$response = new GetAccountAttributesResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AccountAttributes
|
||||
*
|
||||
* @param AccountAttributes $attributes: the AccountAttributes to set
|
||||
*
|
||||
* @return SetAccountAttributesResponse: the response
|
||||
*
|
||||
* @throws MnsException if any exception happends
|
||||
*/
|
||||
public function setAccountAttributes(AccountAttributes $attributes)
|
||||
{
|
||||
$request = new SetAccountAttributesRequest($attributes);
|
||||
$response = new SetAccountAttributesResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function setAccountAttributesAsync(AccountAttributes $attributes,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new SetAccountAttributesRequest($attributes);
|
||||
$response = new SetAccountAttributesResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Common;
|
||||
|
||||
class XMLParser
|
||||
{
|
||||
/**
|
||||
* Most of the error responses are in same format.
|
||||
*/
|
||||
static function parseNormalError(\XMLReader $xmlReader) {
|
||||
$result = array('Code' => NULL, 'Message' => NULL, 'RequestId' => NULL, 'HostId' => NULL);
|
||||
while ($xmlReader->Read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT)
|
||||
{
|
||||
switch ($xmlReader->name) {
|
||||
case 'Code':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$result['Code'] = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'Message':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$result['Message'] = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'RequestId':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$result['RequestId'] = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'HostId':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$result['HostId'] = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace AliyunMNS;
|
||||
|
||||
class Config
|
||||
{
|
||||
//private $maxAttempts;
|
||||
private $proxy; // http://username:password@192.168.16.1:10
|
||||
private $connectTimeout;
|
||||
private $requestTimeout;
|
||||
private $expectContinue;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->maxAttempts = 3;
|
||||
$this->proxy = NULL;
|
||||
$this->requestTimeout = 35; // 35 seconds
|
||||
$this->connectTimeout = 3; // 3 seconds
|
||||
$this->expectContinue = false;
|
||||
}
|
||||
|
||||
/*
|
||||
public function getMaxAttempts()
|
||||
{
|
||||
return $this->maxAttempts;
|
||||
}
|
||||
|
||||
public function setMaxAttempts($maxAttempts)
|
||||
{
|
||||
$this->maxAttempts = $maxAttempts;
|
||||
}
|
||||
*/
|
||||
|
||||
public function getProxy()
|
||||
{
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
public function setProxy($proxy)
|
||||
{
|
||||
$this->proxy = $proxy;
|
||||
}
|
||||
|
||||
public function getRequestTimeout()
|
||||
{
|
||||
return $this->requestTimeout;
|
||||
}
|
||||
|
||||
public function setRequestTimeout($requestTimeout)
|
||||
{
|
||||
$this->requestTimeout = $requestTimeout;
|
||||
}
|
||||
|
||||
public function setConnectTimeout($connectTimeout)
|
||||
{
|
||||
$this->connectTimeout = $connectTimeout;
|
||||
}
|
||||
|
||||
public function getConnectTimeout()
|
||||
{
|
||||
return $this->connectTimeout;
|
||||
}
|
||||
|
||||
public function getExpectContinue()
|
||||
{
|
||||
return $this->expectContinue;
|
||||
}
|
||||
|
||||
public function setExpectContinue($expectContinue)
|
||||
{
|
||||
$this->expectContinue = $expectContinue;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace AliyunMNS;
|
||||
|
||||
class Constants
|
||||
{
|
||||
const GMT_DATE_FORMAT = "D, d M Y H:i:s \\G\\M\\T";
|
||||
|
||||
const MNS_VERSION_HEADER = "x-mns-version";
|
||||
const MNS_HEADER_PREFIX = "x-mns";
|
||||
const MNS_XML_NAMESPACE = "http://mns.aliyuncs.com/doc/v1/";
|
||||
|
||||
const MNS_VERSION = "2015-06-06";
|
||||
const AUTHORIZATION = "Authorization";
|
||||
const MNS = "MNS";
|
||||
|
||||
const CONTENT_LENGTH = "Content-Length";
|
||||
const CONTENT_TYPE = "Content-Type";
|
||||
const SECURITY_TOKEN = "security-token";
|
||||
const DIRECT_MAIL = "DirectMail";
|
||||
const DIRECT_SMS = "DirectSMS";
|
||||
const WEBSOCKET = "WebSocket";
|
||||
|
||||
// XML Tag
|
||||
const ERROR = "Error";
|
||||
const ERRORS = "Errors";
|
||||
const DELAY_SECONDS = "DelaySeconds";
|
||||
const MAXIMUM_MESSAGE_SIZE = "MaximumMessageSize";
|
||||
const MESSAGE_RETENTION_PERIOD = "MessageRetentionPeriod";
|
||||
const VISIBILITY_TIMEOUT = "VisibilityTimeout";
|
||||
const POLLING_WAIT_SECONDS = "PollingWaitSeconds";
|
||||
const MESSAGE_BODY = "MessageBody";
|
||||
const PRIORITY = "Priority";
|
||||
const MESSAGE_ID = "MessageId";
|
||||
const MESSAGE_BODY_MD5 = "MessageBodyMD5";
|
||||
const ENQUEUE_TIME = "EnqueueTime";
|
||||
const NEXT_VISIBLE_TIME = "NextVisibleTime";
|
||||
const FIRST_DEQUEUE_TIME = "FirstDequeueTime";
|
||||
const RECEIPT_HANDLE = "ReceiptHandle";
|
||||
const RECEIPT_HANDLES = "ReceiptHandles";
|
||||
const DEQUEUE_COUNT = "DequeueCount";
|
||||
const ERROR_CODE = "ErrorCode";
|
||||
const ERROR_MESSAGE = "ErrorMessage";
|
||||
const ENDPOINT = "Endpoint";
|
||||
const STRATEGY = "NotifyStrategy";
|
||||
const CONTENT_FORMAT = "NotifyContentFormat";
|
||||
const LOGGING_BUCKET = "LoggingBucket";
|
||||
const LOGGING_ENABLED = "LoggingEnabled";
|
||||
const MESSAGE_ATTRIBUTES = "MessageAttributes";
|
||||
const SUBJECT = "Subject";
|
||||
const ACCOUNT_NAME = "AccountName";
|
||||
const ADDRESS_TYPE = "AddressType";
|
||||
const REPLY_TO_ADDRESS = "ReplyToAddress";
|
||||
const IS_HTML = "IsHtml";
|
||||
const FREE_SIGN_NAME = "FreeSignName";
|
||||
const TEMPLATE_CODE = "TemplateCode";
|
||||
const RECEIVER = "Receiver";
|
||||
const SMS_PARAMS = "SmsParams";
|
||||
const IMPORTANCE_LEVEL = "ImportanceLevel";
|
||||
|
||||
// some MNS ErrorCodes
|
||||
const INVALID_ARGUMENT = "InvalidArgument";
|
||||
const QUEUE_ALREADY_EXIST = "QueueAlreadyExist";
|
||||
const QUEUE_NOT_EXIST = "QueueNotExist";
|
||||
const MALFORMED_XML = "MalformedXML";
|
||||
const MESSAGE_NOT_EXIST = "MessageNotExist";
|
||||
const RECEIPT_HANDLE_ERROR = "ReceiptHandleError";
|
||||
const BATCH_SEND_FAIL = "BatchSendFail";
|
||||
const BATCH_DELETE_FAIL = "BatchDeleteFail";
|
||||
|
||||
const TOPIC_ALREADY_EXIST = "TopicAlreadyExist";
|
||||
const TOPIC_NOT_EXIST = "TopicNotExist";
|
||||
const SUBSCRIPTION_ALREADY_EXIST = "SubscriptionAlreadyExist";
|
||||
const SUBSCRIPTION_NOT_EXIST = "SubscriptionNotExist";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Model\DeleteMessageErrorItem;
|
||||
|
||||
/**
|
||||
* BatchDelete could fail for some receipt handles,
|
||||
* and BatchDeleteFailException will be thrown.
|
||||
* All failed receiptHandles are saved in "$deleteMessageErrorItems"
|
||||
*/
|
||||
class BatchDeleteFailException extends MnsException
|
||||
{
|
||||
protected $deleteMessageErrorItems;
|
||||
|
||||
public function __construct($code, $message, $previousException = NULL, $requestId = NULL, $hostId = NULL)
|
||||
{
|
||||
parent::__construct($code, $message, $previousException, Constants::BATCH_DELETE_FAIL, $requestId, $hostId);
|
||||
|
||||
$this->deleteMessageErrorItems = array();
|
||||
}
|
||||
|
||||
public function addDeleteMessageErrorItem(DeleteMessageErrorItem $item)
|
||||
{
|
||||
$this->deleteMessageErrorItems[] = $item;
|
||||
}
|
||||
|
||||
public function getDeleteMessageErrorItems()
|
||||
{
|
||||
return $this->deleteMessageErrorItems;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Model\SendMessageResponseItem;
|
||||
|
||||
/**
|
||||
* BatchSend could fail for some messages,
|
||||
* and BatchSendFailException will be thrown.
|
||||
* Results for messages are saved in "$sendMessageResponseItems"
|
||||
*/
|
||||
class BatchSendFailException extends MnsException
|
||||
{
|
||||
protected $sendMessageResponseItems;
|
||||
|
||||
public function __construct($code, $message, $previousException = NULL, $requestId = NULL, $hostId = NULL)
|
||||
{
|
||||
parent::__construct($code, $message, $previousException, Constants::BATCH_SEND_FAIL, $requestId, $hostId);
|
||||
|
||||
$this->sendMessageResponseItems = array();
|
||||
}
|
||||
|
||||
public function addSendMessageResponseItem(SendMessageResponseItem $item)
|
||||
{
|
||||
$this->sendMessageResponseItems[] = $item;
|
||||
}
|
||||
|
||||
public function getSendMessageResponseItems()
|
||||
{
|
||||
return $this->sendMessageResponseItems;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class InvalidArgumentException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class MalformedXMLException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class MessageNotExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
class MnsException extends \RuntimeException
|
||||
{
|
||||
private $mnsErrorCode;
|
||||
private $requestId;
|
||||
private $hostId;
|
||||
|
||||
public function __construct($code, $message, $previousException = NULL, $mnsErrorCode = NULL, $requestId = NULL, $hostId = NULL)
|
||||
{
|
||||
parent::__construct($message, $code, $previousException);
|
||||
|
||||
if ($mnsErrorCode == NULL)
|
||||
{
|
||||
if ($code >= 500)
|
||||
{
|
||||
$mnsErrorCode = "ServerError";
|
||||
}
|
||||
else
|
||||
{
|
||||
$mnsErrorCode = "ClientError";
|
||||
}
|
||||
}
|
||||
$this->mnsErrorCode = $mnsErrorCode;
|
||||
|
||||
$this->requestId = $requestId;
|
||||
$this->hostId = $hostId;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$str = "Code: " . $this->getCode() . " Message: " . $this->getMessage();
|
||||
if ($this->mnsErrorCode != NULL)
|
||||
{
|
||||
$str .= " MnsErrorCode: " . $this->mnsErrorCode;
|
||||
}
|
||||
if ($this->requestId != NULL)
|
||||
{
|
||||
$str .= " RequestId: " . $this->requestId;
|
||||
}
|
||||
if ($this->hostId != NULL)
|
||||
{
|
||||
$str .= " HostId: " . $this->hostId;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getMnsErrorCode()
|
||||
{
|
||||
return $this->mnsErrorCode;
|
||||
}
|
||||
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
|
||||
public function getHostId()
|
||||
{
|
||||
return $this->hostId;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class QueueAlreadyExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class QueueNotExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class ReceiptHandleErrorException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class SubscriptionAlreadyExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class SubscriptionNotExistException extends MnsException
|
||||
{
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class TopicAlreadyExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Exception;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class TopicNotExistException extends MnsException
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Http;
|
||||
|
||||
use AliyunMNS\Config;
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Signature\Signature;
|
||||
use AliyunMNS\AsyncCallback;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use AliyunMNS\Responses\MnsPromise;
|
||||
|
||||
class HttpClient
|
||||
{
|
||||
private $client;
|
||||
private $region;
|
||||
private $accountId;
|
||||
private $accessId;
|
||||
private $accessKey;
|
||||
private $securityToken;
|
||||
private $requestTimeout;
|
||||
private $connectTimeout;
|
||||
|
||||
public function __construct($endPoint, $accessId,
|
||||
$accessKey, $securityToken = NULL, Config $config = NULL)
|
||||
{
|
||||
if ($config == NULL)
|
||||
{
|
||||
$config = new Config;
|
||||
}
|
||||
$this->accessId = $accessId;
|
||||
$this->accessKey = $accessKey;
|
||||
$this->client = new \GuzzleHttp\Client([
|
||||
'base_uri' => $endPoint,
|
||||
'defaults' => [
|
||||
'headers' => [
|
||||
'Host' => $endPoint
|
||||
],
|
||||
'proxy' => $config->getProxy(),
|
||||
'expect' => $config->getExpectContinue()
|
||||
]
|
||||
]);
|
||||
$this->requestTimeout = $config->getRequestTimeout();
|
||||
$this->connectTimeout = $config->getConnectTimeout();
|
||||
$this->securityToken = $securityToken;
|
||||
$this->endpoint = $endPoint;
|
||||
$this->parseEndpoint();
|
||||
}
|
||||
|
||||
public function getRegion()
|
||||
{
|
||||
return $this->region;
|
||||
}
|
||||
|
||||
public function getAccountId()
|
||||
{
|
||||
return $this->accountId;
|
||||
}
|
||||
|
||||
// This function is for SDK internal use
|
||||
private function parseEndpoint()
|
||||
{
|
||||
$pieces = explode("//", $this->endpoint);
|
||||
$host = end($pieces);
|
||||
|
||||
$host_pieces = explode(".", $host);
|
||||
$this->accountId = $host_pieces[0];
|
||||
$region_pieces = explode("-internal", $host_pieces[2]);
|
||||
$this->region = $region_pieces[0];
|
||||
}
|
||||
|
||||
private function addRequiredHeaders(BaseRequest &$request)
|
||||
{
|
||||
$body = $request->generateBody();
|
||||
$queryString = $request->generateQueryString();
|
||||
|
||||
$request->setBody($body);
|
||||
$request->setQueryString($queryString);
|
||||
|
||||
if ($body != NULL)
|
||||
{
|
||||
$request->setHeader(Constants::CONTENT_LENGTH, strlen($body));
|
||||
}
|
||||
$request->setHeader('Date', gmdate(Constants::GMT_DATE_FORMAT));
|
||||
if (!$request->isHeaderSet(Constants::CONTENT_TYPE))
|
||||
{
|
||||
$request->setHeader(Constants::CONTENT_TYPE, 'text/xml');
|
||||
}
|
||||
$request->setHeader(Constants::MNS_VERSION_HEADER, Constants::MNS_VERSION);
|
||||
|
||||
if ($this->securityToken != NULL)
|
||||
{
|
||||
$request->setHeader(Constants::SECURITY_TOKEN, $this->securityToken);
|
||||
}
|
||||
|
||||
$sign = Signature::SignRequest($this->accessKey, $request);
|
||||
$request->setHeader(Constants::AUTHORIZATION,
|
||||
Constants::MNS . " " . $this->accessId . ":" . $sign);
|
||||
}
|
||||
|
||||
public function sendRequestAsync(BaseRequest $request,
|
||||
BaseResponse &$response, AsyncCallback $callback = NULL)
|
||||
{
|
||||
$promise = $this->sendRequestAsyncInternal($request, $response, $callback);
|
||||
return new MnsPromise($promise, $response);
|
||||
}
|
||||
|
||||
public function sendRequest(BaseRequest $request, BaseResponse &$response)
|
||||
{
|
||||
$promise = $this->sendRequestAsync($request, $response);
|
||||
return $promise->wait();
|
||||
}
|
||||
|
||||
private function sendRequestAsyncInternal(BaseRequest &$request, BaseResponse &$response, AsyncCallback $callback = NULL)
|
||||
{
|
||||
$this->addRequiredHeaders($request);
|
||||
|
||||
$parameters = array('exceptions' => false, 'http_errors' => false);
|
||||
$queryString = $request->getQueryString();
|
||||
$body = $request->getBody();
|
||||
if ($queryString != NULL) {
|
||||
$parameters['query'] = $queryString;
|
||||
}
|
||||
if ($body != NULL) {
|
||||
$parameters['body'] = $body;
|
||||
}
|
||||
|
||||
$parameters['timeout'] = $this->requestTimeout;
|
||||
$parameters['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$request = new Request(strtoupper($request->getMethod()),
|
||||
$request->getResourcePath(), $request->getHeaders());
|
||||
try
|
||||
{
|
||||
if ($callback != NULL)
|
||||
{
|
||||
return $this->client->sendAsync($request, $parameters)->then(
|
||||
function ($res) use (&$response, $callback) {
|
||||
try {
|
||||
$response->parseResponse($res->getStatusCode(), $res->getBody());
|
||||
$callback->onSucceed($response);
|
||||
} catch (MnsException $e) {
|
||||
$callback->onFailed($e);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->client->sendAsync($request, $parameters);
|
||||
}
|
||||
}
|
||||
catch (TransferException $e)
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
if ($e->hasResponse()) {
|
||||
$message = $e->getResponse()->getBody();
|
||||
}
|
||||
throw new MnsException($e->getCode(), $message, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/intro&intro
|
||||
* for more details
|
||||
*/
|
||||
class AccountAttributes
|
||||
{
|
||||
private $loggingBucket;
|
||||
|
||||
public function __construct(
|
||||
$loggingBucket = NULL)
|
||||
{
|
||||
$this->loggingBucket = $loggingBucket;
|
||||
}
|
||||
|
||||
public function setLoggingBucket($loggingBucket)
|
||||
{
|
||||
$this->loggingBucket = $loggingBucket;
|
||||
}
|
||||
|
||||
public function getLoggingBucket()
|
||||
{
|
||||
return $this->loggingBucket;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
if ($this->loggingBucket !== NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::LOGGING_BUCKET, $this->loggingBucket);
|
||||
}
|
||||
}
|
||||
|
||||
static public function fromXML(\XMLReader $xmlReader)
|
||||
{
|
||||
$loggingBucket = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT)
|
||||
{
|
||||
switch ($xmlReader->name) {
|
||||
case 'LoggingBucket':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$loggingBucket = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$attributes = new AccountAttributes($loggingBucket);
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://help.aliyun.com/document_detail/44501.html
|
||||
* for more details
|
||||
*/
|
||||
class BatchSmsAttributes
|
||||
{
|
||||
public $freeSignName;
|
||||
public $templateCode;
|
||||
public $smsParams;
|
||||
|
||||
public function __construct(
|
||||
$freeSignName, $templateCode, $smsParams=null)
|
||||
{
|
||||
$this->freeSignName = $freeSignName;
|
||||
$this->templateCode = $templateCode;
|
||||
$this->smsParams = $smsParams;
|
||||
}
|
||||
|
||||
public function setFreeSignName($freeSignName)
|
||||
{
|
||||
$this->freeSignName = $freeSignName;
|
||||
}
|
||||
|
||||
public function getFreeSignName()
|
||||
{
|
||||
return $this->freeSignName;
|
||||
}
|
||||
|
||||
public function setTemplateCode($templateCode)
|
||||
{
|
||||
$this->templateCode = $templateCode;
|
||||
}
|
||||
|
||||
public function getTemplateCode()
|
||||
{
|
||||
return $this->templateCode;
|
||||
}
|
||||
|
||||
public function addReceiver($phone, $params)
|
||||
{
|
||||
if (!is_array($params))
|
||||
{
|
||||
throw new MnsException(400, "Params Should be Array!");
|
||||
}
|
||||
|
||||
if ($this->smsParams == null)
|
||||
{
|
||||
$this->smsParams = array();
|
||||
}
|
||||
|
||||
$this->smsParams[$phone] = $params;
|
||||
}
|
||||
|
||||
public function getSmsParams()
|
||||
{
|
||||
return $this->smsParams;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
$jsonArray = array("Type" => "multiContent");
|
||||
if ($this->freeSignName !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::FREE_SIGN_NAME] = $this->freeSignName;
|
||||
}
|
||||
if ($this->templateCode !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::TEMPLATE_CODE] = $this->templateCode;
|
||||
}
|
||||
|
||||
if ($this->smsParams != null)
|
||||
{
|
||||
if (!is_array($this->smsParams))
|
||||
{
|
||||
throw new MnsException(400, "SmsParams should be an array!");
|
||||
}
|
||||
if (!empty($this->smsParams))
|
||||
{
|
||||
$jsonArray[Constants::SMS_PARAMS] = json_encode($this->smsParams, JSON_FORCE_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($jsonArray))
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::DIRECT_SMS, json_encode($jsonArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
class DeleteMessageErrorItem
|
||||
{
|
||||
protected $errorCode;
|
||||
protected $errorMessage;
|
||||
protected $receiptHandle;
|
||||
|
||||
public function __construct($errorCode, $errorMessage, $receiptHandle)
|
||||
{
|
||||
$this->errorCode = $errorCode;
|
||||
$this->errorMessage = $errorMessage;
|
||||
$this->receiptHandle = $receiptHandle;
|
||||
}
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
public function getReceiptHandle()
|
||||
{
|
||||
return $this->receiptHandle;
|
||||
}
|
||||
|
||||
static public function fromXML($xmlReader)
|
||||
{
|
||||
$errorCode = NULL;
|
||||
$errorMessage = NULL;
|
||||
$receiptHandle = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
switch ($xmlReader->nodeType)
|
||||
{
|
||||
case \XMLReader::ELEMENT:
|
||||
switch ($xmlReader->name)
|
||||
{
|
||||
case Constants::ERROR_CODE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$errorCode = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::ERROR_MESSAGE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$errorMessage = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::RECEIPT_HANDLE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$receiptHandle = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case \XMLReader::END_ELEMENT:
|
||||
if ($xmlReader->name == Constants::ERROR)
|
||||
{
|
||||
return new DeleteMessageErrorItem($errorCode, $errorMessage, $receiptHandle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new DeleteMessageErrorItem($errorCode, $errorMessage, $receiptHandle);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/intro&intro
|
||||
* for more details
|
||||
*/
|
||||
class MailAttributes
|
||||
{
|
||||
public $subject;
|
||||
public $accountName;
|
||||
public $addressType;
|
||||
public $replyToAddress;
|
||||
public $isHtml;
|
||||
|
||||
public function __construct(
|
||||
$subject, $accountName, $addressType=0, $replyToAddress=false, $isHtml = false)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->accountName = $accountName;
|
||||
$this->addressType = $addressType;
|
||||
$this->replyToAddress = $replyToAddress;
|
||||
$this->isHtml = $isHtml;
|
||||
}
|
||||
|
||||
public function setSubject($subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function setAccountName($accountName)
|
||||
{
|
||||
$this->accountName = $accountName;
|
||||
}
|
||||
|
||||
public function getAccountName()
|
||||
{
|
||||
return $this->accountName;
|
||||
}
|
||||
|
||||
public function setAddressType($addressType)
|
||||
{
|
||||
$this->addressType = $addressType;
|
||||
}
|
||||
|
||||
public function getAddressType()
|
||||
{
|
||||
return $this->addressType;
|
||||
}
|
||||
|
||||
public function setReplyToAddress($replyToAddress)
|
||||
{
|
||||
$this->replyToAddress = $replyToAddress;
|
||||
}
|
||||
|
||||
public function getReplyToAddress()
|
||||
{
|
||||
return $this->replyToAddress;
|
||||
}
|
||||
|
||||
public function setIsHtml($isHtml)
|
||||
{
|
||||
$this->isHtml = $isHtml;
|
||||
}
|
||||
|
||||
public function getIsHtml()
|
||||
{
|
||||
return $this->isHtml;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
$jsonArray = array();
|
||||
if ($this->subject !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::SUBJECT] = $this->subject;
|
||||
}
|
||||
if ($this->accountName !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::ACCOUNT_NAME] = $this->accountName;
|
||||
}
|
||||
if ($this->addressType !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::ADDRESS_TYPE] = $this->addressType;
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsonArray[Constants::ADDRESS_TYPE] = 0;
|
||||
}
|
||||
if ($this->replyToAddress !== NULL)
|
||||
{
|
||||
if ($this->replyToAddress === TRUE)
|
||||
{
|
||||
$jsonArray[Constants::REPLY_TO_ADDRESS] = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsonArray[Constants::REPLY_TO_ADDRESS] = "0";
|
||||
}
|
||||
}
|
||||
if ($this->isHtml !== NULL)
|
||||
{
|
||||
if ($this->isHtml === TRUE)
|
||||
{
|
||||
$jsonArray[Constants::IS_HTML] = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsonArray[Constants::IS_HTML] = "0";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($jsonArray))
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::DIRECT_MAIL, json_encode($jsonArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Traits\MessagePropertiesForReceive;
|
||||
|
||||
class Message
|
||||
{
|
||||
use MessagePropertiesForReceive;
|
||||
|
||||
public function __construct($messageId, $messageBodyMD5, $messageBody, $enqueueTime, $nextVisibleTime, $firstDequeueTime, $dequeueCount, $priority, $receiptHandle)
|
||||
{
|
||||
$this->messageId = $messageId;
|
||||
$this->messageBodyMD5 = $messageBodyMD5;
|
||||
$this->messageBody = $messageBody;
|
||||
$this->enqueueTime = $enqueueTime;
|
||||
$this->nextVisibleTime = $nextVisibleTime;
|
||||
$this->firstDequeueTime = $firstDequeueTime;
|
||||
$this->dequeueCount = $dequeueCount;
|
||||
$this->priority = $priority;
|
||||
$this->receiptHandle = $receiptHandle;
|
||||
}
|
||||
|
||||
static public function fromXML(\XMLReader $xmlReader, $base64)
|
||||
{
|
||||
$messageId = NULL;
|
||||
$messageBodyMD5 = NULL;
|
||||
$messageBody = NULL;
|
||||
$enqueueTime = NULL;
|
||||
$nextVisibleTime = NULL;
|
||||
$firstDequeueTime = NULL;
|
||||
$dequeueCount = NULL;
|
||||
$priority = NULL;
|
||||
$receiptHandle = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
switch ($xmlReader->nodeType)
|
||||
{
|
||||
case \XMLReader::ELEMENT:
|
||||
switch ($xmlReader->name) {
|
||||
case Constants::MESSAGE_ID:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageId = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::MESSAGE_BODY_MD5:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageBodyMD5 = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::MESSAGE_BODY:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
if ($base64 == TRUE) {
|
||||
$messageBody = base64_decode($xmlReader->value);
|
||||
} else {
|
||||
$messageBody = $xmlReader->value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Constants::ENQUEUE_TIME:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$enqueueTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::NEXT_VISIBLE_TIME:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$nextVisibleTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::FIRST_DEQUEUE_TIME:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$firstDequeueTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::DEQUEUE_COUNT:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$dequeueCount = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::PRIORITY:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$priority = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::RECEIPT_HANDLE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$receiptHandle = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case \XMLReader::END_ELEMENT:
|
||||
if ($xmlReader->name == 'Message')
|
||||
{
|
||||
$message = new Message(
|
||||
$messageId,
|
||||
$messageBodyMD5,
|
||||
$messageBody,
|
||||
$enqueueTime,
|
||||
$nextVisibleTime,
|
||||
$firstDequeueTime,
|
||||
$dequeueCount,
|
||||
$priority,
|
||||
$receiptHandle);
|
||||
return $message;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Message(
|
||||
$messageId,
|
||||
$messageBodyMD5,
|
||||
$messageBody,
|
||||
$enqueueTime,
|
||||
$nextVisibleTime,
|
||||
$firstDequeueTime,
|
||||
$dequeueCount,
|
||||
$priority,
|
||||
$receiptHandle);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/intro&intro
|
||||
* for more details
|
||||
*/
|
||||
class MessageAttributes
|
||||
{
|
||||
// if both SmsAttributes and BatchSmsAttributes are set, only one will take effect
|
||||
private $attributes;
|
||||
|
||||
public function __construct(
|
||||
$attributes = NULL)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
$xmlWriter->startELement(Constants::MESSAGE_ATTRIBUTES);
|
||||
if ($this->attributes != NULL)
|
||||
{
|
||||
if (is_array($this->attributes))
|
||||
{
|
||||
foreach ($this->attributes as $subAttributes)
|
||||
{
|
||||
$subAttributes->writeXML($xmlWriter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/intro&intro
|
||||
* for more details
|
||||
*/
|
||||
class QueueAttributes
|
||||
{
|
||||
private $delaySeconds;
|
||||
private $maximumMessageSize;
|
||||
private $messageRetentionPeriod;
|
||||
private $visibilityTimeout;
|
||||
private $pollingWaitSeconds;
|
||||
private $LoggingEnabled;
|
||||
|
||||
# the following attributes cannot be changed
|
||||
private $queueName;
|
||||
private $createTime;
|
||||
private $lastModifyTime;
|
||||
private $activeMessages;
|
||||
private $inactiveMessages;
|
||||
private $delayMessages;
|
||||
|
||||
public function __construct(
|
||||
$delaySeconds = NULL,
|
||||
$maximumMessageSize = NULL,
|
||||
$messageRetentionPeriod = NULL,
|
||||
$visibilityTimeout = NULL,
|
||||
$pollingWaitSeconds = NULL,
|
||||
$queueName = NULL,
|
||||
$createTime = NULL,
|
||||
$lastModifyTime = NULL,
|
||||
$activeMessages = NULL,
|
||||
$inactiveMessages = NULL,
|
||||
$delayMessages = NULL,
|
||||
$LoggingEnabled = NULL)
|
||||
{
|
||||
$this->delaySeconds = $delaySeconds;
|
||||
$this->maximumMessageSize = $maximumMessageSize;
|
||||
$this->messageRetentionPeriod = $messageRetentionPeriod;
|
||||
$this->visibilityTimeout = $visibilityTimeout;
|
||||
$this->pollingWaitSeconds = $pollingWaitSeconds;
|
||||
$this->loggingEnabled = $LoggingEnabled;
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->createTime = $createTime;
|
||||
$this->lastModifyTime = $lastModifyTime;
|
||||
$this->activeMessages = $activeMessages;
|
||||
$this->inactiveMessages = $inactiveMessages;
|
||||
$this->delayMessages = $delayMessages;
|
||||
}
|
||||
|
||||
public function setDelaySeconds($delaySeconds)
|
||||
{
|
||||
$this->delaySeconds = $delaySeconds;
|
||||
}
|
||||
|
||||
public function getDelaySeconds()
|
||||
{
|
||||
return $this->delaySeconds;
|
||||
}
|
||||
|
||||
public function setLoggingEnabled($loggingEnabled)
|
||||
{
|
||||
$this->loggingEnabled = $loggingEnabled;
|
||||
}
|
||||
|
||||
public function getLoggingEnabled()
|
||||
{
|
||||
return $this->loggingEnabled;
|
||||
}
|
||||
|
||||
public function setMaximumMessageSize($maximumMessageSize)
|
||||
{
|
||||
$this->maximumMessageSize = $maximumMessageSize;
|
||||
}
|
||||
|
||||
public function getMaximumMessageSize()
|
||||
{
|
||||
return $this->maximumMessageSize;
|
||||
}
|
||||
|
||||
public function setMessageRetentionPeriod($messageRetentionPeriod)
|
||||
{
|
||||
$this->messageRetentionPeriod = $messageRetentionPeriod;
|
||||
}
|
||||
|
||||
public function getMessageRetentionPeriod()
|
||||
{
|
||||
return $this->messageRetentionPeriod;
|
||||
}
|
||||
|
||||
public function setVisibilityTimeout($visibilityTimeout)
|
||||
{
|
||||
$this->visibilityTimeout = $visibilityTimeout;
|
||||
}
|
||||
|
||||
public function getVisibilityTimeout()
|
||||
{
|
||||
return $this->visibilityTimeout;
|
||||
}
|
||||
|
||||
public function setPollingWaitSeconds($pollingWaitSeconds)
|
||||
{
|
||||
$this->pollingWaitSeconds = $pollingWaitSeconds;
|
||||
}
|
||||
|
||||
public function getPollingWaitSeconds()
|
||||
{
|
||||
return $this->pollingWaitSeconds;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getCreateTime()
|
||||
{
|
||||
return $this->createTime;
|
||||
}
|
||||
|
||||
public function getLastModifyTime()
|
||||
{
|
||||
return $this->lastModifyTime;
|
||||
}
|
||||
|
||||
public function getActiveMessages()
|
||||
{
|
||||
return $this->activeMessages;
|
||||
}
|
||||
|
||||
public function getInactiveMessages()
|
||||
{
|
||||
return $this->inactiveMessages;
|
||||
}
|
||||
|
||||
public function getDelayMessages()
|
||||
{
|
||||
return $this->delayMessages;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
if ($this->delaySeconds != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::DELAY_SECONDS, $this->delaySeconds);
|
||||
}
|
||||
if ($this->maximumMessageSize != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::MAXIMUM_MESSAGE_SIZE, $this->maximumMessageSize);
|
||||
}
|
||||
if ($this->messageRetentionPeriod != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::MESSAGE_RETENTION_PERIOD, $this->messageRetentionPeriod);
|
||||
}
|
||||
if ($this->visibilityTimeout != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::VISIBILITY_TIMEOUT, $this->visibilityTimeout);
|
||||
}
|
||||
if ($this->pollingWaitSeconds != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::POLLING_WAIT_SECONDS, $this->pollingWaitSeconds);
|
||||
}
|
||||
if ($this->loggingEnabled !== NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::LOGGING_ENABLED, $this->loggingEnabled ? "True" : "False");
|
||||
}
|
||||
}
|
||||
|
||||
static public function fromXML(\XMLReader $xmlReader)
|
||||
{
|
||||
$delaySeconds = NULL;
|
||||
$maximumMessageSize = NULL;
|
||||
$messageRetentionPeriod = NULL;
|
||||
$visibilityTimeout = NULL;
|
||||
$pollingWaitSeconds = NULL;
|
||||
$queueName = NULL;
|
||||
$createTime = NULL;
|
||||
$lastModifyTime = NULL;
|
||||
$activeMessages = NULL;
|
||||
$inactiveMessages = NULL;
|
||||
$delayMessages = NULL;
|
||||
$loggingEnabled = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT)
|
||||
{
|
||||
switch ($xmlReader->name) {
|
||||
case 'DelaySeconds':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$delaySeconds = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'MaximumMessageSize':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$maximumMessageSize = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'MessageRetentionPeriod':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageRetentionPeriod = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'VisibilityTimeout':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$visibilityTimeout = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'PollingWaitSeconds':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$pollingWaitSeconds = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'QueueName':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$queueName = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'CreateTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$createTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'LastModifyTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$lastModifyTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'ActiveMessages':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$activeMessages = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'InactiveMessages':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$inactiveMessages = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'DelayMessages':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$delayMessages = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'LoggingEnabled':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$loggingEnabled = $xmlReader->value;
|
||||
if ($loggingEnabled == "True")
|
||||
{
|
||||
$loggingEnabled = True;
|
||||
}
|
||||
else
|
||||
{
|
||||
$loggingEnabled = False;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$attributes = new QueueAttributes(
|
||||
$delaySeconds,
|
||||
$maximumMessageSize,
|
||||
$messageRetentionPeriod,
|
||||
$visibilityTimeout,
|
||||
$pollingWaitSeconds,
|
||||
$queueName,
|
||||
$createTime,
|
||||
$lastModifyTime,
|
||||
$activeMessages,
|
||||
$inactiveMessages,
|
||||
$delayMessages,
|
||||
$loggingEnabled);
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Traits\MessagePropertiesForSend;
|
||||
|
||||
// this class is used for BatchSend
|
||||
class SendMessageRequestItem
|
||||
{
|
||||
use MessagePropertiesForSend;
|
||||
|
||||
public function __construct($messageBody, $delaySeconds = NULL, $priority = NULL)
|
||||
{
|
||||
$this->messageBody = $messageBody;
|
||||
$this->delaySeconds = $delaySeconds;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter, $base64)
|
||||
{
|
||||
$xmlWriter->startELement('Message');
|
||||
$this->writeMessagePropertiesForSendXML($xmlWriter, $base64);
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Traits\MessageIdAndMD5;
|
||||
|
||||
/**
|
||||
* if isSucceed() == TRUE, the messageId and messageBodyMD5 are returned.
|
||||
* otherwise, the errorCode and errorMessage are returned.
|
||||
*/
|
||||
class SendMessageResponseItem
|
||||
{
|
||||
use MessageIdAndMD5;
|
||||
|
||||
protected $isSucceed;
|
||||
protected $errorCode;
|
||||
protected $errorMessage;
|
||||
|
||||
public function __construct($isSucceed, $param1, $param2)
|
||||
{
|
||||
$this->isSucceed = $isSucceed;
|
||||
if ($isSucceed == TRUE)
|
||||
{
|
||||
$this->messageId = $param1;
|
||||
$this->messageBodyMD5 = $param2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errorCode = $param1;
|
||||
$this->errorMessage = $param2;
|
||||
}
|
||||
}
|
||||
|
||||
public function isSucceed()
|
||||
{
|
||||
return $this->isSucceed;
|
||||
}
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
static public function fromXML($xmlReader)
|
||||
{
|
||||
$messageId = NULL;
|
||||
$messageBodyMD5 = NULL;
|
||||
$errorCode = NULL;
|
||||
$errorMessage = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
switch ($xmlReader->nodeType)
|
||||
{
|
||||
case \XMLReader::ELEMENT:
|
||||
switch ($xmlReader->name) {
|
||||
case Constants::MESSAGE_ID:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageId = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::MESSAGE_BODY_MD5:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageBodyMD5 = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::ERROR_CODE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$errorCode = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case Constants::ERROR_MESSAGE:
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$errorMessage = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case \XMLReader::END_ELEMENT:
|
||||
if ($xmlReader->name == 'Message')
|
||||
{
|
||||
if ($messageId != NULL)
|
||||
{
|
||||
return new SendMessageResponseItem(TRUE, $messageId, $messageBodyMD5);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SendMessageResponseItem(FALSE, $errorCode, $errorMessage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($messageId != NULL)
|
||||
{
|
||||
return new SendMessageResponseItem(TRUE, $messageId, $messageBodyMD5);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SendMessageResponseItem(FALSE, $errorCode, $errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://help.aliyun.com/document_detail/44501.html
|
||||
* for more details
|
||||
*/
|
||||
class SmsAttributes
|
||||
{
|
||||
public $freeSignName;
|
||||
public $templateCode;
|
||||
public $smsParams;
|
||||
public $receiver;
|
||||
|
||||
public function __construct(
|
||||
$freeSignName, $templateCode, $smsParams=array(), $receiver=null)
|
||||
{
|
||||
$this->freeSignName = $freeSignName;
|
||||
$this->templateCode = $templateCode;
|
||||
$this->smsParams = $smsParams;
|
||||
$this->receiver = $receiver;
|
||||
}
|
||||
|
||||
public function setFreeSignName($freeSignName)
|
||||
{
|
||||
$this->freeSignName = $freeSignName;
|
||||
}
|
||||
|
||||
public function getFreeSignName()
|
||||
{
|
||||
return $this->freeSignName;
|
||||
}
|
||||
|
||||
public function setTemplateCode($templateCode)
|
||||
{
|
||||
$this->templateCode = $templateCode;
|
||||
}
|
||||
|
||||
public function getTemplateCode()
|
||||
{
|
||||
return $this->templateCode;
|
||||
}
|
||||
|
||||
public function setSmsParams($smsParams)
|
||||
{
|
||||
$this->smsParams = $smsParams;
|
||||
}
|
||||
|
||||
public function getSmsParams()
|
||||
{
|
||||
return $this->smsParams;
|
||||
}
|
||||
|
||||
public function setReceiver($receiver)
|
||||
{
|
||||
$this->receiver = $receiver;
|
||||
}
|
||||
|
||||
public function getReceiver()
|
||||
{
|
||||
return $this->receiver;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
$jsonArray = array();
|
||||
if ($this->freeSignName !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::FREE_SIGN_NAME] = $this->freeSignName;
|
||||
}
|
||||
if ($this->templateCode !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::TEMPLATE_CODE] = $this->templateCode;
|
||||
}
|
||||
if ($this->receiver !== NULL)
|
||||
{
|
||||
$jsonArray[Constants::RECEIVER] = $this->receiver;
|
||||
}
|
||||
|
||||
if ($this->smsParams !== null)
|
||||
{
|
||||
if (!is_array($this->smsParams))
|
||||
{
|
||||
throw new MnsException(400, "SmsParams should be an array!");
|
||||
}
|
||||
$jsonArray[Constants::SMS_PARAMS] = json_encode($this->smsParams, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
if (!empty($jsonArray))
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::DIRECT_SMS, json_encode($jsonArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
class SubscriptionAttributes
|
||||
{
|
||||
private $endpoint;
|
||||
private $strategy;
|
||||
private $contentFormat;
|
||||
|
||||
# may change in AliyunMNS\Topic
|
||||
private $topicName;
|
||||
|
||||
# the following attributes cannot be changed
|
||||
private $subscriptionName;
|
||||
private $topicOwner;
|
||||
private $createTime;
|
||||
private $lastModifyTime;
|
||||
|
||||
public function __construct(
|
||||
$subscriptionName = NULL,
|
||||
$endpoint = NULL,
|
||||
$strategy = NULL,
|
||||
$contentFormat = NULL,
|
||||
$topicName = NULL,
|
||||
$topicOwner = NULL,
|
||||
$createTime = NULL,
|
||||
$lastModifyTime = NULL)
|
||||
{
|
||||
$this->endpoint = $endpoint;
|
||||
$this->strategy = $strategy;
|
||||
$this->contentFormat = $contentFormat;
|
||||
$this->subscriptionName = $subscriptionName;
|
||||
|
||||
//cloud change in AliyunMNS\Topic
|
||||
$this->topicName = $topicName;
|
||||
|
||||
$this->topicOwner = $topicOwner;
|
||||
$this->createTime = $createTime;
|
||||
$this->lastModifyTime = $lastModifyTime;
|
||||
}
|
||||
|
||||
public function getEndpoint()
|
||||
{
|
||||
return $this->endpoint;
|
||||
}
|
||||
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
$this->endpoint = $endpoint;
|
||||
}
|
||||
|
||||
public function getStrategy()
|
||||
{
|
||||
return $this->strategy;
|
||||
}
|
||||
|
||||
public function setStrategy($strategy)
|
||||
{
|
||||
$this->strategy = $strategy;
|
||||
}
|
||||
|
||||
public function getContentFormat()
|
||||
{
|
||||
return $this->contentFormat;
|
||||
}
|
||||
|
||||
public function setContentFormat($contentFormat)
|
||||
{
|
||||
$this->contentFormat = $contentFormat;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function setTopicName($topicName)
|
||||
{
|
||||
$this->topicName = $topicName;
|
||||
}
|
||||
|
||||
public function getTopicOwner()
|
||||
{
|
||||
return $this->topicOwner;
|
||||
}
|
||||
|
||||
public function getSubscriptionName()
|
||||
{
|
||||
return $this->subscriptionName;
|
||||
}
|
||||
|
||||
public function getCreateTime()
|
||||
{
|
||||
return $this->createTime;
|
||||
}
|
||||
|
||||
public function getLastModifyTime()
|
||||
{
|
||||
return $this->lastModifyTime;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
if ($this->endpoint != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::ENDPOINT, $this->endpoint);
|
||||
}
|
||||
if ($this->strategy != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::STRATEGY, $this->strategy);
|
||||
}
|
||||
if ($this->contentFormat != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::CONTENT_FORMAT, $this->contentFormat);
|
||||
}
|
||||
}
|
||||
|
||||
static public function fromXML(\XMLReader $xmlReader)
|
||||
{
|
||||
$endpoint = NULL;
|
||||
$strategy = NULL;
|
||||
$contentFormat = NULL;
|
||||
$topicOwner = NULL;
|
||||
$topicName = NULL;
|
||||
$createTime = NULL;
|
||||
$lastModifyTime = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT)
|
||||
{
|
||||
switch ($xmlReader->name) {
|
||||
case 'TopicOwner':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$topicOwner = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'TopicName':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$topicName = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'SubscriptionName':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$subscriptionName = $xmlReader->value;
|
||||
}
|
||||
case 'Endpoint':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$endpoint = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'NotifyStrategy':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$strategy = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'NotifyContentFormat':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$contentFormat = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'CreateTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$createTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'LastModifyTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$lastModifyTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$attributes = new SubscriptionAttributes(
|
||||
$subscriptionName,
|
||||
$endpoint,
|
||||
$strategy,
|
||||
$contentFormat,
|
||||
$topicName,
|
||||
$topicOwner,
|
||||
$createTime,
|
||||
$lastModifyTime);
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
/**
|
||||
* Please refer to
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/intro&intro
|
||||
* for more details
|
||||
*/
|
||||
class TopicAttributes
|
||||
{
|
||||
private $maximumMessageSize;
|
||||
private $messageRetentionPeriod;
|
||||
private $LoggingEnabled;
|
||||
|
||||
# the following attributes cannot be changed
|
||||
private $topicName;
|
||||
private $createTime;
|
||||
private $lastModifyTime;
|
||||
|
||||
public function __construct(
|
||||
$maximumMessageSize = NULL,
|
||||
$messageRetentionPeriod = NULL,
|
||||
$topicName = NULL,
|
||||
$createTime = NULL,
|
||||
$lastModifyTime = NULL,
|
||||
$LoggingEnabled = NULL)
|
||||
{
|
||||
$this->maximumMessageSize = $maximumMessageSize;
|
||||
$this->messageRetentionPeriod = $messageRetentionPeriod;
|
||||
$this->loggingEnabled = $LoggingEnabled;
|
||||
|
||||
$this->topicName = $topicName;
|
||||
$this->createTime = $createTime;
|
||||
$this->lastModifyTime = $lastModifyTime;
|
||||
}
|
||||
|
||||
public function setMaximumMessageSize($maximumMessageSize)
|
||||
{
|
||||
$this->maximumMessageSize = $maximumMessageSize;
|
||||
}
|
||||
|
||||
public function getMaximumMessageSize()
|
||||
{
|
||||
return $this->maximumMessageSize;
|
||||
}
|
||||
|
||||
public function setLoggingEnabled($loggingEnabled)
|
||||
{
|
||||
$this->loggingEnabled = $loggingEnabled;
|
||||
}
|
||||
|
||||
public function getLoggingEnabled()
|
||||
{
|
||||
return $this->loggingEnabled;
|
||||
}
|
||||
|
||||
public function setMessageRetentionPeriod($messageRetentionPeriod)
|
||||
{
|
||||
$this->messageRetentionPeriod = $messageRetentionPeriod;
|
||||
}
|
||||
|
||||
public function getMessageRetentionPeriod()
|
||||
{
|
||||
return $this->messageRetentionPeriod;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getCreateTime()
|
||||
{
|
||||
return $this->createTime;
|
||||
}
|
||||
|
||||
public function getLastModifyTime()
|
||||
{
|
||||
return $this->lastModifyTime;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
if ($this->maximumMessageSize != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::MAXIMUM_MESSAGE_SIZE, $this->maximumMessageSize);
|
||||
}
|
||||
if ($this->messageRetentionPeriod != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::MESSAGE_RETENTION_PERIOD, $this->messageRetentionPeriod);
|
||||
}
|
||||
if ($this->loggingEnabled !== NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::LOGGING_ENABLED, $this->loggingEnabled ? "True" : "False");
|
||||
}
|
||||
}
|
||||
|
||||
static public function fromXML(\XMLReader $xmlReader)
|
||||
{
|
||||
$maximumMessageSize = NULL;
|
||||
$messageRetentionPeriod = NULL;
|
||||
$topicName = NULL;
|
||||
$createTime = NULL;
|
||||
$lastModifyTime = NULL;
|
||||
$loggingEnabled = NULL;
|
||||
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT)
|
||||
{
|
||||
switch ($xmlReader->name) {
|
||||
case 'MaximumMessageSize':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$maximumMessageSize = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'MessageRetentionPeriod':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$messageRetentionPeriod = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'TopicName':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$topicName = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'CreateTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$createTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'LastModifyTime':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$lastModifyTime = $xmlReader->value;
|
||||
}
|
||||
break;
|
||||
case 'LoggingEnabled':
|
||||
$xmlReader->read();
|
||||
if ($xmlReader->nodeType == \XMLReader::TEXT)
|
||||
{
|
||||
$loggingEnabled = $xmlReader->value;
|
||||
if ($loggingEnabled == "True")
|
||||
{
|
||||
$loggingEnabled = True;
|
||||
}
|
||||
else
|
||||
{
|
||||
$loggingEnabled = False;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$attributes = new TopicAttributes(
|
||||
$maximumMessageSize,
|
||||
$messageRetentionPeriod,
|
||||
$topicName,
|
||||
$createTime,
|
||||
$lastModifyTime,
|
||||
$loggingEnabled);
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
|
||||
class UpdateSubscriptionAttributes
|
||||
{
|
||||
private $subscriptionName;
|
||||
|
||||
private $strategy;
|
||||
|
||||
# may change in AliyunMNS\Topic
|
||||
private $topicName;
|
||||
|
||||
public function __construct(
|
||||
$subscriptionName = NULL,
|
||||
$strategy = NULL)
|
||||
{
|
||||
$this->subscriptionName = $subscriptionName;
|
||||
|
||||
$this->strategy = $strategy;
|
||||
}
|
||||
|
||||
public function getStrategy()
|
||||
{
|
||||
return $this->strategy;
|
||||
}
|
||||
|
||||
public function setStrategy($strategy)
|
||||
{
|
||||
$this->strategy = $strategy;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function setTopicName($topicName)
|
||||
{
|
||||
$this->topicName = $topicName;
|
||||
}
|
||||
|
||||
public function getSubscriptionName()
|
||||
{
|
||||
return $this->subscriptionName;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
if ($this->strategy != NULL)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::STRATEGY, $this->strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Model;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
class WebSocketAttributes
|
||||
{
|
||||
public $importanceLevel;
|
||||
|
||||
public function __construct($importanceLevel)
|
||||
{
|
||||
$this->importanceLevel = $importanceLevel;
|
||||
}
|
||||
|
||||
public function setImportanceLevel($importanceLevel)
|
||||
{
|
||||
$this->importanceLevel = $importanceLevel;
|
||||
}
|
||||
|
||||
public function getImportanceLevel()
|
||||
{
|
||||
return $this->importanceLevel;
|
||||
}
|
||||
|
||||
public function writeXML(\XMLWriter $xmlWriter)
|
||||
{
|
||||
$jsonArray = array(Constants::IMPORTANCE_LEVEL => $this->importanceLevel);
|
||||
$xmlWriter->writeElement(Constants::WEBSOCKET, json_encode($jsonArray));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
namespace AliyunMNS;
|
||||
|
||||
use AliyunMNS\Http\HttpClient;
|
||||
use AliyunMNS\AsyncCallback;
|
||||
use AliyunMNS\Model\QueueAttributes;
|
||||
use AliyunMNS\Requests\SetQueueAttributeRequest;
|
||||
use AliyunMNS\Responses\SetQueueAttributeResponse;
|
||||
use AliyunMNS\Requests\GetQueueAttributeRequest;
|
||||
use AliyunMNS\Responses\GetQueueAttributeResponse;
|
||||
use AliyunMNS\Requests\SendMessageRequest;
|
||||
use AliyunMNS\Responses\SendMessageResponse;
|
||||
use AliyunMNS\Requests\PeekMessageRequest;
|
||||
use AliyunMNS\Responses\PeekMessageResponse;
|
||||
use AliyunMNS\Requests\ReceiveMessageRequest;
|
||||
use AliyunMNS\Responses\ReceiveMessageResponse;
|
||||
use AliyunMNS\Requests\DeleteMessageRequest;
|
||||
use AliyunMNS\Responses\DeleteMessageResponse;
|
||||
use AliyunMNS\Requests\ChangeMessageVisibilityRequest;
|
||||
use AliyunMNS\Responses\ChangeMessageVisibilityResponse;
|
||||
use AliyunMNS\Requests\BatchSendMessageRequest;
|
||||
use AliyunMNS\Responses\BatchSendMessageResponse;
|
||||
use AliyunMNS\Requests\BatchReceiveMessageRequest;
|
||||
use AliyunMNS\Responses\BatchReceiveMessageResponse;
|
||||
use AliyunMNS\Requests\BatchPeekMessageRequest;
|
||||
use AliyunMNS\Responses\BatchPeekMessageResponse;
|
||||
use AliyunMNS\Requests\BatchDeleteMessageRequest;
|
||||
use AliyunMNS\Responses\BatchDeleteMessageResponse;
|
||||
|
||||
class Queue
|
||||
{
|
||||
private $queueName;
|
||||
private $client;
|
||||
|
||||
// boolean, whether the message body will be encoded in base64
|
||||
private $base64;
|
||||
|
||||
public function __construct(HttpClient $client, $queueName, $base64 = TRUE)
|
||||
{
|
||||
$this->queueName = $queueName;
|
||||
$this->client = $client;
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function setBase64($base64)
|
||||
{
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function isBase64()
|
||||
{
|
||||
return ($this->base64 == TRUE);
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the QueueAttributes, detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&queue_operation
|
||||
*
|
||||
* @param QueueAttributes $attributes: the QueueAttributes to set
|
||||
*
|
||||
* @return SetQueueAttributeResponse: the response
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws InvalidArgumentException if any argument value is invalid
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function setAttribute(QueueAttributes $attributes)
|
||||
{
|
||||
$request = new SetQueueAttributeRequest($this->queueName, $attributes);
|
||||
$response = new SetQueueAttributeResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function setAttributeAsync(QueueAttributes $attributes,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new SetQueueAttributeRequest($this->queueName, $attributes);
|
||||
$response = new SetQueueAttributeResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the QueueAttributes, detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&queue_operation
|
||||
*
|
||||
* @return GetQueueAttributeResponse: containing the attributes
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function getAttribute()
|
||||
{
|
||||
$request = new GetQueueAttributeRequest($this->queueName);
|
||||
$response = new GetQueueAttributeResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function getAttributeAsync(AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new GetQueueAttributeRequest($this->queueName);
|
||||
$response = new GetQueueAttributeResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* SendMessage, the messageBody will be automatically encoded in base64
|
||||
* If you do not need the message body to be encoded in Base64,
|
||||
* please specify the $base64 = FALSE in Queue
|
||||
*
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param SendMessageRequest: containing the message body and properties
|
||||
*
|
||||
* @return SendMessageResponse: containing the messageId and bodyMD5
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws InvalidArgumentException if any argument value is invalid
|
||||
* @throws MalformedXMLException if any error in xml
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function sendMessage(SendMessageRequest $request)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$request->setBase64($this->base64);
|
||||
$response = new SendMessageResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function sendMessageAsync(SendMessageRequest $request,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$request->setBase64($this->base64);
|
||||
$response = new SendMessageResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* PeekMessage, the messageBody will be automatically decoded as base64 if the $base64 in Queue is TRUE
|
||||
*
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @return PeekMessageResponse: containing the messageBody and properties
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MessageNotExistException if no message exists in the queue
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function peekMessage()
|
||||
{
|
||||
$request = new PeekMessageRequest($this->queueName);
|
||||
$response = new PeekMessageResponse($this->base64);
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function peekMessageAsync(AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new PeekMessageRequest($this->queueName);
|
||||
$response = new PeekMessageResponse($this->base64);
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* ReceiveMessage, the messageBody will be automatically decoded as base64 if $base64 = TRUE in Queue
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param waitSeconds: the long polling waitseconds
|
||||
*
|
||||
* @return ReceiveMessageResponse: containing the messageBody and properties
|
||||
* the response is same as PeekMessageResponse,
|
||||
* except that the receiptHandle is also returned in receiveMessage
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MessageNotExistException if no message exists in the queue
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function receiveMessage($waitSeconds = NULL)
|
||||
{
|
||||
$request = new ReceiveMessageRequest($this->queueName, $waitSeconds);
|
||||
$response = new ReceiveMessageResponse($this->base64);
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function receiveMessageAsync(AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new ReceiveMessageRequest($this->queueName);
|
||||
$response = new ReceiveMessageResponse($this->base64);
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* DeleteMessage
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param $receiptHandle: the receiptHandle returned from receiveMessage
|
||||
*
|
||||
* @return ReceiveMessageResponse
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws InvalidArgumentException if the argument is invalid
|
||||
* @throws ReceiptHandleErrorException if the $receiptHandle is invalid
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function deleteMessage($receiptHandle)
|
||||
{
|
||||
$request = new DeleteMessageRequest($this->queueName, $receiptHandle);
|
||||
$response = new DeleteMessageResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function deleteMessageAsync($receiptHandle,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new DeleteMessageRequest($this->queueName, $receiptHandle);
|
||||
$response = new DeleteMessageResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* ChangeMessageVisibility, set the nextVisibleTime for the message
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param $receiptHandle: the receiptHandle returned from receiveMessage
|
||||
*
|
||||
* @return ChangeMessageVisibilityResponse
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MessageNotExistException if the message does not exist
|
||||
* @throws InvalidArgumentException if the argument is invalid
|
||||
* @throws ReceiptHandleErrorException if the $receiptHandle is invalid
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function changeMessageVisibility($receiptHandle, $visibilityTimeout)
|
||||
{
|
||||
$request = new ChangeMessageVisibilityRequest($this->queueName, $receiptHandle, $visibilityTimeout);
|
||||
$response = new ChangeMessageVisibilityResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* BatchSendMessage, message body will be automatically encoded in base64
|
||||
* If you do not need the message body to be encoded in Base64,
|
||||
* please specify the $base64 = FALSE in Queue
|
||||
*
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param BatchSendMessageRequest:
|
||||
* the requests containing an array of SendMessageRequestItems
|
||||
*
|
||||
* @return BatchSendMessageResponse
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MalformedXMLException if any error in the xml
|
||||
* @throws InvalidArgumentException if the argument is invalid
|
||||
* @throws BatchSendFailException if some messages are not sent
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function batchSendMessage(BatchSendMessageRequest $request)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$request->setBase64($this->base64);
|
||||
$response = new BatchSendMessageResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function batchSendMessageAsync(BatchSendMessageRequest $request,
|
||||
AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$request->setBase64($this->base64);
|
||||
$response = new BatchSendMessageResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* BatchReceiveMessage, message body will be automatically decoded as base64 if $base64 = TRUE in Queue
|
||||
*
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param BatchReceiveMessageRequest:
|
||||
* containing numOfMessages and waitSeconds
|
||||
*
|
||||
* @return BatchReceiveMessageResponse:
|
||||
* the received messages
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MessageNotExistException if no message exists
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function batchReceiveMessage(BatchReceiveMessageRequest $request)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$response = new BatchReceiveMessageResponse($this->base64);
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function batchReceiveMessageAsync(BatchReceiveMessageRequest $request, AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request->setQueueName($this->queueName);
|
||||
$response = new BatchReceiveMessageResponse($this->base64);
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* BatchPeekMessage, message body will be automatically decoded as base64 is $base64 = TRUE in Queue
|
||||
*
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param BatchPeekMessageRequest:
|
||||
* containing numOfMessages and waitSeconds
|
||||
*
|
||||
* @return BatchPeekMessageResponse:
|
||||
* the received messages
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws MessageNotExistException if no message exists
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function batchPeekMessage($numOfMessages)
|
||||
{
|
||||
$request = new BatchPeekMessageRequest($this->queueName, $numOfMessages);
|
||||
$response = new BatchPeekMessageResponse($this->base64);
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function batchPeekMessageAsync($numOfMessages, AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new BatchPeekMessageRequest($this->queueName, $numOfMessages);
|
||||
$response = new BatchPeekMessageResponse($this->base64);
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* BatchDeleteMessage
|
||||
* detail API sepcs:
|
||||
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&message_operation
|
||||
*
|
||||
* @param $receiptHandles:
|
||||
* array of $receiptHandle, which is got from receiveMessage
|
||||
*
|
||||
* @return BatchDeleteMessageResponse
|
||||
*
|
||||
* @throws QueueNotExistException if queue does not exist
|
||||
* @throws ReceiptHandleErrorException if the receiptHandle is invalid
|
||||
* @throws InvalidArgumentException if the argument is invalid
|
||||
* @throws BatchDeleteFailException if any message not deleted
|
||||
* @throws MnsException if any other exception happends
|
||||
*/
|
||||
public function batchDeleteMessage($receiptHandles)
|
||||
{
|
||||
$request = new BatchDeleteMessageRequest($this->queueName, $receiptHandles);
|
||||
$response = new BatchDeleteMessageResponse();
|
||||
return $this->client->sendRequest($request, $response);
|
||||
}
|
||||
|
||||
public function batchDeleteMessageAsync($receiptHandles, AsyncCallback $callback = NULL)
|
||||
{
|
||||
$request = new BatchDeleteMessageRequest($this->queueName, $receiptHandles);
|
||||
$response = new BatchDeleteMessageResponse();
|
||||
return $this->client->sendRequestAsync($request, $response, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
abstract class BaseRequest
|
||||
{
|
||||
protected $headers;
|
||||
protected $resourcePath;
|
||||
protected $method;
|
||||
|
||||
protected $body;
|
||||
protected $queryString;
|
||||
|
||||
public function __construct($method, $resourcePath) {
|
||||
$this->method = $method;
|
||||
$this->resourcePath = $resourcePath;
|
||||
}
|
||||
|
||||
abstract public function generateBody();
|
||||
abstract public function generateQueryString();
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function setQueryString($queryString)
|
||||
{
|
||||
$this->queryString = $queryString;
|
||||
}
|
||||
|
||||
public function getQueryString()
|
||||
{
|
||||
return $this->queryString;
|
||||
}
|
||||
|
||||
public function isHeaderSet($header)
|
||||
{
|
||||
return isset($this->headers[$header]);
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function removeHeader($header)
|
||||
{
|
||||
if (isset($this->headers[$header]))
|
||||
{
|
||||
unset($this->headers[$header]);
|
||||
}
|
||||
}
|
||||
|
||||
public function setHeader($header, $value)
|
||||
{
|
||||
$this->headers[$header] = $value;
|
||||
}
|
||||
|
||||
public function getResourcePath()
|
||||
{
|
||||
return $this->resourcePath;
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class BatchDeleteMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $receiptHandles;
|
||||
|
||||
public function __construct($queueName, array $receiptHandles)
|
||||
{
|
||||
parent::__construct('delete', 'queues/' . $queueName . '/messages');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->receiptHandles = $receiptHandles;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getReceiptHandles()
|
||||
{
|
||||
return $this->receiptHandles;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, Constants::RECEIPT_HANDLES, Constants::MNS_XML_NAMESPACE);
|
||||
foreach ($this->receiptHandles as $receiptHandle)
|
||||
{
|
||||
$xmlWriter->writeElement(Constants::RECEIPT_HANDLE, $receiptHandle);
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class BatchPeekMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $numOfMessages;
|
||||
private $waitSeconds;
|
||||
|
||||
public function __construct($queueName, $numOfMessages)
|
||||
{
|
||||
parent::__construct('get', 'queues/' . $queueName . '/messages');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->numOfMessages = $numOfMessages;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getNumOfMessages()
|
||||
{
|
||||
return $this->numOfMessages;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return http_build_query(array("numOfMessages" => $this->numOfMessages, "peekonly" => "true"));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class BatchReceiveMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $numOfMessages;
|
||||
private $waitSeconds;
|
||||
|
||||
public function __construct($numOfMessages, $waitSeconds = NULL)
|
||||
{
|
||||
parent::__construct('get', NULL);
|
||||
|
||||
$this->queueName = NULL;
|
||||
$this->numOfMessages = $numOfMessages;
|
||||
$this->waitSeconds = $waitSeconds;
|
||||
}
|
||||
|
||||
public function setQueueName($queueName)
|
||||
{
|
||||
$this->queueName = $queueName;
|
||||
$this->resourcePath = 'queues/' . $queueName . '/messages';
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getWaitSeconds()
|
||||
{
|
||||
return $this->waitSeconds;
|
||||
}
|
||||
|
||||
public function getNumOfMessages()
|
||||
{
|
||||
return $this->numOfMessages;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
$params = array("numOfMessages" => $this->numOfMessages);
|
||||
if ($this->waitSeconds != NULL)
|
||||
{
|
||||
$params["waitseconds"] = $this->waitSeconds;
|
||||
}
|
||||
return http_build_query($params);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\SendMessageRequestItem;
|
||||
|
||||
class BatchSendMessageRequest extends BaseRequest
|
||||
{
|
||||
protected $queueName;
|
||||
protected $sendMessageRequestItems;
|
||||
|
||||
// boolean, whether the message body will be encoded in base64
|
||||
protected $base64;
|
||||
|
||||
public function __construct(array $sendMessageRequestItems, $base64 = TRUE)
|
||||
{
|
||||
parent::__construct('post', NULL);
|
||||
|
||||
$this->queueName = NULL;
|
||||
$this->sendMessageRequestItems = $sendMessageRequestItems;
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function setBase64($base64)
|
||||
{
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function isBase64()
|
||||
{
|
||||
return ($this->base64 == TRUE);
|
||||
}
|
||||
|
||||
public function setQueueName($queueName)
|
||||
{
|
||||
$this->queueName = $queueName;
|
||||
$this->resourcePath = 'queues/' . $queueName . '/messages';
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getSendMessageRequestItems()
|
||||
{
|
||||
return $this->sendMessageRequestItems;
|
||||
}
|
||||
|
||||
public function addSendMessageRequestItem(SendMessageRequestItem $item)
|
||||
{
|
||||
$this->sendMessageRequestItems[] = $item;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Messages", Constants::MNS_XML_NAMESPACE);
|
||||
foreach ($this->sendMessageRequestItems as $item)
|
||||
{
|
||||
$item->writeXML($xmlWriter, $this->base64);
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class ChangeMessageVisibilityRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $receiptHandle;
|
||||
private $visibilityTimeout;
|
||||
|
||||
public function __construct($queueName, $receiptHandle, $visibilityTimeout)
|
||||
{
|
||||
parent::__construct('put', 'queues/' . $queueName . '/messages');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->receiptHandle = $receiptHandle;
|
||||
$this->visibilityTimeout = $visibilityTimeout;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getReceiptHandle()
|
||||
{
|
||||
return $this->receiptHandle;
|
||||
}
|
||||
|
||||
public function getVisibilityTimeout()
|
||||
{
|
||||
return $this->visibilityTimeout;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return http_build_query(array("receiptHandle" => $this->receiptHandle, "visibilityTimeout" => $this->visibilityTimeout));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\QueueAttributes;
|
||||
|
||||
class CreateQueueRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $attributes;
|
||||
|
||||
public function __construct($queueName, QueueAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', 'queues/' . $queueName);
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new QueueAttributes;
|
||||
}
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getQueueAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Queue", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\TopicAttributes;
|
||||
|
||||
class CreateTopicRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
private $attributes;
|
||||
|
||||
public function __construct($topicName, TopicAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', 'topics/' . $topicName);
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new TopicAttributes;
|
||||
}
|
||||
|
||||
$this->topicName = $topicName;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getTopicAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Topic", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class DeleteMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $receiptHandle;
|
||||
|
||||
public function __construct($queueName, $receiptHandle)
|
||||
{
|
||||
parent::__construct('delete', 'queues/' . $queueName . '/messages');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->receiptHandle = $receiptHandle;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getReceiptHandle()
|
||||
{
|
||||
return $this->receiptHandle;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return http_build_query(array("ReceiptHandle" => $this->receiptHandle));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\QueueAttributes;
|
||||
|
||||
class DeleteQueueRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
|
||||
public function __construct($queueName)
|
||||
{
|
||||
parent::__construct('delete', 'queues/' . $queueName);
|
||||
$this->queueName = $queueName;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\TopicAttributes;
|
||||
|
||||
class DeleteTopicRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
|
||||
public function __construct($topicName)
|
||||
{
|
||||
parent::__construct('delete', 'topics/' . $topicName);
|
||||
$this->topicName = $topicName;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class GetAccountAttributesRequest extends BaseRequest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('get', '/?accountmeta=true');
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class GetQueueAttributeRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
|
||||
public function __construct($queueName)
|
||||
{
|
||||
parent::__construct('get', 'queues/' . $queueName);
|
||||
|
||||
$this->queueName = $queueName;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class GetSubscriptionAttributeRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
private $subscriptionName;
|
||||
|
||||
public function __construct($topicName, $subscriptionName)
|
||||
{
|
||||
parent::__construct('get', 'topics/' . $topicName . '/subscriptions/' . $subscriptionName);
|
||||
$this->topicName = $topicName;
|
||||
$this->subscriptionName = $subscriptionName;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getSubscriptionName()
|
||||
{
|
||||
return $this->subscriptionName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class GetTopicAttributeRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
|
||||
public function __construct($topicName)
|
||||
{
|
||||
parent::__construct('get', 'topics/' . $topicName);
|
||||
|
||||
$this->topicName = $topicName;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class ListQueueRequest extends BaseRequest
|
||||
{
|
||||
private $retNum;
|
||||
private $prefix;
|
||||
private $marker;
|
||||
|
||||
public function __construct($retNum = NULL, $prefix = NULL, $marker = NULL)
|
||||
{
|
||||
parent::__construct('get', 'queues');
|
||||
|
||||
$this->setRetNum($retNum);
|
||||
$this->setPrefix($prefix);
|
||||
$this->setMarker($marker);
|
||||
}
|
||||
|
||||
public function getRetNum()
|
||||
{
|
||||
return $this->retNum;
|
||||
}
|
||||
|
||||
public function setRetNum($retNum)
|
||||
{
|
||||
$this->retNum = $retNum;
|
||||
if ($retNum != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-ret-number", $retNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-ret-number");
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefis = $prefix;
|
||||
if ($prefix != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-prefix", $prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-prefix");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMarker()
|
||||
{
|
||||
return $this->marker;
|
||||
}
|
||||
|
||||
public function setMarker($marker)
|
||||
{
|
||||
$this->marker = $marker;
|
||||
if ($marker != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-marker", $marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-marker");
|
||||
}
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class ListSubscriptionRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
private $retNum;
|
||||
private $prefix;
|
||||
private $marker;
|
||||
|
||||
public function __construct(
|
||||
$topicName,
|
||||
$retNum = NULL,
|
||||
$prefix = NULL,
|
||||
$marker = NULL)
|
||||
{
|
||||
parent::__construct('get', 'topics/' . $topicName . '/subscriptions');
|
||||
|
||||
$this->topicName = $topicName;
|
||||
$this->setRetNum($retNum);
|
||||
$this->setPrefix($prefix);
|
||||
$this->setMarker($marker);
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getRetNum()
|
||||
{
|
||||
return $this->retNum;
|
||||
}
|
||||
|
||||
public function setRetNum($retNum)
|
||||
{
|
||||
$this->retNum = $retNum;
|
||||
if ($retNum != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-ret-number", $retNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-ret-number");
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefis = $prefix;
|
||||
if ($prefix != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-prefix", $prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-prefix");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMarker()
|
||||
{
|
||||
return $this->marker;
|
||||
}
|
||||
|
||||
public function setMarker($marker)
|
||||
{
|
||||
$this->marker = $marker;
|
||||
if ($marker != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-marker", $marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-marker");
|
||||
}
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class ListTopicRequest extends BaseRequest
|
||||
{
|
||||
private $retNum;
|
||||
private $prefix;
|
||||
private $marker;
|
||||
|
||||
public function __construct($retNum = NULL, $prefix = NULL, $marker = NULL)
|
||||
{
|
||||
parent::__construct('get', 'topics');
|
||||
|
||||
$this->setRetNum($retNum);
|
||||
$this->setPrefix($prefix);
|
||||
$this->setMarker($marker);
|
||||
}
|
||||
|
||||
public function getRetNum()
|
||||
{
|
||||
return $this->retNum;
|
||||
}
|
||||
|
||||
public function setRetNum($retNum)
|
||||
{
|
||||
$this->retNum = $retNum;
|
||||
if ($retNum != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-ret-number", $retNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-ret-number");
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefis = $prefix;
|
||||
if ($prefix != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-prefix", $prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-prefix");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMarker()
|
||||
{
|
||||
return $this->marker;
|
||||
}
|
||||
|
||||
public function setMarker($marker)
|
||||
{
|
||||
$this->marker = $marker;
|
||||
if ($marker != NULL)
|
||||
{
|
||||
$this->setHeader("x-mns-marker", $marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeHeader("x-mns-marker");
|
||||
}
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class PeekMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
|
||||
public function __construct($queueName)
|
||||
{
|
||||
parent::__construct('get', 'queues/' . $queueName . '/messages?peekonly=true');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Traits\MessagePropertiesForPublish;
|
||||
|
||||
class PublishMessageRequest extends BaseRequest
|
||||
{
|
||||
use MessagePropertiesForPublish;
|
||||
|
||||
private $topicName;
|
||||
|
||||
public function __construct($messageBody, $messageAttributes = NULL)
|
||||
{
|
||||
parent::__construct('post', NULL);
|
||||
|
||||
$this->topicName = NULL;
|
||||
$this->messageBody = $messageBody;
|
||||
$this->messageAttributes = $messageAttributes;
|
||||
}
|
||||
|
||||
public function setTopicName($topicName)
|
||||
{
|
||||
$this->topicName = $topicName;
|
||||
$this->resourcePath = 'topics/' . $topicName . '/messages';
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Message", Constants::MNS_XML_NAMESPACE);
|
||||
$this->writeMessagePropertiesForPublishXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class ReceiveMessageRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $waitSeconds;
|
||||
|
||||
public function __construct($queueName, $waitSeconds = NULL)
|
||||
{
|
||||
parent::__construct('get', 'queues/' . $queueName . '/messages');
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->waitSeconds = $waitSeconds;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getWaitSeconds()
|
||||
{
|
||||
return $this->waitSeconds;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
if ($this->waitSeconds != NULL)
|
||||
{
|
||||
return http_build_query(array("waitseconds" => $this->waitSeconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\QueueAttributes;
|
||||
use AliyunMNS\Traits\MessagePropertiesForSend;
|
||||
|
||||
class SendMessageRequest extends BaseRequest
|
||||
{
|
||||
use MessagePropertiesForSend;
|
||||
|
||||
private $queueName;
|
||||
|
||||
// boolean, whether the message body will be encoded in base64
|
||||
private $base64;
|
||||
|
||||
public function __construct($messageBody, $delaySeconds = NULL, $priority = NULL, $base64 = TRUE)
|
||||
{
|
||||
parent::__construct('post', NULL);
|
||||
|
||||
$this->queueName = NULL;
|
||||
$this->messageBody = $messageBody;
|
||||
$this->delaySeconds = $delaySeconds;
|
||||
$this->priority = $priority;
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function setBase64($base64)
|
||||
{
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function isBase64()
|
||||
{
|
||||
return ($this->base64 == TRUE);
|
||||
}
|
||||
|
||||
public function setQueueName($queueName)
|
||||
{
|
||||
$this->queueName = $queueName;
|
||||
$this->resourcePath = 'queues/' . $queueName . '/messages';
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Message", Constants::MNS_XML_NAMESPACE);
|
||||
$this->writeMessagePropertiesForSendXML($xmlWriter, $this->base64);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\AccountAttributes;
|
||||
|
||||
class SetAccountAttributesRequest extends BaseRequest
|
||||
{
|
||||
private $attributes;
|
||||
|
||||
public function __construct(AccountAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', '/?accountmeta=true');
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new AccountAttributes;
|
||||
}
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getAccountAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Account", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\QueueAttributes;
|
||||
|
||||
class SetQueueAttributeRequest extends BaseRequest
|
||||
{
|
||||
private $queueName;
|
||||
private $attributes;
|
||||
|
||||
public function __construct($queueName, QueueAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', 'queues/' . $queueName . '?metaoverride=true');
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new QueueAttributes;
|
||||
}
|
||||
|
||||
$this->queueName = $queueName;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
|
||||
public function getQueueAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Queue", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\UpdateSubscriptionAttributes;
|
||||
|
||||
class SetSubscriptionAttributeRequest extends BaseRequest
|
||||
{
|
||||
|
||||
public function __construct(UpdateSubscriptionAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', 'topics/' . $attributes->getTopicName() . '/subscriptions/' . $attributes->getSubscriptionName() . '?metaoverride=true');
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new UpdateSubscriptionAttributes();
|
||||
}
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getSubscriptionAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Subscription", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\TopicAttributes;
|
||||
|
||||
class SetTopicAttributeRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
private $attributes;
|
||||
|
||||
public function __construct($topicName, TopicAttributes $attributes = NULL)
|
||||
{
|
||||
parent::__construct('put', 'topics/' . $topicName . '?metaoverride=true');
|
||||
|
||||
if ($attributes == NULL)
|
||||
{
|
||||
$attributes = new TopicAttributes();
|
||||
}
|
||||
|
||||
$this->topicName = $topicName;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getTopicAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Topic", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
use AliyunMNS\Model\SubscriptionAttributes;
|
||||
|
||||
class SubscribeRequest extends BaseRequest
|
||||
{
|
||||
private $attributes;
|
||||
|
||||
public function __construct(SubscriptionAttributes $attributes)
|
||||
{
|
||||
parent::__construct('put', 'topics/' . $attributes->getTopicName() . '/subscriptions/' . $attributes->getSubscriptionName());
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getSubscriptionAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
$xmlWriter = new \XMLWriter;
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->startDocument("1.0", "UTF-8");
|
||||
$xmlWriter->startElementNS(NULL, "Subscription", Constants::MNS_XML_NAMESPACE);
|
||||
$this->attributes->writeXML($xmlWriter);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endDocument();
|
||||
return $xmlWriter->outputMemory();
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Requests;
|
||||
|
||||
use AliyunMNS\Requests\BaseRequest;
|
||||
|
||||
class UnsubscribeRequest extends BaseRequest
|
||||
{
|
||||
private $topicName;
|
||||
private $subscriptionName;
|
||||
|
||||
public function __construct($topicName, $subscriptionName)
|
||||
{
|
||||
parent::__construct('delete', 'topics/' . $topicName . '/subscriptions/' . $subscriptionName);
|
||||
$this->topicName = $topicName;
|
||||
$this->subscriptionName = $subscriptionName;
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
|
||||
public function getSubscriptionName()
|
||||
{
|
||||
return $this->subscriptionName;
|
||||
}
|
||||
|
||||
public function generateBody()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function generateQueryString()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
|
||||
abstract class BaseResponse
|
||||
{
|
||||
protected $succeed;
|
||||
protected $statusCode;
|
||||
|
||||
abstract public function parseResponse($statusCode, $content);
|
||||
|
||||
public function isSucceed()
|
||||
{
|
||||
return $this->succeed;
|
||||
}
|
||||
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
protected function loadXmlContent($content)
|
||||
{
|
||||
$xmlReader = new \XMLReader();
|
||||
$isXml = $xmlReader->XML($content);
|
||||
if ($isXml === FALSE) {
|
||||
throw new MnsException($this->statusCode, $content);
|
||||
}
|
||||
try {
|
||||
while ($xmlReader->read()) {}
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($this->statusCode, $content);
|
||||
}
|
||||
$xmlReader->XML($content);
|
||||
return $xmlReader;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Exception\BatchDeleteFailException;
|
||||
use AliyunMNS\Exception\ReceiptHandleErrorException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
use AliyunMNS\Model\DeleteMessageErrorItem;
|
||||
|
||||
class BatchDeleteMessageResponse extends BaseResponse
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
|
||||
switch ($xmlReader->name) {
|
||||
case Constants::ERROR:
|
||||
$this->parseNormalErrorResponse($xmlReader);
|
||||
break;
|
||||
default: // case Constants::Messages
|
||||
$this->parseBatchDeleteErrorResponse($xmlReader);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function parseBatchDeleteErrorResponse($xmlReader)
|
||||
{
|
||||
$ex = new BatchDeleteFailException($this->statusCode, "BatchDeleteMessage Failed For Some ReceiptHandles");
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == Constants::ERROR) {
|
||||
$ex->addDeleteMessageErrorItem( DeleteMessageErrorItem::fromXML($xmlReader));
|
||||
}
|
||||
}
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
private function parseNormalErrorResponse($xmlReader)
|
||||
{
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
|
||||
{
|
||||
throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\MessageNotExistException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
use AliyunMNS\Model\Message;
|
||||
|
||||
class BatchPeekMessageResponse extends BaseResponse
|
||||
{
|
||||
protected $messages;
|
||||
|
||||
// boolean, whether the message body will be decoded as base64
|
||||
protected $base64;
|
||||
|
||||
public function __construct($base64 = TRUE)
|
||||
{
|
||||
$this->messages = array();
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function setBase64($base64)
|
||||
{
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function isBase64()
|
||||
{
|
||||
return ($this->base64 == TRUE);
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 200) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT
|
||||
&& $xmlReader->name == 'Message')
|
||||
{
|
||||
$this->messages[] = Message::fromXML($xmlReader, $this->base64);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($statusCode, $e->getMessage(), $e);
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::MESSAGE_NOT_EXIST)
|
||||
{
|
||||
throw new MessageNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\MessageNotExistException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
use AliyunMNS\Model\Message;
|
||||
|
||||
class BatchReceiveMessageResponse extends BaseResponse
|
||||
{
|
||||
protected $messages;
|
||||
|
||||
// boolean, whether the message body will be decoded as base64
|
||||
protected $base64;
|
||||
|
||||
public function __construct($base64 = TRUE)
|
||||
{
|
||||
$this->messages = array();
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function setBase64($base64)
|
||||
{
|
||||
$this->base64 = $base64;
|
||||
}
|
||||
|
||||
public function isBase64()
|
||||
{
|
||||
return ($this->base64 == TRUE);
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 200) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT
|
||||
&& $xmlReader->name == 'Message')
|
||||
{
|
||||
$this->messages[] = Message::fromXML($xmlReader, $this->base64);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($statusCode, $e->getMessage(), $e);
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::MESSAGE_NOT_EXIST)
|
||||
{
|
||||
throw new MessageNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\BatchSendFailException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Exception\MalformedXMLException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
use AliyunMNS\Model\SendMessageResponseItem;
|
||||
use AliyunMNS\Traits\MessageIdAndMD5;
|
||||
|
||||
class BatchSendMessageResponse extends BaseResponse
|
||||
{
|
||||
protected $sendMessageResponseItems;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sendMessageResponseItems = array();
|
||||
}
|
||||
|
||||
public function getSendMessageResponseItems()
|
||||
{
|
||||
return $this->sendMessageResponseItems;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 201) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == 'Message') {
|
||||
$this->sendMessageResponseItems[] = SendMessageResponseItem::fromXML($xmlReader);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($statusCode, $e->getMessage(), $e);
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
|
||||
switch ($xmlReader->name) {
|
||||
case Constants::ERROR:
|
||||
$this->parseNormalErrorResponse($xmlReader);
|
||||
break;
|
||||
default: // case Constants::Messages
|
||||
$this->parseBatchSendErrorResponse($xmlReader);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function parseBatchSendErrorResponse($xmlReader)
|
||||
{
|
||||
$ex = new BatchSendFailException($this->statusCode, "BatchSendMessage Failed For Some Messages");
|
||||
while ($xmlReader->read())
|
||||
{
|
||||
if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == 'Message') {
|
||||
$ex->addSendMessageResponseItem( SendMessageResponseItem::fromXML($xmlReader));
|
||||
}
|
||||
}
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
private function parseNormalErrorResponse($xmlReader)
|
||||
{
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::MALFORMED_XML)
|
||||
{
|
||||
throw new MalformedXMLException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\MessageNotExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Exception\ReceiptHandleErrorException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
use AliyunMNS\Model\Message;
|
||||
|
||||
class ChangeMessageVisibilityResponse extends BaseResponse
|
||||
{
|
||||
protected $receiptHandle;
|
||||
protected $nextVisibleTime;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getReceiptHandle()
|
||||
{
|
||||
return $this->receiptHandle;
|
||||
}
|
||||
|
||||
public function getNextVisibleTime()
|
||||
{
|
||||
return $this->nextVisibleTime;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 200) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$message = Message::fromXML($xmlReader, TRUE);
|
||||
$this->receiptHandle = $message->getReceiptHandle();
|
||||
$this->nextVisibleTime = $message->getNextVisibleTime();
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($statusCode, $e->getMessage(), $e);
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::MESSAGE_NOT_EXIST)
|
||||
{
|
||||
throw new MessageNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
|
||||
{
|
||||
throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueAlreadyExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class CreateQueueResponse extends BaseResponse
|
||||
{
|
||||
private $queueName;
|
||||
|
||||
public function __construct($queueName)
|
||||
{
|
||||
$this->queueName = $queueName;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 201 || $statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::QUEUE_ALREADY_EXIST)
|
||||
{
|
||||
throw new QueueAlreadyExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getQueueName()
|
||||
{
|
||||
return $this->queueName;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\TopicAlreadyExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class CreateTopicResponse extends BaseResponse
|
||||
{
|
||||
private $topicName;
|
||||
|
||||
public function __construct($topicName)
|
||||
{
|
||||
$this->topicName = $topicName;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 201 || $statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::TOPIC_ALREADY_EXIST)
|
||||
{
|
||||
throw new TopicAlreadyExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTopicName()
|
||||
{
|
||||
return $this->topicName;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Exception\QueueNotExistException;
|
||||
use AliyunMNS\Exception\InvalidArgumentException;
|
||||
use AliyunMNS\Exception\ReceiptHandleErrorException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class DeleteMessageResponse extends BaseResponse
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
if ($result['Code'] == Constants::INVALID_ARGUMENT)
|
||||
{
|
||||
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
|
||||
{
|
||||
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
|
||||
{
|
||||
throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
}
|
||||
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class DeleteQueueResponse extends BaseResponse
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class DeleteTopicResponse extends BaseResponse
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 204) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace AliyunMNS\Responses;
|
||||
|
||||
use AliyunMNS\Constants;
|
||||
use AliyunMNS\Model\AccountAttributes;
|
||||
use AliyunMNS\Exception\MnsException;
|
||||
use AliyunMNS\Responses\BaseResponse;
|
||||
use AliyunMNS\Common\XMLParser;
|
||||
|
||||
class GetAccountAttributesResponse extends BaseResponse
|
||||
{
|
||||
private $attributes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->attributes = NULL;
|
||||
}
|
||||
|
||||
public function getAccountAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function parseResponse($statusCode, $content)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
if ($statusCode == 200) {
|
||||
$this->succeed = TRUE;
|
||||
} else {
|
||||
$this->parseErrorResponse($statusCode, $content);
|
||||
}
|
||||
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$this->attributes = AccountAttributes::fromXML($xmlReader);
|
||||
} catch (\Exception $e) {
|
||||
throw new MnsException($statusCode, $e->getMessage(), $e);
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
|
||||
{
|
||||
$this->succeed = FALSE;
|
||||
$xmlReader = $this->loadXmlContent($content);
|
||||
|
||||
try {
|
||||
$result = XMLParser::parseNormalError($xmlReader);
|
||||
|
||||
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
|
||||
} catch (\Exception $e) {
|
||||
if ($exception != NULL) {
|
||||
throw $exception;
|
||||
} elseif($e instanceof MnsException) {
|
||||
throw $e;
|
||||
} else {
|
||||
throw new MnsException($statusCode, $e->getMessage());
|
||||
}
|
||||
} catch (\Throwable $t) {
|
||||
throw new MnsException($statusCode, $t->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user