-
Notifications
You must be signed in to change notification settings - Fork 1.6k
liaofei edited this page Jan 20, 2021
·
1 revision
短信为驱动类加载,可以二开加入的不同驱动
配置文件
\config\sms.php
只需要在stores
下加入驱动名称,对应配置参数,如:aliyun
<?php
return [
//默认支付模式
'default' => 'yunxin',
//单个手机每日发送上限
'maxPhoneCount' => 10,
//验证码每分钟发送上线
'maxMinuteCount' => 20,
//单个IP每日发送上限
'maxIpCount' => 50,
//驱动模式
'stores' => [
//云信
'yunxin' => [
//短信模板id
'template_id' => [
//验证码自定义时效
'VERIFICATION_CODE_TIME' => 538393,
//验证码
'VERIFICATION_CODE' => 518076,
//支付成功
'PAY_SUCCESS_CODE' => 520268,
//发货提醒
'DELIVER_GOODS_CODE' => 520269,
//确认收货提醒
'TAKE_DELIVERY_CODE' => 520271,
//管理员下单提醒
'ADMIN_PLACE_ORDER_CODE' => 520272,
//管理员退货提醒
'ADMIN_RETURN_GOODS_CODE' => 520274,
//管理员支付成功提醒
'ADMIN_PAY_SUCCESS_CODE' => 520273,
//管理员确认收货
'ADMIN_TAKE_DELIVERY_CODE' => 520422,
//改价提醒
'PRICE_REVISION_CODE' => 528288,
//订单未支付
'ORDER_PAY_FALSE' => 528116,
],
],
//阿里云
'aliyun' => [
'template_id' => [
//验证码
'VERIFICATION_CODE' => '',
//支付成功
'PAY_SUCCESS_CODE' => '',
//发货提醒
'DELIVER_GOODS_CODE' => '',
//确认收货提醒
'TAKE_DELIVERY_CODE' => '',
//管理员下单提醒
'ADMIN_PLACE_ORDER_CODE' => '',
//管理员退货提醒
'ADMIN_RETURN_GOODS_CODE' => '',
//管理员支付成功提醒
'ADMIN_PAY_SUCCESS_CODE' => '',
//管理员确认收货
'ADMIN_TAKE_DELIVERY_CODE' => '',
//改价提醒
'PRICE_REVISION_CODE' => '',
//订单未支付
'ORDER_PAY_FALSE' => '',
],
'sign_name' => '',
'access_key_id' => '',
'access_key_secret' => '',
'region_id' => ''
]
]
];
\crmeb\services\sms\Sms.php
短信驱动入口类,继承 \crmeb\basic\BaseManager
类,
<?php
namespace crmeb\services\sms;
use crmeb\basic\BaseManager;
use crmeb\services\sms\storage\Yunxin;
use think\facade\Config;
/**
* Class Sms
* @package crmeb\services\sms
* @mixin Yunxin
*/
class Sms extends BaseManager
{
/**
* 空间名
* @var string
*/
protected $namespace = '\\crmeb\\services\\sms\\storage\\';
/**
* 默认驱动
* @return mixed
*/
protected function getDefaultDriver()
{
return Config::get('sms.default', 'yunxin');
}
}
目录\crmeb\services\sms\storage\
必需继承\crmeb\basic\BaseSms
类,并实现发送短信方法send
:
/**
* 发送短信
* @param string $phone
* @param string $templateId
* @param array $data
* @return mixed
*/
abstract public function send(string $phone, string $templateId, array $data = []);
实例化短信类:
$sms = new Sms('yunxin', [
'sms_account' => 'your_account',
'sms_token' => 'your_token',
'site_url' => '请求根域名'
])
也可以使用:
$sms = app()->make(Sms::class, ['yunxin',[
'sms_account' => 'your_account',
'sms_token' => 'your_token',
'site_url' => '请求根域名'
]]);
发送短信,直接使用$sms
调用send
方法传入参数就可以了:
$sms->send('发送人手机号', '使用短信模版编号,配置文件中', '模版必需参数,array');