Sms.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\TencentCloudService;
  4. use app\common\controller\Api;
  5. class Sms extends Api
  6. {
  7. protected $noNeedLogin = "*";
  8. public function send($mobile = null, $event = null)
  9. {
  10. if (!preg_match("/^1[23456789]\d{9}$/", $mobile))
  11. $this->error("手机号码错误!");
  12. if (!in_array($event, [
  13. "bind_mobile",//用户绑定手机
  14. "user_login",// 用户登录
  15. "user_cancel", // 用户注销账户
  16. "massager_login",//助教登录
  17. "agency_login", // 代理商登录
  18. "register", // 用户注册
  19. "reset_pwd", // 用户修改密码
  20. "massager_rest_pwd", // 助教修改密码
  21. "massager_modify_mobile", // 修改电话
  22. "massager_close_account", // 注销账户
  23. ]))
  24. $this->error("发送类型异常");
  25. $code = rand(1000, 9999);
  26. $valid = TencentCloudService::tencent_cloud_sms_send("2280835", $mobile, [$code]);
  27. if ($valid->code()) {
  28. \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => request()->ip(), 'createtime' => time()]);
  29. $this->success(true);
  30. }
  31. $this->error($valid->msg());
  32. }
  33. // public function test_vms_send()
  34. // {
  35. // $valid = TencentCloudService::tencent_cloud_vms_send("15574920253", "1477072", "OAP" . time());
  36. // dump($valid);
  37. // }
  38. }