Smsconfig.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 听雨 < 389625819@qq.com >
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\admin\controller\base\Permissions;
  13. use think\Db;
  14. class Smsconfig extends Permissions
  15. {
  16. public function index()
  17. {
  18. $data = Db::name('smsconfig')->where('sms', 'sms')->find();
  19. $this->assign('data', $data);
  20. $grouptabs = (new \app\common\model\ConfigTab())->order('sort desc')->select();
  21. $this->assign('tabs', $grouptabs);
  22. return $this->fetch();
  23. }
  24. public function publish()
  25. {
  26. if ($this->request->isPost()) {
  27. $post = $this->request->post();
  28. $validate = new \think\Validate([
  29. ['appkey', 'require', 'AppKey不能为空'],
  30. ['secretkey', 'require', 'SecretKey不能为空'],
  31. ['name', 'require', '短信签名不能为空'],
  32. ['code', 'require', '短信模板ID不能为空'],
  33. ]);
  34. if (!$validate->check($post)) {
  35. $this->error('提交失败:' . $validate->getError());
  36. }
  37. //$post['content'] = htmlentities($post['content']);
  38. if (false == Db::name('smsconfig')->where('sms', 'sms')->update($post)) {
  39. $this->error('提交失败');
  40. } else {
  41. $this->success('提交成功', 'admin/smsconfig/index');
  42. }
  43. } else {
  44. $this->error('非法请求');
  45. }
  46. }
  47. public function smsto()
  48. {
  49. if ($this->request->isPost()) {
  50. $post = $this->request->post();
  51. $validate = new \think\Validate([
  52. ['phone', 'require|length:11,11|number', '手机号码不能为空|手机号码格式不正确|手机号码格式不正确'],
  53. ]);
  54. if (!$validate->check($post)) {
  55. $this->error('提交失败:' . $validate->getError());
  56. }
  57. $phone = (string)$post['phone'];
  58. $param = '{"name":"Tplay用户"}';
  59. $smsto = SendSms($param, $phone);
  60. if (!empty($smsto)) {
  61. $this->error('发送失败');
  62. } else {
  63. $this->success('短信发送成功');
  64. }
  65. } else {
  66. return $this->fetch();
  67. }
  68. }
  69. }