GithubHelp home page GithubHelp logo

andrew-wang / aliyun Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weijiansdlx/aliyun

0.0 2.0 0.0 1.12 MB

Yii2 extension for aliyun dayu,log,mns,oss

License: BSD 3-Clause "New" or "Revised" License

PHP 24.53% Batchfile 0.06% Shell 0.07% HTML 73.40% CSS 0.20% JavaScript 1.73%

aliyun's Introduction

###阿里云[OSS,DAYU,LOG,MNS, MQ]

阿里云官方SDK的Composer封装,支持Yii2。 添加删除文件的功能,修改getUrl(只返回文件外链url,不带其他参数)。

###安装

$ php composer.phar require gulltour/aliyun "~1.0.0"

###OSS Yii2使用

修改config/params.php

添加:

'oss'=>[
         'class'=>'gulltour\aliyun\oss\AliyunOss',
         'bucket'=>'',
         'AccessKeyId' => '',
         'AccessKeySecret' => '',
         'ossServer' => '', //服务器外网地址,杭州为 http://oss-cn-hangzhou.aliyuncs.com
         'ossServerInternal' => '', //服务器内网地址,杭州为 http://oss-cn-hangzhou-internal.aliyuncs.com 如果为空则不走内网上传,内网上传会节省流量
         'imageHost' => '' //自定义资源域名 默认为 http://bucket.img-cn-hangzhou.aliyuncs.com/
     ],

###使用

Yii::$app->oss->upload2oss($filePath, $ssoPath);

Yii::$app->oss->getImageUrl($path, $style=null);

###LOG Yii2配置

 'log'=>[
          'class'=>'aliyun\oss\AliyunLog',
          'logstore'=>'gulltour',
          'project'=>'',
          'AccessKeyId' => '',
          'AccessKeySecret' => '',
          'endpoint'=>'oss-cn-hangzhou.aliyuncs.com',
       ],

###阿里大于 Yii2配置

 'dayu'=>[
             'class'=>'gulltour\aliyun\aliyunDayu',
             'appKey' => '',
             'secretKey' => '',
             'signName' => '',
         ],

###使用

Yii::$app->dayu->smsSend($mobile, $params, $template);

MQ Yii2使用

配置

在组件配置中添加如下配置,

'notificationMq' => [
            'class' => 'gulltour\aliyun\AliyunMQ',
            'endpoint' => 'http://publictest-rest.ons.aliyun.com',
            'topic' => 'kooeu_email_sms',
            'accessKeyId' => 'iEjugjCFUSBh1IXu',
            'accessKeySecret' => 'kvNO5lvWEBLGAEOJKfTWFjVJmWmMde',
            'producerGroup' => 'PID_HYW_Message',
            'consumerGroup' => 'CID_HYW_Message',
            'messageReceiver' => function($message) {echo $message;},
            'sentCallback' => function($message, $aliMsgID) {echo $message;echo $aliMsgID;},
]

使用示例

Yii::$app->notificationMq->sendMessage('1234567891');

###MNS Yii2使用

YII2插件-阿里云消息队列SDK

配置

'mns'=>[
    'class'=>'gulltour\aliyun\aliyunMns',
    'accessId' => '',
    'accessKey' => '',
    'endpoint' => 'http://.mns.cn-beijing.aliyuncs.com/',
],

使用示例:

// 发送消息到队列
\Yii::$app->mns->sendMessage("QueueName", "content demo");
// 接收队列消息
$messageObject = \Yii::$app->mns->receiveMessage("QueueName");
$data = $messageObject->getMessageBody();
// 删除队列消息
\Yii::$app->mns->->deleteMessage('QueueName', $messageObject);
//publish 消息到主题
\Yii::$app->mns->publishMessage('TopicName', $data);
//订阅主题,在Yii2的 controller 中接收推送过来的数据
public function actionSubscribe()
{
	$message = \Yii::$app->request->getRawBody();
	$data = json_decode($message, true); //如果消息是JSON,PHP中需要转换成数组

###License 除 “版权所有(C)阿里云计算有限公司” 的代码文件外,遵循 MIT license 开源。

aliyun's People

Contributors

andrew-wang avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.