Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
weijiansdlx
committed
Mar 17, 2017
1 parent
e2145e1
commit 250885b
Showing
777 changed files
with
143,573 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace aliyun\dayu; | ||
use yii\base\Component; | ||
require_once __DIR__.'/taobao-sdk-PHP-auto/Autoloader.php'; | ||
|
||
class AliyunDayu extends Component | ||
{ | ||
|
||
private $client; | ||
public function init() | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
namespace aliyun\log; | ||
use yii\base\Component; | ||
use yii\base\InvalidConfigException; | ||
|
||
require_once __DIR__.'/aliyun-log-php-sdk-master/Log_Autoload.php'; | ||
/** | ||
* | ||
* @author weijian | ||
* 'log'=>[ | ||
* 'class'=>'aliyun\oss\AliyunLog', | ||
* 'logstore'=>'', | ||
* 'project'=>'', | ||
* 'AccessKeyId' => '', | ||
* 'AccessKeySecret' => '', | ||
* 'endpoint'=>'oss-cn-hangzhou.aliyuncs.com', | ||
* ], | ||
*/ | ||
class AliyunLog extends Component | ||
{ | ||
public $endpoint = 'cn-hangzhou.sls.aliyuncs.com'; // 选择与上面步骤创建 project 所属区域匹配的 Endpoint | ||
public $AccessKeyId = 'your_access_key_id'; // 使用你的阿里云访问秘钥 AccessKeyId | ||
public $AccessKeySecret = 'your_access_key'; // 使用你的阿里云访问秘钥 AccessKeySecret | ||
public $project = 'your_project'; // 上面步骤创建的项目名称 | ||
public $logstore = 'your_logstore'; // 上面步骤创建的日志库名称 | ||
|
||
private $client; | ||
public function init() | ||
{ | ||
parent::init(); | ||
if (!isset($this->AccessKeyId)) { | ||
throw new InvalidConfigException('请先配置AccessKeyId'); | ||
} | ||
if (!isset($this->AccessKeySecret)) { | ||
throw new InvalidConfigException('请先配置AccessKeySecret'); | ||
} | ||
$this->client = new Aliyun_Log_Client($this->endpoint, $this->AccessKeyId, $this->AccessKeySecret); | ||
} | ||
|
||
/** | ||
* 列出当前 project 下的所有日志库名称 | ||
*/ | ||
public function listStores() | ||
{ | ||
$req = new Aliyun_Log_Models_ListLogstoresRequest($this->project); | ||
return $this->client->listLogstores($req); | ||
} | ||
|
||
/** | ||
* 创建 logstore | ||
*/ | ||
public function createStores() | ||
{ | ||
$req = new Aliyun_Log_Models_CreateLogstoreRequest($this->project,$this->logstore,3,2); | ||
return $this->client -> createLogstore($req); | ||
} | ||
|
||
|
||
/** | ||
* 写入日志 | ||
*/ | ||
public function putLogs($topic, $source, $logitems=[]) | ||
{ | ||
for ($i = 0; $i < 5; $i++) | ||
{ | ||
$contents = array('index1'=> strval($i)); | ||
$logItem = new Aliyun_Log_Models_LogItem(); | ||
$logItem->setTime(time()); | ||
$logItem->setContents($contents); | ||
array_push($logitems, $logItem); | ||
} | ||
$req = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, $topic, $source, $logitems); | ||
return $this->client->putLogs($req); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?php | ||
namespace aliyun\mns; | ||
|
||
require_once __DIR__.'/aliyun-mns-php-sdk-1.3.3/mns-autoloader.php'; | ||
use yii\base\Component; | ||
use AliyunMNS\Client; | ||
use AliyunMNS\Requests\PublishMessageRequest; | ||
use AliyunMNS\Requests\CreateQueueRequest; | ||
use AliyunMNS\Model\SubscriptionAttributes; | ||
use AliyunMNS\Requests\SendMessageRequest; | ||
use AliyunMNS\Exception\MnsException; | ||
/** | ||
* ============================================== | ||
* Copy right 2016-2017 | ||
* ============================================== | ||
* 阿里云MQ SDK | ||
* @param unknowtype | ||
* @return return_type | ||
* @author: weijian | ||
*/ | ||
class AliyunMns extends Component | ||
{ | ||
public $accessId = ''; | ||
public $accessKey = ''; | ||
public $endpoint = 'http://.mns.cn-beijing.aliyuncs.com/'; | ||
private $client; | ||
|
||
public function init(){ | ||
$this->client = new Client($this->endpoint, $this->accessId, $this->accessKey); | ||
return $this->client; | ||
} | ||
|
||
public function __call($method_name, $args) | ||
{ | ||
return call_user_func_array([$this->client, $method_name],$args); | ||
} | ||
|
||
/** | ||
* ==================================================================== | ||
* 以下提供一些便捷方法,也可以通过官方SDK的方法做同样的处理 | ||
* -------------------------------------------------------------------- | ||
*/ | ||
|
||
|
||
/** | ||
* 发送消息到队列 | ||
* @param string $queueName 队列名称 | ||
* @param string $messageBody 消息内容 | ||
* @return \AliyunMNS\SendMessageResponse: | ||
* @example sendMessage("boss-dev", "content demo"); | ||
*/ | ||
public function createQueue($queueName) | ||
{ | ||
$request = new CreateQueueRequest($queueName); | ||
try | ||
{ | ||
return $this->client->createQueue($request); | ||
} | ||
catch (MnsException $e) | ||
{ | ||
echo "CreateQueueFailed: " . $e; | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* 发送消息到队列 | ||
* @param string $queueName 队列名称 | ||
* @param string $messageBody 消息内容 | ||
* @return \AliyunMNS\SendMessageResponse: | ||
* @example sendMessage("boss-dev", "content demo"); | ||
*/ | ||
public function sendMessage($queueName, $messageBody) | ||
{ | ||
if (!is_string($messageBody)){ | ||
$messageBody = json_encode($messageBody); | ||
} | ||
$queue = $this->client->getQueueRef($queueName); | ||
try | ||
{ | ||
$request = new SendMessageRequest($messageBody); | ||
return $queue->sendMessage($request); | ||
} | ||
catch (MnsException $e) | ||
{ | ||
echo "SendMessage Failed: " . $e; | ||
return; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* 从队列里获取消息 | ||
* @param string $queueName 队列名称 | ||
* @return \AliyunMNS\ReceiveMessageResponse: | ||
* @example receiveMessage("boss-dev"); | ||
*/ | ||
public function receiveMessage($queueName) | ||
{ | ||
$receiptHandle = NULL; | ||
$queue = $this->client->getQueueRef($queueName); | ||
try | ||
{ | ||
// when receiving messages, it's always a good practice to set the waitSeconds to be 30. | ||
// it means to send one http-long-polling request which lasts 30 seconds at most. | ||
return $queue->receiveMessage(30); | ||
} | ||
catch (MnsException $e) | ||
{ | ||
echo "ReceiveMessage Failed: " . $e; | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* 删除消息 | ||
* @param object $messageObject 消息实体 | ||
* @return \AliyunMNS\Responses\ReceiveMessageResponse | ||
*/ | ||
public function deleteMessage($queueName, $messageObject) | ||
{ | ||
$queue = $this->client->getQueueRef($queueName); | ||
$receiptHandle = $messageObject->getReceiptHandle(); | ||
return $queue->deleteMessage($receiptHandle); | ||
} | ||
|
||
/** | ||
* 发布消息到Topic | ||
* @param string $topicName Toppic名称 | ||
* @param string $messageBody 消息内容 | ||
* @example publishMessage('customer-login-dev', 'test content'); | ||
* @return \AliyunMNS\Responses\BaseResponse | ||
*/ | ||
public function publishMessage($topicName, $messageBody) | ||
{ | ||
if (!is_string($messageBody)){ | ||
$messageBody = json_encode($messageBody); | ||
} | ||
$topic = $this->client->getTopicRef($topicName); | ||
$request = new PublishMessageRequest($messageBody); | ||
|
||
return $topic->publishMessage($request); | ||
} | ||
|
||
/** | ||
* 添加订阅器 | ||
* @param string $topicName Topic名称 | ||
* @param string $subscriptionName 订阅器名称 | ||
* @param url $endPoint 接收内容的URL,包含 http://,其它方式看阿里云的文档 | ||
* @return \AliyunMNS\Responses\BaseResponse | ||
*/ | ||
public function subscribeTopic($topicName, $subscriptionName, $endPoint) | ||
{ | ||
$topic = $this->client->getTopicRef($topicName); | ||
$attributes = new SubscriptionAttributes($subscriptionName, $endPoint); | ||
|
||
return $topic->subscribe($attributes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
namespace aliyun\oss; | ||
use yii\base\Component; | ||
use OSS\Core\OssException; | ||
require_once __DIR__.'/aliyun-oss-php-sdk-2.2.2/autoload.php'; | ||
/** | ||
* | ||
* @author weijian | ||
* 'oss'=>[ | ||
* 'class'=>'aliyun\oss\AliyunOss', | ||
* 'bucket'=>'', | ||
* 'prefix'=>'', | ||
* 'AccessKeyId' => '', | ||
* 'AccessKeySecret' => '', | ||
* 'endpoint'=>'oss-cn-hangzhou.aliyuncs.com', | ||
* 'imageHost' => 'http://bucket.img-cn-hangzhou.aliyuncs.com/' | ||
* ], | ||
*/ | ||
class AliyunOss extends Component | ||
{ | ||
public $bucket = ''; | ||
public $prefix = ''; //路径前缀 | ||
public $AccessKeyId = ''; | ||
public $AccessKeySecret = ''; | ||
public $endpoint = 'oss-cn-hangzhou.aliyuncs.com'; | ||
public $imageHost = 'http://bucket.img-cn-hangzhou.aliyuncs.com/'; | ||
|
||
private $client; | ||
public function init() | ||
{ | ||
if (empty($this->imageHost)) { | ||
$this->imageHost = 'http://'.$this->bucket.'/'.$this->endpoint.'/'; | ||
} | ||
try { | ||
$this->client = new \OSS\OssClient($this->AccessKeyId, $this->AccessKeySecret, $this->endpoint); | ||
} catch (OssException $e) { | ||
print $e->getMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* 上传文件到OSS | ||
*/ | ||
public function upload2oss($tempName, $path=null) | ||
{ | ||
try { | ||
$stream = file_get_contents($tempName); | ||
if (empty($path)){ | ||
$path = date('Ymd').mb_substr(md5($stream), -8); | ||
} | ||
$this->client->putObject($this->bucket, $this->prefix.$path, $stream); | ||
return $path; | ||
} catch (OssException $ex) { | ||
throw new \ErrorException( "Error: " . $ex->getMessage() . "\n"); | ||
} | ||
} | ||
|
||
/** | ||
* 上传文件流到OSS | ||
*/ | ||
public function uploadStream2oss($stream,$filename) | ||
{ | ||
try { | ||
return $this->client->putObject( $this->bucket, $this->prefix.$filename, $stream); | ||
} catch (OSSException $ex) { | ||
throw new \ErrorException( "Error: " . $ex->getMessage() . "\n"); | ||
} | ||
} | ||
|
||
/** | ||
* 获取图片地址 | ||
* @param string $path 路径 | ||
* @param string $style 样式 | ||
*/ | ||
public function getImageUrl($path, $style=null) | ||
{ | ||
if (empty($style)){ | ||
return $this->imageHost.$this->prefix.$path; | ||
} | ||
return $this->imageHost.$this->prefix.$path.'@!'.$style; | ||
} | ||
|
||
public function __call($method_name, $args) | ||
{ | ||
if(empty($args['Bucket'])){ | ||
$args['Bucket'] = $this->bucket; | ||
} | ||
return call_user_func_array([$this->client, $method_name],$args); | ||
} | ||
} |
Oops, something went wrong.