VerifyController.class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Admin\Controller;
  3. class VerifyController extends \Think\Controller
  4. {
  5. public function code()
  6. {
  7. $config['useNoise'] = true;
  8. $config['length'] = 4;
  9. $config['codeSet'] = '1234567890';
  10. $verify = new \Think\Verify($config);
  11. $verify->entry('.cn');
  12. }
  13. public function mobile()
  14. {
  15. if (IS_POST) {
  16. if (check($_POST['mobile'], 'mobile')) {
  17. $mobile = $_POST['mobile'];
  18. }
  19. else {
  20. $this->error('手机号码格式错误!');
  21. }
  22. if (empty($_POST['type'])) {
  23. $this->error('短信模版名称错误!');
  24. }
  25. $Configmobile = D('ConfigMobile')->where(array('id' => $_POST['type']))->find();
  26. if ($Configmobile) {
  27. $code = rand(111111, 999999);
  28. session('mobilecode', $code);
  29. $content = str_replace('[url]', $code, $Configmobile['content']);
  30. }
  31. else {
  32. $this->error('短信模版错误!');
  33. }
  34. C('MOBILE_URL', $_POST['mobile_url']);
  35. C('MOBILE_USER', $_POST['mobile_user']);
  36. C('MOBILE_PASS', $_POST['mobile_pass']);
  37. }
  38. if (0 < smssend($mobile, $content)) {
  39. $this->success('短信发送成功!');
  40. }
  41. else {
  42. $this->error('短信发送失败!');
  43. }
  44. }
  45. public function email()
  46. {
  47. if (IS_POST) {
  48. if (check($_POST['email'], 'email')) {
  49. $email = $_POST['email'];
  50. }
  51. else {
  52. $this->error('邮件格式错误!');
  53. }
  54. if (empty($_POST['type'])) {
  55. $this->error('邮件模版名称错误!');
  56. }
  57. $Configemail = D('ConfigEmail')->where(array('id' => $_POST['type']))->find();
  58. if ($Configemail) {
  59. $code = rand(111111, 999999);
  60. session('emailcode', $code);
  61. $content = str_replace('[url]', $code, $Configemail['content']);
  62. $title = $Configemail['title'];
  63. }
  64. else {
  65. $this->error('邮件模版错误!');
  66. }
  67. C('SMTP_HOST', $_POST['smtp_host']);
  68. C('SMTP_PORT', $_POST['smtp_port']);
  69. C('SMTP_USER', $_POST['smtp_user']);
  70. C('SMTP_PASS', $_POST['smtp_pass']);
  71. C('SMTP_NAME', $_POST['smtp_name']);
  72. C('SMTP_EMAIL', $_POST['smtp_email']);
  73. }
  74. if (send_email($email, $title, $content)) {
  75. $this->success('邮件发送成功!');
  76. }
  77. else {
  78. $this->error('邮件发送失败!');
  79. }
  80. }
  81. }
  82. ?>