SmsLogic.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use think\facade\Log;
  18. /**
  19. * 短信逻辑
  20. * Class SmsLogic
  21. * @package app\api\logic
  22. */
  23. class SmsLogic extends BaseLogic
  24. {
  25. /**
  26. * @notes 发送验证码
  27. * @param $params
  28. * @return false|mixed
  29. * @author 段誉
  30. * @date 2022/9/15 16:17
  31. */
  32. public static function sendCode($params)
  33. {
  34. try {
  35. $scene = NoticeEnum::getSceneByTag($params['scene']);
  36. if (empty($scene)) {
  37. throw new \Exception('场景值异常');
  38. }
  39. $result = event('Notice', [
  40. 'scene_id' => $scene,
  41. 'params' => [
  42. 'user_id' => 0,
  43. 'mobile' => $params['mobile'],
  44. 'code' => mt_rand(1000, 9999),
  45. ]
  46. ]);
  47. return $result[0];
  48. } catch (\Exception $e) {
  49. self::$error = $e->getMessage();
  50. return false;
  51. }
  52. }
  53. }