小程序/yii2-mns

阿里云、云片短信推送,yii2-mns

安装: 34

依赖: 0

建议: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

v1.0.1 2017-08-07 03:16 UTC

This package is auto-updated.

Last update: 2024-09-14 19:25:55 UTC


README

阿里云、云片短信推送

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

composer require xiaochengfu/yii2-mns "v1.0.1"

或者

"xiaochengfu/yii2-mns": "*"

将以下内容添加到您的 composer.json 文件的 require 部分。

使用方法

1.在主配置文件中增加components

'components' => [
      'mns'=>[
                 'class'=> 'xiaochengfu\mns\Module',
                 'config'=>[
                     'aliyun'=>[
                         'active'=>true, //true位开启,false为关闭
                         'accessId' => 'xxxx',
                         'accessKey' => 'xxxxxxxxx',
                         'endpoint' => 'http://xxxx.mns.cn-hangzhou.aliyuncs.com/',
                         'topicName' => 'xxx',
                         'smsSignName' => 'xxxx',
                     ],
                     'yunpian' => [
                         'active'=>false,
                         'apikey' => 'xxxxxx', // 请替换成您的apikey
                     ]
                 ]

             ],
]

2.在程序中使用:

当使用云片时:

$smsParams = '具体的消息内容';

当使用阿里云时:

$smsParams = [
    'code'=>'xxx',
    'product'=>'xxx'
];

单条发送:

Yii::$app->mns->send('186********',$smsParams,MnsComponent::YZM);

//批量发送

$mobile = ['phone1','phone2','phone3'];
$result = Yii::$app->mns->batchSend($mobile,$smsParams,MnsComponent::YZM);

$smsParams与MnsComponent::YZM的类型要一致,这里可以根据自己的模板id自行定义规则!