SmsAdmin.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\notification\sms;
  12. use app\controller\admin\AuthController;
  13. use app\services\message\sms\SmsAdminServices;
  14. use think\facade\App;
  15. /**
  16. * 短信账号
  17. * Class SmsAdmin
  18. * @package app\controller\admin\v1\sms
  19. */
  20. class SmsAdmin extends AuthController
  21. {
  22. /**
  23. * 构造方法
  24. * SmsAdmin constructor.
  25. * @param App $app
  26. * @param SmsAdminServices $services
  27. */
  28. public function __construct(App $app, SmsAdminServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 发送验证码
  35. * @return mixed
  36. */
  37. public function captcha()
  38. {
  39. if (!request()->isPost()) {
  40. return $this->fail('发送失败');
  41. }
  42. $phone = request()->param('phone');
  43. if (!trim($phone)) {
  44. return $this->fail('请填写手机号');
  45. }
  46. return $this->success($this->services->captcha($phone));
  47. }
  48. /**
  49. * 修改/注册短信平台账号
  50. */
  51. public function save()
  52. {
  53. [$account, $password, $phone, $code, $url, $sign] = $this->request->postMore([
  54. ['account', ''],
  55. ['password', ''],
  56. ['phone', ''],
  57. ['code', ''],
  58. ['url', ''],
  59. ['sign', ''],
  60. ], true);
  61. $signLen = mb_strlen(trim($sign));
  62. if (!strlen(trim($account))) return $this->fail('请填写账号');
  63. if (!strlen(trim($password))) return $this->fail('请填写密码');
  64. if (!$signLen) return $this->fail('请填写短信签名');
  65. if ($signLen > 8) return $this->fail('短信签名最长为8位');
  66. if (!strlen(trim($code))) return $this->fail('请填写验证码');
  67. if (!strlen(trim($url))) return $this->fail('请填写域名');
  68. $status = $this->services->register($account, $password, $url, $phone, $code, $sign);
  69. return $this->success('短信平台:' . $status['msg']);
  70. }
  71. }