12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Elton
- * Date: 2020/7/16
- * Time: 18:23
- */
- namespace app\common\service;
- use app\common\constants\ShortMsgConstants;
- use app\common\library\Redis;
- use think\Config;
- class VipShortMsgService
- {
- protected static $instance;
- public static function instance(){
- if (is_null(self::$instance)) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 登录账号异常后,短信通知管理员
- * @param string $throw_msg 登录异常的推送信息
- */
- public function throwNotice($throw_msg)
- {
- // 1.获取管理员手机号
- $mobiles = explode(',', str_replace(',', ',', trim(Config::get('site.throw_mobiles'))));
- // 2.遍历手机号,推送告警信息
- if ($mobiles) {
- foreach ($mobiles as $k => $mobile) {
- if ($mobile && strlen($mobile) == 11) {
- ShortMessageService::instance()->singleMsg($throw_msg, $mobile);
- LogService::info("ThrowNotice:发送内容:" . $throw_msg . ":手机号:" . $mobile);
- }
- }
- }
- }
- /**
- * 发送短信验证码
- * @param $phone 手机号
- * @return int
- */
- public function sendShortMsg($phone)
- {
- $code = ShortMessageService::instance()->generateSMSCode();
- $content = "您的验证码为{$code},五分钟内有效,切勿将验证码泄露与他人。如有问题请联系客服!";
- try {
- $data = ShortMessageService::instance()->singleShortMsg($content, $phone);
- if ($data['code']) {
- return $code;
- } else {
- LogService::error('VipShortMsgService:' . $data['code']);
- return false;
- }
- } catch (\Exception $e) {
- LogService::error($e->getMessage());
- return false;
- }
- }
- }
|