Ems.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. //
  3. //namespace app\api\controller;
  4. //
  5. //use app\common\controller\Api;
  6. //use app\common\library\Ems as Emslib;
  7. //use app\common\model\User;
  8. //
  9. ///**
  10. // * 邮箱验证码接口
  11. // */
  12. //class Ems extends Api
  13. //{
  14. // protected $noNeedLogin = '*';
  15. // protected $noNeedRight = '*';
  16. //
  17. // public function _initialize()
  18. // {
  19. // parent::_initialize();
  20. // \think\Hook::add('ems_send', function ($params) {
  21. // $obj = \app\common\library\Email::instance();
  22. // $result = $obj
  23. // ->to($params->email)
  24. // ->subject('验证码')
  25. // ->message("你的验证码是:" . $params->code)
  26. // ->send();
  27. // return $result;
  28. // });
  29. // }
  30. //
  31. // /**
  32. // * 发送验证码
  33. // *
  34. // * @param string $email 邮箱
  35. // * @param string $event 事件名称
  36. // */
  37. // public function send()
  38. // {
  39. // $email = $this->request->request("email");
  40. // $event = $this->request->request("event");
  41. // $event = $event ? $event : 'register';
  42. //
  43. // $last = Emslib::get($email, $event);
  44. // if ($last && time() - $last['createtime'] < 60) {
  45. // $this->error(__('发送频繁'));
  46. // }
  47. // if ($event) {
  48. // $userinfo = User::getByEmail($email);
  49. // if ($event == 'register' && $userinfo) {
  50. // //已被注册
  51. // $this->error(__('已被注册'));
  52. // } elseif (in_array($event, ['changeemail']) && $userinfo) {
  53. // //被占用
  54. // $this->error(__('已被占用'));
  55. // } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
  56. // //未注册
  57. // $this->error(__('未注册'));
  58. // }
  59. // }
  60. // $ret = Emslib::send($email, null, $event);
  61. // if ($ret) {
  62. // $this->success(__('发送成功'));
  63. // } else {
  64. // $this->error(__('发送失败'));
  65. // }
  66. // }
  67. //
  68. // /**
  69. // * 检测验证码
  70. // *
  71. // * @param string $email 邮箱
  72. // * @param string $event 事件名称
  73. // * @param string $captcha 验证码
  74. // */
  75. // public function check()
  76. // {
  77. // $email = $this->request->request("email");
  78. // $event = $this->request->request("event");
  79. // $event = $event ? $event : 'register';
  80. // $captcha = $this->request->request("captcha");
  81. //
  82. // if ($event) {
  83. // $userinfo = User::getByEmail($email);
  84. // if ($event == 'register' && $userinfo) {
  85. // //已被注册
  86. // $this->error(__('已被注册'));
  87. // } elseif (in_array($event, ['changeemail']) && $userinfo) {
  88. // //被占用
  89. // $this->error(__('已被占用'));
  90. // } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
  91. // //未注册
  92. // $this->error(__('未注册'));
  93. // }
  94. // }
  95. // $ret = Emslib::check($email, $captcha, $event);
  96. // if ($ret) {
  97. // $this->success(__('成功'));
  98. // } else {
  99. // $this->error(__('验证码不正确'));
  100. // }
  101. // }
  102. //}