Browse Source

topic fuzamei

lin 6 years ago
parent
commit
a260e98e62

+ 0 - 1
backend/controllers/MessageController.php

@@ -30,7 +30,6 @@ class MessageController extends BaseController
 		]);
 	}
 
-
 	/**
 	 * 发送消息
 	 * @author: libingke

+ 14 - 1
backend/controllers/SiteController.php

@@ -22,7 +22,7 @@ class SiteController extends Controller
                 'class' => AccessControl::className(),
                 'rules' => [
                     [
-                        'actions' => ['login', 'error', 'index'],
+                        'actions' => ['login', 'error', 'index','testcreatequeue'],
                         'allow' => true,
                     ],
                     [
@@ -64,6 +64,19 @@ class SiteController extends Controller
     }
 
 
+
+    /**
+     * Displays testapi.
+     *
+     * @return string
+     */
+    public function actionTestcreatequeue()
+    {
+        var_dump( Yii::$app->messageQueue->createQueue('yang'));
+    }
+
+
+
     /**
      * Login action.
      *

+ 12 - 0
common/config/main.php

@@ -16,6 +16,18 @@ return [
 			'user'	=> 'guest',
 			'pass'	=> 'Guest',
 		],
+        'cUrl' => [
+            'class' => '\components\components\CUrl'
+        ],
+//
+//        //新增加的加密
+        'messageQueue' => [
+            'class' => '\components\components\messageQueue\MessageInterface',
+            'key' => 'QkwzrML50o1KIK5bI-HbkVBcTSA_Ehdh',
+            'protocol' => 'http',
+//            'host' => '120.78.153.45'
+            'host' => 'ki.logsystemadmin.airent.test.com'
+        ],
 
         'cache' => [
             'class' => 'yii\caching\FileCache',

+ 423 - 0
components/components/CUrl.php

@@ -0,0 +1,423 @@
+<?php
+namespace components\components;
+
+use Yii;
+use yii\base\Component;
+use yii\helpers\Json;
+use yii\web\HttpException;
+
+/**
+ * CUrl Model
+ * cURL 模型
+ * ----------------
+ * @version 1.0.0
+ * @author Verdient。
+ */
+class CUrl extends Component
+{
+	/**
+	 * const CURLOPT_QUERY
+	 * 查询参数
+	 * -------------------
+	 * @author Verdient。
+	 */
+	const CURLOPT_QUERY = 'query';
+
+	/**
+	 * @var public $onlyContent
+	 * 只返回消息体
+	 * ------------------------
+	 * @author Verdient。
+	 */
+	public $onlyContent = true;
+
+	/**
+	 * @var private $_response
+	 * 响应内容
+	 * -----------------------
+	 * @author Verident。
+	 */
+	private $_response = null;
+
+	/**
+	 * @var private $_responseCode
+	 * 状态码
+	 * ---------------------------
+	 * @author Verdient。
+	 */
+	private $_responseCode = null;
+
+	/**
+	 * @var private $_options
+	 * 参数
+	 * ----------------------
+	 * @author Verdient。
+	 */
+	private $_options = [];
+
+	/**
+	 * @var private $_curl
+	 * cUrl实例
+	 * -------------------
+	 * @author Verdient。
+	 */
+	private $_curl = null;
+
+	/**
+	 * @var private $_defaultOptions
+	 * 默认参数
+	 * -----------------------------
+	 * @author Verdient。
+	 */
+	private $_defaultOptions = [
+		CURLOPT_USERAGENT => 'Yii2-CUrl-Agent',
+		CURLOPT_TIMEOUT => 30,
+		CURLOPT_CONNECTTIMEOUT => 30,
+		CURLOPT_RETURNTRANSFER => true,
+		CURLOPT_HEADER => false,
+		CURLOPT_SSL_VERIFYPEER => false,
+		CURLOPT_SSL_VERIFYHOST => false,
+		CURLOPT_HTTPHEADER => [],
+		self::CURLOPT_QUERY => [],
+	];
+
+	/**
+	 * get(String $url, String $dataType)
+	 * 通过get方式获取数据
+	 * ------------------------------
+	 * @param String $url url地址
+	 * @param String $dataType 返回数据格式
+	 * ------------------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function get($url, $dataType = null){
+		return $this->_httpRequest('GET', $url, $dataType);
+	}
+
+	/**
+	 * head(String $url)
+	 * 通过head方式获取数据
+	 * --------------------
+	 * @param String $url url地址
+	 * --------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function head($url){
+		return $this->_httpRequest('HEAD', $url);
+	}
+
+	/**
+	 * post(String $url, String $dataType)
+	 * 通过post方式获取数据
+	 * -----------------------------------
+	 * @param String $url url地址
+	 * @param String $dataType 返回数据格式
+	 * ------------------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function post($url, $dataType = null){
+		return $this->_httpRequest('POST', $url, $dataType);
+	}
+
+	/**
+	 * put(String $url, String $dataType)
+	 * 通过put方式获取数据
+	 * -------------------
+	 * @param String $url url地址
+	 * @param String $dataType 返回数据格式
+	 * ------------------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function put($url, $dataType = null){
+		return $this->_httpRequest('PUT', $url, $dataType);
+	}
+
+	/**
+	 * delete(String $url, String $dataType)
+	 * 通过delete方式获取数据
+	 * -------------------------------------
+	 * @param String $url url地址
+	 * @param String $dataType 返回数据格式
+	 * ------------------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function delete($url, $dataType = null){
+		return $this->_httpRequest('DELETE', $url, $dataType);
+	}
+
+	/**
+	 * setHeader(Array $headers)
+	 * 设置发送的头部信息
+	 * --------------------------
+	 * @param Array $headers 头部信息
+	 * ------------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function setHeader(Array $headers){
+		$header = [];
+		foreach($headers as $key => $value){
+			$header[] = $key . ':' . $value;
+		}
+		$this->setOption(CURLOPT_HTTPHEADER, $header);
+	}
+
+	/**
+	 * setData(Array $data, Callable / String $callback = null)
+	 * 设置发送的数据
+	 * --------------------------------------------------------
+	 * @param Array $data 发送的数据
+	 * @param Callable / String $callback 回调函数
+	 * -------------------------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function setData(Array $data, $callback = null){
+		if(is_string($callback)){
+			if(strtoupper($callback) == 'JSON'){
+				$data = Json::encode($data);
+				$this->setHeader(['Content-Type' => 'application/json', 'Content-Length' => strlen($data)]);
+				return $this->setOption(CURLOPT_POSTFIELDS, $data);
+			}
+		}
+		if(is_callable($callback)){
+			$data = call_user_func($callback, $data);
+		}
+		return $this->setOption(CURLOPT_POSTFIELDS, $callback == null ? http_build_query($data) : $data);
+	}
+
+	/**
+	 * setQuery(Array $query)
+	 * 设置查询信息
+	 * ----------------------
+	 * @param Array $query 查询信息
+	 * ---------------------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function setQuery(Array $query){
+		$this->setOption(self::CURLOPT_QUERY, $query);
+	}
+
+	/**
+	 * setOption(String $key, Mixed $value)
+	 * 设置选项
+	 * ------------------------------------
+	 * @param String $key 选项名称
+	 * @param Mixed $value 选项内容
+	 * ----------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function setOption($key, $value){
+		if(isset($this->_options[$key]) && is_array($this->_options[$key])){
+			$this->_options[$key] = array_merge($this->_options[$key], $value);
+		}else{
+			$this->_options[$key] = $value;
+		}
+		return $this;
+	}
+
+	/**
+	 * setOptions(Array $options)
+	 * 批量设置选项
+	 * --------------------------
+	 * @param String $options 选项集合
+	 * -------------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function setOptions($options){
+		foreach($options as $key => $value){
+			$this->setOption($key, $value);
+		}
+		return $this;
+	}
+
+	/**
+	 * unsetOption(String $key)
+	 * 删除选项
+	 * ------------------------
+	 * @param String $key 选项名称
+	 * --------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function unsetOption($key){
+		if(isset($this->_options[$key])){
+			unset($this->_options[$key]);
+		}
+		return $this;
+	}
+
+	/**
+	 * resetOptions()
+	 * 重置选项
+	 * --------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function resetOptions(){
+		if (isset($this->_options)) {
+			$this->_options = [];
+		}
+		return $this;
+	}
+
+	/**
+	 * reset()
+	 * 重置
+	 * -------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function reset(){
+		if($this->_curl !== null){
+			@curl_close($this->_curl);
+		}
+		$this->_curl = null;
+		$this->_options = [];
+		$this->_response = null;
+		$this->_responseCode = null;
+		return $this;
+	}
+
+	/**
+	 * getOption(String $key)
+	 * 获取选项内容
+	 * ----------------------
+	 * @param String $key 选项名称
+	 * ---------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function getOption($key){
+		$mergesOptions = $this->getOptions();
+		return isset($mergesOptions[$key]) ? $mergesOptions[$key] : false;
+	}
+
+	/**
+	 * getOptions()
+	 * 获取所有的选项内容
+	 * ------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function getOptions(){
+		return $this->_options + $this->_defaultOptions;
+	}
+
+	/**
+	 * getInfo(String $opt)
+	 * 获取连接资源句柄的信息
+	 * ----------------------
+	 * @param String $opt 选项名称
+	 * ---------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	public function getInfo($opt = null){
+		if($this->_curl !== null && $opt === null){
+			return curl_getinfo($this->_curl);
+		}else if($this->_curl !== null && $opt !== null){
+			return curl_getinfo($this->_curl, $opt);
+		}else{
+			return [];
+		}
+	}
+
+	/**
+	 * getResponse()
+	 * 获取响应内容
+	 * -------------
+	 * @return Mixed
+	 * @author Verdient。
+	 */
+	public function getResponse(){
+		return $this->_response;
+	}
+
+	/**
+	 * getResponseCode()
+	 * 获取状态码
+	 * -----------------
+	 * @return Integer
+	 * @author Verdient。
+	 */
+	public function getResponseCode(){
+		return $this->_responseCode;
+	}
+
+	/**
+	 * _httpRequest(String $method, String $url, String $dataType)
+	 * http请求
+	 * -----------------------------------------------------------
+	 * @param String $method 请求方式
+	 * @param String $url 请求地址
+	 * @param String $dataType 返回数据格式
+	 * ------------------------------------
+	 * @return Object
+	 * @author Verdient。
+	 */
+	private function _httpRequest($method, $url, $dataType = null){
+		$this->setOption(CURLOPT_CUSTOMREQUEST, strtoupper($method));
+		if($method === 'HEAD'){
+			$this->setOption(CURLOPT_NOBODY, true);
+			$this->unsetOption(CURLOPT_WRITEFUNCTION);
+		}
+		$query = $this->getOption(self::CURLOPT_QUERY);
+		if(!empty($query)){
+			$url = $url . '?' . http_build_query($query);
+		}
+		$this->_curl = curl_init($url);
+		$options = $this->getOptions();
+		$curlOptions = [];
+		foreach($options as $key => $value){
+			if(is_numeric($key)){
+				$curlOptions[$key] = $value;
+			}
+		}
+		curl_setopt_array($this->_curl, $curlOptions);
+		$body = curl_exec($this->_curl);
+		if($body === false){
+			$errorCode  = curl_errno($this->_curl);
+			Yii::error(['code' => $errorCode, 'type' => curl_strerror($errorCode), 'message' => curl_error($this->_curl), 'info' => curl_getinfo($this->_curl), 'version' => curl_version()], __METHOD__);
+			switch($errorCode){
+				case 7:
+					throw new HttpException(504, 'CUrl requset timeout');
+					break;
+				default:
+					throw new HttpException(502, 'CUrl requset error(' . $errorCode . ')');
+					break;
+			}
+		}
+		$this->_responseCode = curl_getinfo($this->_curl, CURLINFO_HTTP_CODE);
+		$this->_response = $body;
+		if($this->getOption(CURLOPT_CUSTOMREQUEST) === 'HEAD'){
+			$this->reset();
+			return true;
+		}
+		Yii::trace(['method' => $method, 'url' => $url, 'options' => $options, 'code' => $this->_responseCode, 'response' => $this->_response], __METHOD__);
+		switch(strtoupper($dataType)){
+			case 'JSON':
+				try{
+					$this->_response = Json::decode($this->_response);
+				}catch(\Exception $e){
+					Yii::warning(['method' => $method, 'url' => $url, 'options' => $options, 'responseCode' => $this->_responseCode, 'response' => $this->_response], __METHOD__);
+				}
+				break;
+		}
+		if($this->onlyContent === true){
+			$response = $this->_response;
+		}else{
+			$response = ['code' => $this->_responseCode, 'content' => $this->_response];
+		}
+		$this->reset();
+		return $response;
+	}
+}

+ 290 - 0
components/components/messageQueue/MessageInterface.php

@@ -0,0 +1,290 @@
+<?php
+namespace components\components\messageQueue;
+
+use Yii;
+use yii\base\Component;
+
+/**
+ * MessageInterface
+ * 消息队列 接口
+ * -----------------
+ * @author Verdient。
+ * @version 1.0.0
+ */
+class MessageInterface extends Component {
+
+	/**
+	 * @var public String $key
+	 * 签名密钥
+	 * -----------------------
+	 * @method Config
+	 * @author Verdient。
+	 */
+	public $key;
+
+	/**
+	 * @var public $protocol
+	 * 访问协议
+	 * ---------------------
+	 * @method Config
+	 * @author Verdient。
+	 */
+	public $protocol = '';
+
+	/**
+	 * @var public $host
+	 * 域名
+	 * -----------------
+	 * @method Config
+	 * @author Verdient。
+	 */
+	public $host = '';
+
+	/**
+	 * @var public $port
+	 * 端口
+	 * -----------------
+	 * @method Config
+	 * @author Verdient。
+	 */
+	public $port = '';
+
+	/**
+	 * @var public $_urlPrefix
+	 * URL 路径前缀
+	 * -----------------------
+	 * @author Verdient。
+	 */
+	protected $_urlPrefix;
+
+	/**
+	 * init()
+	 * 初始化
+	 * ------
+	 * @param String $publicKey 公钥
+	 * -----------------------------
+	 * @return Array / false
+	 * @author Verdient。
+	 */
+	public function init(){
+		parent::init();
+		if(!$this->protocol){
+			$this->protocol = Yii::$app->request->isSecureConnection ? 'https' : 'http';
+		}
+		if(!$this->host){
+			$this->host = explode(':', $_SERVER['HTTP_HOST'])[0];
+		}
+		$this->_urlPrefix = $this->protocol . '://' . $this->host . ($this->port ? (($this->protocol == 'https' && $this->port == 443) || ($this->protocol == 'http' && $this->port == 80) ? '' : (':' . $this->port)) : '');
+	}
+
+	/**
+	 * createQueue(String $name)
+	 * 创建队列
+	 * -------------------------
+	 * @param String $name 队列名称
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function createQueue($name){
+		return $this->_formatResponse($this->_send('post', '/queue/create', ['name' => $name]));
+	}
+
+	/**
+	 * queueList()
+	 * 队列列表
+	 * -----------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function queueList(){
+		return $this->_formatResponse($this->_send('get', '/queue/list'));
+	}
+
+	/**
+	 * deleteQueue(String $name)
+	 * 删除队列
+	 * -------------------------
+	 * @param String $name 队列名称
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function deleteQueue($name){
+		return $this->_formatResponse($this->_send('post', '/queue/delete', ['name' => $name]));
+	}
+
+	/**
+	 * sendMessage(String $name, Array $message)
+	 * 发送消息
+	 * -----------------------------------------
+	 * @param String $name 队列名称
+	 * @param Array $message 消息
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function sendMessage($name, Array $message){
+		return $this->_formatResponse($this->_send('post', '/message/send', ['queue' => $name, 'message' => $message]));
+	}
+
+	/**
+	 * batchSendMessage(String $name, Array $message)
+	 * 批量发送消息
+	 * ----------------------------------------------
+	 * @param String $name 队列名称
+	 * @param Array $message 消息
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function batchSendMessage($name, Array $message){
+		return $this->_formatResponse($this->_send('post', '/message/batch-send', ['queue' => $name, 'message' => $message]));
+	}
+
+	/**
+	 * messageList(String $name)
+	 * 消息列表
+	 * -------------------------
+	 * @param String $name 队列名称
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function messageList($name){
+		return $this->_formatResponse($this->_send('get', '/message/list', [], ['name' => $name]));
+	}
+
+	/**
+	 * flushMessage(String $name)
+	 * 清空消息
+	 * --------------------------
+	 * @param String $name 队列名称
+	 * ---------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function flushMessage($name){
+		return $this->_formatResponse($this->_send('post', '/message/purge', ['name' => $name]));
+	}
+
+	/**
+	 * consumeMessage(String $name, Integer $count)
+	 * 消费消息
+	 * --------------------------------------------
+	 * @param String $name 队列名称
+	 * @param Integer $count 消费数量
+	 * ------------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function consumeMessage($name, $count){
+		return $this->_formatResponse($this->_send('post', '/message/purge', ['name' => $name, 'count' => $count]));
+	}
+
+	/**
+	 * deleteMessage(String $name, Array $ids)
+	 * 删除消息
+	 * ---------------------------------------
+	 * @param String $name 队列名称
+	 * @param Array $ids 消息编号集合
+	 * -------------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function deleteMessage($name, Array $ids){
+		return $this->_formatResponse($this->_send('post', '/message/delete', ['name' => $name, 'mids' => $ids]));
+	}
+
+	/**
+	 * ackMessage(String $name, Array $ids)
+	 * 应答消息
+	 * ------------------------------------
+	 * @param String $name 队列名称
+	 * @param Array $ids 消息编号集合
+	 * -----------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function ackMessage($name, Array $ids){
+		return $this->_formatResponse($this->_send('post', '/message/ack', ['name' => $name, 'mids' => $ids]));
+	}
+
+	/**
+	 * messageStatus(String $name, String $id)
+	 * 消息状态
+	 * ---------------------------------------
+	 * @param String $name 队列名称
+	 * @param String $id 消息编号
+	 * ----------------------------
+	 * @author Verdient。
+	 */
+	public function messageStatus($name, $id){
+		return $this->_formatResponse($this->_send('get', '/query/message-status', [], ['queue' => $name, 'mid' => $id]));
+	}
+
+	/**
+	 * _send(String $method, String $url[, Array $data = []])
+	 * 发送数据
+	 * ------------------------------------------------------
+	 * @param String $method 访问方法
+	 * @param String $url URL路径
+	 * @param Array $data 发送的数据
+	 * ------------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	protected function _send($method, $url, Array $data = [], Array $query = []){
+		$method = strtolower($method);
+		if(!empty($query)){
+			$url .= '?' . http_build_query($query);
+		}
+		$url = $this->_urlPrefix . $url;
+		$signature = new Signature();
+		$signature->key = $this->key;
+		$signature->verb = $method;
+		if($method == 'post'){
+			if(!empty($data)){
+				Yii::$app->cUrl->setData($data, 'JSON');
+			}
+			$signature->content = $data;
+		}
+		Yii::$app->cUrl->setHeader([
+			'Authorization' => 'FzmMQ client_test:' . $signature->signature,
+			'Verb' => $signature->verb,
+			'Date' => $signature->date,
+			'Content-Md5' => $signature->contentMd5,
+			'Signature-Method' => $signature->signatureMethod,
+			'Signature-Version' => $signature->signatureVersion
+		]);
+		$options = Yii::$app->cUrl->getOptions();
+		$response = Yii::$app->cUrl->$method($url, 'JSON');
+		Yii::trace(['url' => $url, 'cUrl' => $options, 'response' => $response], __METHOD__);
+		return $response;
+	}
+
+	/**
+	 * _formatResponse(Mixed $response)
+	 * 格式化响应
+	 * --------------------------------
+	 * @param Mixed $response 响应内容
+	 * ------------------------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	protected function _formatResponse($response){
+		$flag = false;
+		if(is_array($response) && isset($response['code']) && $response['code'] == 200){
+			$flag = true;
+		}
+		return $flag ? [
+			'result' => $flag,
+			'data' => isset($response['data']) ? $response['data'] : null,
+			'code' => $response['code']
+		] : [
+			'result' => $flag,
+			'message' => isset($response['message']) ? $response['message'] : 'Unknown Error',
+			'code' => isset($response['code']) ? $response['code'] : 500
+		];
+	}
+}

+ 220 - 0
components/components/messageQueue/Signature.php

@@ -0,0 +1,220 @@
+<?php
+namespace components\components\messageQueue;
+
+use yii\base\Component;
+use yii\base\InvalidParamException;
+
+/**
+ * Signature
+ * 签名
+ * ---------
+ * @author Verdient。
+ * @version 1.0.0
+ */
+class Signature extends Component {
+
+	/**
+	 * @var public String $key
+	 * 签名密钥
+	 * -----------------------
+	 * @author Verdient。
+	 */
+	public $key;
+
+	/**
+	 * @var public String $verb
+	 * 访问方式
+	 * ------------------------
+	 * @author Verdient。
+	 */
+	public $verb;
+
+	/**
+	 * @var public String $contentType
+	 * 消息体类型
+	 * -------------------------------
+	 * @author Verdient。
+	 */
+	public $contentType = 'application/json';
+
+	/**
+	 * @var public String $signatureMethod
+	 * 签名方法
+	 * -----------------------------------
+	 * @author Verdient。
+	 */
+	public $signatureMethod = 'MD5';
+
+	/**
+	 * @var public String $signatureVersion
+	 * 签名版本
+	 * ------------------------------------
+	 * @author Verdient。
+	 */
+	public $signatureVersion = '1.0';
+
+	/**
+	 * @var public String $_content
+	 * 消息体
+	 * ----------------------------
+	 * @author Verdient。
+	 */
+	public $_content = [];
+
+	/**
+	 * @var protected String $_contentMd5
+	 * 消息体MD5值
+	 * ----------------------------------
+	 * @author Verdient。
+	 */
+	protected $_contentMd5 = null;
+
+	/**
+	 * @var protected String $_date
+	 * 日期
+	 * ----------------------------
+	 * @author Verdient。
+	 */
+	protected $_date;
+
+	/**
+	 * @var protected String $_signature
+	 * 签名
+	 * ---------------------------------
+	 * @author Verdient。
+	 */
+	protected $_signature;
+
+	/**
+	 * setContent(Array $content)
+	 * 设置消息体
+	 * --------------------------
+	 * @param Array $content 消息体
+	 * ----------------------------
+	 * @author Verdient。
+	 */
+	public function setContent(Array $content){
+		static::_prepareContent($content);
+		$this->_content = $content;
+	}
+
+	/**
+	 * getContent()
+	 * 获取消息体
+	 * ------------
+	 * @return Array
+	 * @author Verdient。
+	 */
+	public function getContent(){
+		return $this->_content;
+	}
+
+	/**
+	 * setDate(Mixed $date)
+	 * 设置日期
+	 * --------------------
+	 * @param Mixed $date 日期
+	 * -----------------------
+	 * @author Verdient。
+	 */
+	public function setDate($date){
+		if(is_numeric($date) && ctype_digit($str) && $str <= 2147483647){
+			$this->_date = gmdate('D, d M Y H:i:s \G\M\T', $date);
+		}else if(is_string($date)){
+			$this->_date = gmdate('D, d M Y H:i:s \G\M\T', strtotime($date));
+		}else{
+			throw new InvalidParamException('Data must be a timestamp or date string');
+		}
+	}
+
+	/**
+	 * getDate()
+	 * 获取日期
+	 * ---------
+	 * @return String
+	 * @author Verdient。
+	 */
+	public function getDate(){
+		if(!$this->_date){
+			$this->_date = gmdate('D, d M Y H:i:s \G\M\T');
+		}
+		return $this->_date;
+	}
+
+	/**
+	 * getContentMd5()
+	 * 获取消息体MD5值
+	 * ---------------
+	 * @return String
+	 * @author Verdient。
+	 */
+	public function getContentMd5(){
+		if(!$this->_contentMd5 !== null){
+			if(!is_array($this->content)){
+				throw new InvalidParamException('Content must be an Array');
+			}
+			$this->_contentMd5 = empty($this->content) ? '' : md5(json_encode($this->content));
+		}
+		return $this->_contentMd5;
+	}
+
+	/**
+	 * getSignature()
+	 * 获取签名
+	 * --------------
+	 * @return String
+	 * @author Verdient。
+	 */
+	public function getSignature(){
+		if(!$this->_signature){
+			if(!$this->key){
+				throw new InvalidParamException('Signature key must be set');
+			}
+			$this->_signature = md5(base64_encode(hash_hmac("sha1", $this->_buildSignatureString(), $this->key . '&', true)));
+		}
+		return $this->_signature;
+	}
+
+	/**
+	 * _buildSignatureString()
+	 * 构建待签名的字符串
+	 * -----------------------
+	 * @return String
+	 * @author Verdient。
+	 */
+	protected function _buildSignatureString(){
+		return strtoupper($this->verb) .
+			"\n\n" .
+			$this->contentMd5 .
+			"\n" .
+			$this->contentType .
+			"\n" .
+			$this->date.
+			"\n" .
+			$this->signatureMethod .
+			"\n" .
+			$this->signatureVersion .
+			"\n\n" .
+			$this->key .
+			"\n";
+	}
+
+	/**
+	 * _prepareContent(Array &$content)
+	 * 准备消息体
+	 * --------------------------------
+	 * @param Array &$content 消息体
+	 * ----------------------------
+	 * @author Verdient。
+	 */
+	protected static function _prepareContent(&$content){
+		ksort($content);
+		foreach($content as $key => $value){
+			if(empty($value)){
+				unset($content[$key]);
+			}else if(is_array($value)){
+				static::_prepareContent($content[$key]);
+			}
+		}
+	}
+}

+ 3 - 0
components/config/.gitignore

@@ -0,0 +1,3 @@
+main-local.php
+params-local.php
+/bootstrap.php

+ 14 - 0
components/config/main.php

@@ -0,0 +1,14 @@
+<?php
+return [
+	'components' => [
+		'cUrl' => [
+			'class' => '\components\CUrl'
+		],
+		'messageQueue' => [
+			'class' => 'common\components\messageQueue\MessageInterface',
+			'key' => 'QkwzrML50o1KIK5bI-HbkVBcTSA_Ehdh',
+			'protocol' => 'http',
+			'host' => '120.78.153.45'
+		]
+	]
+];