V2.0 - 阿里云短信
1、发送短信:
用途,如user_login(用户登录),user_register(用户注册),更多用途可以在 系统设置 - 网站设置 - 短信配置
/**
* 发送短信
*
* ```php
* Yii::$app->services->sms->send($mobile, $variate, $usage, $member_id)
* ```
* @param $mobile *手机号码
* @param $variate *短信内容键值对,例["code"=>"123"]
* @param $usage *用途,如user_login
* @param int $member_id *用户ID
* @return string|void|null
* @throws UnprocessableEntityHttpException
*/
PHP Code复制内容到剪贴板
- /**
- * @var
- */
- public $mobile;
- /**
- * @var
- */
- public $usage;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [['mobile', 'usage'], 'required'],
- [['usage'], 'in', 'range' => array_keys(LogSms::$usageExplain)],
- ['mobile', 'match', 'pattern' => RegularHelper::mobile(), 'message' => '请输入正确的手机号'],
- ];
- }
- /**
- * @return array
- */
- public function attributeLabels()
- {
- return [
- 'mobile' => '手机号码',
- 'usage' => '用途',
- ];
- }
- /**
- * @throws \yii\web\UnprocessableEntityHttpException
- */
- public function send()
- {
- $code = rand(1000, 9999);
- return Yii::$app->services->sms->send($this->mobile, ["code" => $code], $this->usage);
- }
上一篇 V2.0 - 私信通知
下一篇 V2.0 - 批量操作/批量勾选