Index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace addons\alisms\controller;
  3. use think\addons\Controller;
  4. /**
  5. * 阿里短信
  6. */
  7. class Index extends Controller
  8. {
  9. protected $model = null;
  10. public function _initialize()
  11. {
  12. if (!\app\admin\library\Auth::instance()->id) {
  13. $this->error('暂无权限浏览');
  14. }
  15. parent::_initialize();
  16. }
  17. public function index()
  18. {
  19. return $this->view->fetch();
  20. }
  21. public function send()
  22. {
  23. $config = get_addon_config('alisms');
  24. $mobile = $this->request->post('mobile');
  25. $template = $this->request->post('template');
  26. $sign = $this->request->post('sign');
  27. if (!$mobile || !$template) {
  28. $this->error('手机号、模板ID不能为空');
  29. }
  30. $sign = $sign ? $sign : $config['sign'];
  31. $param = (array)json_decode($this->request->post('param', '', 'trim'));
  32. $alisms = new \addons\alisms\library\Alisms();
  33. $ret = $alisms->mobile($mobile)
  34. ->template($template)
  35. ->sign($sign)
  36. ->param($param)
  37. ->send();
  38. if ($ret) {
  39. $this->success("发送成功");
  40. } else {
  41. $this->error("发送失败!失败原因:" . $alisms->getError());
  42. }
  43. }
  44. }