PHPackages                             bingher/ali-sms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. bingher/ali-sms

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

bingher/ali-sms
===============

send aliyun sms

v1.1.4(5mo ago)142.2k↓100%1MITPHPPHP &gt;=7.0

Since Oct 17Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/hbh112233abc/ali-sms)[ Packagist](https://packagist.org/packages/bingher/ali-sms)[ RSS](/packages/bingher-ali-sms/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (0)

ali-sms
=======

[](#ali-sms)

php plugin for aliyun sms,only send sms

install
-------

[](#install)

```
composer require bingher/ali-sms

```

use
---

[](#use)

```
use bingher\sms\AliSms;
$config = [
    'version' => '2017-05-25',
    'host' => 'dysmsapi.aliyuncs.com',
    'scheme' => 'http',
    'region_id' => 'cn-hangzhou',
    'access_key' => 'your aliyun accessKeyId',
    'access_secret' => 'your aliyun accessSecret',
    'product' => '海迈电子档案平台',
    'actions' => [
        'register' => [
            'sign_name' => '注册验证',
            'template_code' => 'SMS_67105498',
            'template_param' => [
                'code' => '',
                'product' => '',
            ]
        ],
        'login' => [
            'sign_name' => '登录验证',
            'template_code' => 'SMS_67105500',
            'template_param' => [
                'code' => '',
                'product' => '',
            ]
        ],
        'change_password' => [
            'sign_name' => '变更验证',
            'template_code' => 'SMS_67105496',
            'template_param' => [
                'code' => '',
                'product' => '',
            ]
        ],
    ],
];

$sms = new AliSms($config);
//注册验证
$sms->register('18759201xxx',['code'=>123456]);
//或者
$sms->register('18759201xxx',['code'=>123456,'product'=>'xxx平台']);
//传参中请根据actions中不同动作的template_param的值设置,如果不传product默认取配置的product值

//登录验证
$sms->login('18759201xxx',['code'=>123456]);
//或者
$sms->login('18759201xxx',['code'=>123456,'product'=>'xxx平台']);

//修改密码
$sms->change_password('18759201xxx',['code'=>123456]);
//或者
$sms->changePassword('18759201xxx',['code'=>123456,'product'=>'xxx平台']);

//AliSms中的短信方法可以根据actions配置自动匹配,如上配置有三个方法分别是:register,login,change_password,用户可以根据自己的业务需求增加其他配置

```

config remark
-------------

[](#config-remark)

配置类型默认必须配置说明versionstring`2017-05-25`N日期格式,阿里云短信 sdk 版本hoststring`dysmsapi.aliyuncs.com`N阿里云短信服务器域名schemestringhttpN请求协议,https/httpregion\_idstring`cn-hangzhou`Y阿里云短信服务器所在地区,请从阿里云短信服务获取access\_keystringY你的阿里云 accessKeyIdaccess\_secretstringY你的阿里云 accessSecretproductstringY你的平台产品名称,actions 中 template\_param 参数 product 用的默认值actionsarrayY操作配置,不同动作的配置数组,格式为`动作名=>配置项数组`,*动作名*请用全小写下划线格式,如:change\_password,如此调用时可以访问`$sms->change_password(...);`亦可`$sms->changePassword(...);`,*配置项*内容请参考阿里云短信模板for thinkphp6
-------------

[](#for-thinkphp6)

### step1 新增配置文件 config/ali\_sms.php

[](#step1-新增配置文件-configali_smsphp)

```
