Connectsms.php 9.0 KB

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