verifycode.ctrl.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('setting');
  8. load()->model('utility');
  9. $dos = array('send_code', 'check_smscode');
  10. $do = in_array($do, $dos) ? $do : 'send_code';
  11. $custom_sign = safe_gpc_string($_GPC['custom_sign']);
  12. $_W['uniacid'] = intval($_GPC['uniacid']);
  13. if (empty($_W['uniacid'])) {
  14. $uniacid_arr = array(
  15. 'name' => '短信验证码',
  16. );
  17. } else {
  18. $uniacid_arr = pdo_fetch('SELECT * FROM ' . tablename('uni_account') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  19. if(empty($uniacid_arr)) {
  20. iajax(-1, '非法访问');
  21. }
  22. }
  23. $receiver = trim($_GPC['receiver']);
  24. if(empty($receiver)){
  25. iajax(-1, '请输入邮箱或手机号');
  26. } elseif(preg_match(REGULAR_MOBILE, $receiver)){
  27. $receiver_type = 'mobile';
  28. } elseif(preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $receiver)) {
  29. $receiver_type = 'email';
  30. } else {
  31. iajax(-1, '您输入的邮箱或手机号格式错误');
  32. }
  33. pdo_delete('uni_verifycode', array('createtime <' => TIMESTAMP - 1800));
  34. if ($do == 'check_smscode') {
  35. $smscode = intval($_GPC['smscode']);
  36. $verify_res = utility_smscode_verify(0, $receiver, $smscode);
  37. if (is_error($verify_res)) {
  38. iajax($verify_res['errno'], $verify_res['message']);
  39. }
  40. }
  41. if ($do == 'send_code') {
  42. $verifycode_table = table('uni_verifycode');
  43. $row = $verifycode_table->getByReceiverVerifycode($_W['uniacid'], $receiver, '');
  44. $record = array();
  45. $code = random(6, true);
  46. if(!empty($row)) {
  47. $imagecode = intval($_GPC['imagecode']);
  48. $failed_count = table('uni_verifycode')->getFailedCountByReceiver($receiver);
  49. if ($failed_count >= 3) {
  50. if (empty($imagecode)) {
  51. iajax(-3, '请输入图形验证码!');
  52. }
  53. if (!checkcaptcha($imagecode)) {
  54. iajax(-1, '图形验证码错误!');
  55. }
  56. }
  57. if($row['total'] >= 5) {
  58. iajax(-1, '您的操作过于频繁,请稍后再试');
  59. }
  60. $record['total'] = $row['total'] + 1;
  61. } else {
  62. $record['uniacid'] = $_W['uniacid'];
  63. $record['receiver'] = $receiver;
  64. $record['total'] = 1;
  65. }
  66. $record['verifycode'] = $code;
  67. $record['createtime'] = TIMESTAMP;
  68. if(!empty($row)) {
  69. pdo_update('uni_verifycode', $record, array('id' => $row['id']));
  70. } else {
  71. pdo_insert('uni_verifycode', $record);
  72. }
  73. if($receiver_type == 'email') {
  74. load()->func('communication');
  75. $content = "您的邮箱验证码为: {$code} 您正在使用{$uniacid_arr['name']}相关功能, 需要你进行身份确认.";
  76. $result = ihttp_email($receiver, "{$uniacid_arr['name']}身份确认验证码", $content);
  77. } else {
  78. load()->model('cloud');
  79. $r = cloud_prepare();
  80. if(is_error($r)) {
  81. iajax(-1, $r['message']);
  82. }
  83. $setting = uni_setting($_W['uniacid'], 'notify');
  84. $content = "您的短信验证码为: {$code} 您正在使用{$uniacid_arr['name']}相关功能, 需要你进行身份确认";
  85. $result = cloud_sms_send($receiver, $content, array(), $custom_sign);
  86. /* $postdata = array('verify_code' => $code, 'module' => $uniacid_arr['name']);
  87. $result = cloud_sms_send($receiver, '800002', $postdata, $custom_sign);
  88. */
  89. }
  90. if (is_error($result)) {
  91. iajax(-1, $result['message']);
  92. }
  93. iajax(0, '短信发送成功!');
  94. }