SmsLogic.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\logic;
  15. use app\common\enum\notice\NoticeEnum;
  16. use app\common\logic\BaseLogic;
  17. /**
  18. * 短信逻辑
  19. * Class SmsLogic
  20. * @package app\api\logic
  21. */
  22. class SmsLogic extends BaseLogic
  23. {
  24. /**
  25. * @notes 发送验证码
  26. * @param $params
  27. * @return false|mixed
  28. * @author 段誉
  29. * @date 2022/9/15 16:17
  30. */
  31. public static function sendCode($params)
  32. {
  33. try {
  34. $scene = NoticeEnum::getSceneByTag($params['scene']);
  35. if (empty($scene)) {
  36. throw new \Exception('场景值异常');
  37. }
  38. $result = event('Notice', [
  39. 'scene_id' => $scene,
  40. 'params' => [
  41. 'mobile' => $params['mobile'],
  42. 'code' => mt_rand(1000, 9999),
  43. ]
  44. ]);
  45. return $result[0];
  46. } catch (\Exception $e) {
  47. self::$error = $e->getMessage();
  48. return false;
  49. }
  50. }
  51. }