Connect.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 第三方登录控制器
  14. */
  15. class Connect extends MobileMall
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/login.lang.php');
  21. }
  22. /**
  23. * @api {POST} api/Connect/get_sms_captcha 短信动态码
  24. * @apiVersion 1.0.0
  25. * @apiGroup Connect
  26. *
  27. * @apiParam {String} phone 手机号
  28. * @apiParam {String} type 短信类型 1为注册,2为登录,3为找回密码
  29. *
  30. * @apiSuccess {String} code 返回码,10000为成功
  31. * @apiSuccess {String} message 返回消息
  32. * @apiSuccess {Object} result 返回数据
  33. * @apiSuccess {Int} result.sms_time 发送倒计时
  34. */
  35. public function get_sms_captcha(){
  36. $state = lang('send_fail');
  37. $sms_mobile = input('param.phone');
  38. if (strlen($sms_mobile) == 11){
  39. $log_type = input('param.type');//短信类型:1为注册,2为登录,3为找回密码
  40. $state = 'true';
  41. $member_model = model('member');
  42. $member = $member_model->getMemberInfo(array('member_mobile' => $sms_mobile));
  43. $sms_captcha = rand(100000, 999999);
  44. switch ($log_type) {
  45. case '1':
  46. if (config('ds_config.sms_register') != 1) {
  47. $state = lang('system_obile_registration_function');
  48. }
  49. if (!empty($member)) {//检查手机号是否已被注册
  50. $state = '当前手机号已被注册,请更换其他号码。';
  51. }
  52. $mailmt_code = 'register';
  53. break;
  54. case '2':
  55. if (config('ds_config.sms_login') != 1) {
  56. $state = lang('enable_mobile_phone_login');
  57. }
  58. if (empty($member)) {//检查手机号是否已绑定会员
  59. $state = lang('check_correct_number');
  60. }
  61. $mailmt_code = 'login';
  62. break;
  63. case '3':
  64. if (config('ds_config.sms_password') != 1) {
  65. $state = lang('mobile_back_password');
  66. }
  67. if (empty($member)) {//检查手机号是否已绑定会员
  68. $state = lang('check_correct_number');
  69. }
  70. $mailmt_code = 'reset_password';
  71. break;
  72. default:
  73. $state = lang('param_error');
  74. break;
  75. }
  76. if ($state == 'true') {
  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($param['code']);
  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. ds_json_encode(10000, lang('send_success'),array('sms_time' => 60));
  94. exit;
  95. } else {
  96. $state = $result['message'];
  97. }
  98. }
  99. }
  100. ds_json_encode(10001,$state);
  101. }
  102. /**
  103. * 验证注册动态码
  104. */
  105. public function check_sms_captcha(){
  106. $state = lang('validation_fails');
  107. $phone = input('param.phone');
  108. $captcha = input('param.captcha');
  109. $log_type=input('param.type');
  110. if (strlen($phone) == 11){
  111. $state = 'true';
  112. $condition = array();
  113. $condition[] = array('smslog_phone','=',$phone);
  114. $condition[] = array('smslog_captcha','=',$captcha);
  115. $condition[] = array('smslog_type','=',$log_type);
  116. $smslog_model = model('smslog');
  117. $sms_log = $smslog_model->getSmsInfo($condition);
  118. if(empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP-1800)) {//半小时内进行验证为有效
  119. $state = lang('dynamic_code_expired');
  120. ds_json_encode(10001,$state);
  121. }
  122. ds_json_encode(10000, '',$state);
  123. }
  124. ds_json_encode(10001,$state);
  125. }
  126. /**
  127. * @api {POST} api/Connect/sms_register 手机注册
  128. * @apiVersion 1.0.0
  129. * @apiGroup Connect
  130. *
  131. * @apiParam {String} phone 手机号
  132. * @apiParam {String} captcha 验证码
  133. * @apiParam {String} password 密码
  134. * @apiParam {Int} inviter_id 推荐人id
  135. * @apiParam {String} client 客户端类型
  136. *
  137. * @apiSuccess {String} code 返回码,10000为成功
  138. * @apiSuccess {String} message 返回消息
  139. * @apiSuccess {Object} result 返回数据
  140. * @apiSuccess {Int} result.state 注册状态 1成功0失败
  141. * @apiSuccess {String} result.username 用户名称
  142. * @apiSuccess {String} result.key 用户token
  143. * @apiSuccess {Object} result.info 用户信息
  144. * @apiSuccess {Int} result.info.member_id 用户ID
  145. * @apiSuccess {Object} result.info.member_name 用户名称
  146. * @apiSuccess {Object} result.info.member_truename 真实姓名
  147. * @apiSuccess {Object} result.info.member_avatar 头像
  148. * @apiSuccess {Object} result.info.member_points 积分
  149. * @apiSuccess {Object} result.info.member_email 邮箱
  150. * @apiSuccess {Object} result.info.member_mobile 手机号
  151. * @apiSuccess {Object} result.info.member_qq QQ
  152. * @apiSuccess {Object} result.info.member_ww 旺旺
  153. */
  154. public function sms_register(){
  155. if(config('ds_config.sms_register')!=1){
  156. ds_json_encode(10001,lang('login_register_cancel'));
  157. }
  158. $phone = input('post.phone');
  159. $captcha = input('post.captcha');
  160. $password = input('post.password');
  161. $client = input('post.client');
  162. $inviter_id = intval(input('post.inviter_id'));
  163. $logic_connect_api = model('connectapi','logic');
  164. $state_data = $logic_connect_api->smsRegister($phone, $captcha, $password, $client,$inviter_id);
  165. if($state_data['state']=='1'){
  166. $state_data['info'] = $this->getMemberUser($state_data['info']);
  167. ds_json_encode(10000, '',$state_data);
  168. } else {
  169. ds_json_encode(10001,$state_data['msg']);
  170. }
  171. }
  172. /**
  173. * 手机验证码登录
  174. */
  175. public function sms_login()
  176. {
  177. $member_mobile = input('post.usermobile');
  178. $mobilecode = input('post.mobilecode');
  179. $client=input('post.client');
  180. if(empty($member_mobile) || empty($mobilecode)){
  181. ds_json_encode(10001,lang('param_error'));
  182. }
  183. if (config('ds_config.sms_login') != 1) {
  184. ds_json_encode(10001,lang('enable_mobile_phone_login'));
  185. }
  186. $condition = array();
  187. $condition[] = array('smslog_phone','=',$member_mobile);
  188. $condition[] = array('smslog_captcha','=',$mobilecode);
  189. $condition[] = array('smslog_type','=',2);
  190. $smslog_model = model('smslog');
  191. $sms_log = $smslog_model->getSmsInfo($condition);
  192. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  193. ds_json_encode(10001,lang('dynamic_code_expired'));
  194. }
  195. $member_model = model('member');
  196. $member = $member_model->getMemberInfo(array('member_mobile' => $member_mobile)); //获取当前手机号的用户信息
  197. if (!empty($member)) {
  198. if (!$member['member_state']) {//1为启用 0 为禁用
  199. ds_json_encode(10001, lang('login_index_account_stop'));
  200. }
  201. $token = $member_model->getBuyerToken($member['member_id'], $member['member_name'], $client);
  202. if($token) {
  203. $result = array();
  204. $result['token'] = $token;
  205. $result['info'] = $this->getMemberUser($member);
  206. //是否有卖家账户
  207. $seller_model = model('seller');
  208. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member['member_id']));
  209. if($seller_info){
  210. $token = Sellerlogin::_get_seller_token($seller_info['seller_id'], $seller_info['seller_name'], $client);
  211. if(!$token){
  212. ds_json_encode(10001,lang('login_fail'));
  213. }
  214. //读取店铺信息
  215. $store_model = model('store');
  216. $store_info = $store_model->getStoreInfoByID($seller_info['store_id']);
  217. $result['seller_token'] = $token;
  218. $result['seller_info'] = $this->getSellerUser($seller_info,$store_info);
  219. $result['info']['store_id']=$store_info['store_id'];
  220. }
  221. ds_json_encode(10000, '',$result);
  222. }else{
  223. ds_json_encode(10001,lang('param_error'));
  224. }
  225. }else{
  226. ds_json_encode(10001,lang('mobile_not_exist'));
  227. }
  228. }
  229. /**
  230. * @api {POST} api/Connect/find_password 手机找回密码
  231. * @apiVersion 1.0.0
  232. * @apiGroup Connect
  233. *
  234. * @apiHeader {String} X-DS-KEY 用户授权token
  235. *
  236. * @apiParam {String} phone 手机号
  237. * @apiParam {String} captcha 验证码
  238. * @apiParam {String} password 密码
  239. * @apiParam {String} client 用户端 wap手机端
  240. *
  241. * @apiSuccess {String} code 返回码,10000为成功
  242. * @apiSuccess {String} message 返回消息
  243. * @apiSuccess {Object} result 返回数据
  244. * @apiSuccess {Int} result.state 找回密码状态 1成功0失败
  245. * @apiSuccess {String} result.username 用户名称
  246. * @apiSuccess {String} result.key 用户token
  247. * @apiSuccess {Int} result.info.member_id 用户ID
  248. * @apiSuccess {String} result.info.member_name 用户名称
  249. * @apiSuccess {String} result.info.member_truename 真实姓名
  250. * @apiSuccess {String} result.info.member_avatar 头像
  251. * @apiSuccess {String} result.info.member_points 积分
  252. * @apiSuccess {String} result.info.member_email 邮箱
  253. * @apiSuccess {String} result.info.member_mobile 手机号
  254. * @apiSuccess {String} result.info.member_qq QQ
  255. * @apiSuccess {String} result.info.member_ww 旺旺
  256. */
  257. public function find_password(){
  258. $phone = input('post.phone');
  259. $captcha = input('post.captcha');
  260. $password = input('post.password');
  261. $client = input('post.client');
  262. $logic_connect_api = model('connectapi','logic');
  263. $state_data = $logic_connect_api->smsPassword($phone, $captcha, $password, $client);
  264. if($state_data['state']){
  265. unset($state_data['state']);
  266. unset($state_data['msg']);
  267. $state_data['info']=$this->getMemberUser($state_data['info']);
  268. ds_json_encode(10000, '',$state_data);
  269. } else {
  270. ds_json_encode(10001,$state_data['msg']);
  271. }
  272. }
  273. /**
  274. * 登录开关状态
  275. */
  276. public function get_state() {
  277. $logic_connect_api = model('connectapi','logic');
  278. $state_array = $logic_connect_api->getStateInfo();
  279. $key = input('param.t');
  280. if(trim($key) != '' && array_key_exists($key,$state_array)){
  281. ds_json_encode(10000, '',$state_array[$key]);
  282. } else {
  283. ds_json_encode(10001,lang('param_error'));
  284. }
  285. }
  286. }