Connect.php 13 KB

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