Connectsms.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /*
  3. * 手机验证码
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  12. * 网站地址: https://www.valimart.net/
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Connectsms extends BaseMall {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/login.lang.php');
  22. }
  23. /**
  24. * 短信动态码
  25. */
  26. public function get_captcha() {
  27. header("Content-Type: text/html;charset=utf-8");
  28. $sms_mobile = input('param.sms_mobile');
  29. if (strlen($sms_mobile) == 11) {
  30. $log_type = input('param.type'); //短信类型:1为注册,2为登录,3为找回密码
  31. $member_model = model('member');
  32. $member = $member_model->getMemberInfo(array('member_mobile' => $sms_mobile));
  33. $sms_captcha = rand(100000, 999999);
  34. $log_msg = lang('ds_you_in').'' . date("Y-m-d");
  35. switch ($log_type) {
  36. case '1':
  37. if (config('ds_config.sms_register') != 1) {
  38. echo lang('system_obile_registration_function');
  39. exit;
  40. }
  41. if (!empty($member)) {
  42. //检查手机号是否已被注册
  43. echo lang('change_another_number');;
  44. exit;
  45. }
  46. $mailmt_code = 'register';
  47. break;
  48. case '2':
  49. if (config('ds_config.sms_login') != 1) {
  50. echo lang('enable_mobile_phone_login');
  51. exit;
  52. }
  53. if (empty($member)) {
  54. //检查手机号是否已绑定会员
  55. echo lang('check_correct_number');
  56. exit;
  57. }
  58. $mailmt_code = 'login';
  59. break;
  60. case '3':
  61. if (config('ds_config.sms_password') != 1) {
  62. echo lang('mobile_back_password');
  63. exit;
  64. }
  65. if (empty($member)) {
  66. //检查手机号是否已绑定会员
  67. echo lang('check_correct_number');
  68. exit;
  69. }
  70. $mailmt_code = 'reset_password';
  71. break;
  72. default:
  73. echo lang('param_error');
  74. exit;
  75. break;
  76. }
  77. $smslog_model = model('smslog');
  78. $mailtemplates_model = model('mailtemplates');
  79. $tpl_info = $mailtemplates_model->getTplInfo(array('mailmt_code' => $mailmt_code));
  80. $param = array();
  81. $param['code'] = $sms_captcha;
  82. $ten_param=array($sms_captcha);
  83. $message = ds_replace_text($tpl_info['mailmt_content'], $param);
  84. $smslog_param=array(
  85. 'ali_template_code'=>$tpl_info['ali_template_code'],
  86. 'ali_template_param'=>$param,
  87. 'ten_template_code'=>$tpl_info['ten_template_code'],
  88. 'ten_template_param'=>$ten_param,
  89. 'message'=>$message,
  90. );
  91. $result = $smslog_model->sendSms($sms_mobile,$smslog_param,$log_type,$sms_captcha,$member['member_id'],$member['member_name']);
  92. if($result['state']){
  93. session('sms_mobile', $sms_mobile);
  94. session('sms_captcha', $sms_captcha);
  95. echo 'true';
  96. //exit;
  97. }else{
  98. echo $result['message'];
  99. exit;
  100. }
  101. } else {
  102. echo lang('phone_length_incorrect');
  103. exit;
  104. }
  105. }
  106. /**
  107. * 验证注册动态码
  108. */
  109. public function check_captcha() {
  110. $state = lang('validation_fails');
  111. $phone = input('get.phone');
  112. $captcha = input('get.sms_captcha');
  113. if (strlen($phone) == 11 && strlen($captcha) == 6) {
  114. $state = 'true';
  115. $condition = array();
  116. $condition[] = array('smslog_phone','=',$phone);
  117. $condition[] = array('smslog_captcha','=',$captcha);
  118. $condition[] = array('smslog_type','=',1);
  119. $smslog_model = model('smslog');
  120. $sms_log = $smslog_model->getSmsInfo($condition);
  121. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  122. $state = lang('dynamic_code_expired');
  123. }
  124. }
  125. exit($state);
  126. }
  127. /**
  128. * 登录
  129. */
  130. public function login() {
  131. if(!config('ds_config.sms_login') && config('ds_config.captcha_status_login')==1 && !captcha_check(input('post.captcha_mobile'))){
  132. ds_json_encode(10001,lang('image_verification_code_error'));
  133. }
  134. if (request()->isPost()) {
  135. if (config('ds_config.sms_login') != 1) {
  136. ds_json_encode(10001,lang('enable_mobile_phone_login'));
  137. }
  138. $phone = input('post.sms_mobile');
  139. $captcha = input('post.sms_captcha');
  140. $condition = array();
  141. $condition[] = array('smslog_phone','=',$phone);
  142. $condition[] = array('smslog_captcha','=',$captcha);
  143. $condition[] = array('smslog_type','=',2);
  144. $smslog_model = model('smslog');
  145. $sms_log = $smslog_model->getSmsInfo($condition);
  146. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  147. ds_json_encode(10001,lang('dynamic_code_expired'));
  148. }
  149. $member_model = model('member');
  150. $member = $member_model->getMemberInfo(array('member_mobile' => $phone)); //检查手机号是否已被注册
  151. if (!empty($member)) {
  152. if (!$member['member_state']) {//1为启用 0 为禁用
  153. ds_json_encode(10001,lang('login_index_account_stop'));
  154. }
  155. $member_model->createSession($member); //自动登录
  156. $reload = input('param.ref_url');
  157. if (empty($reload)) {
  158. $reload = (string)url('Member/index');
  159. }
  160. ds_json_encode(10000,lang('login_index_login_success'), '','',false);
  161. }
  162. }
  163. }
  164. /**
  165. * 找回密码
  166. */
  167. public function find_password() {
  168. if (config('ds_config.sms_password') != 1) {
  169. ds_json_encode(10001,lang('mobile_back_password'));
  170. }
  171. $sms_mobile = trim(input('sms_mobile'));
  172. $sms_captcha = trim(input('sms_captcha'));
  173. $member_password = trim(input('member_password'));
  174. //判断验证码是否正确
  175. if ($sms_captcha != session('sms_captcha')) {
  176. ds_json_encode(10001,lang('login_index_wrong_checkcode'));
  177. }
  178. if ($sms_mobile != session('sms_mobile')) {
  179. ds_json_encode(10001,lang('receive_number_inconsistent'));
  180. }
  181. $condition = array();
  182. $condition[] = array('smslog_phone','=',$sms_mobile);
  183. $condition[] = array('smslog_captcha','=',$sms_captcha);
  184. $condition[] = array('smslog_type','=',3);
  185. $smslog_model = model('smslog');
  186. $sms_log = $smslog_model->getSmsInfo($condition);
  187. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  188. ds_json_encode(10001,lang('dynamic_code_expired'));
  189. }
  190. $member_model = model('member');
  191. $member = $member_model->getMemberInfo(array('member_mobile' => $sms_mobile)); //检查手机号是否已被注册
  192. if (!empty($member)) {
  193. if (!$member['member_state']) {//1为启用 0 为禁用
  194. ds_json_encode(10001, lang('login_index_account_stop'));
  195. }
  196. $member_model->editMember(array('member_id' => $member['member_id']), array('member_password' => md5($member_password)),$member['member_id']);
  197. $member_model->createSession($member); //自动登录
  198. ds_json_encode(10000,lang('password_changed_successfully'));
  199. }
  200. }
  201. }