| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-04-30
- // +—————————————————————————————————————————————————————————————————————
- session_start();
- class Api_Login extends PhalApi_Api {
- public function getRules() {
- return array(
- 'userLogin' => array(
- 'user_login' => array('name' => 'user_login', 'type' => 'string', 'desc' => '账号'),
- 'code' => array('name' => 'code', 'type' => 'string', 'require' => true, 'desc' => '验证码'),
- 'source' => array('name' => 'source', 'type' => 'string', 'desc' => '注册来源android/ios'),
- 'mobileid' => array('name' => 'mobileid', 'type' => 'string', 'desc' => '手机设备号'),
- ),
-
- 'getLoginCode' => array(
- 'country_code' => array('name' => 'country_code', 'type' => 'int','default'=>'86', 'require' => true, 'desc' => '国家代号'),
- 'mobile' => array('name' => 'mobile', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => '手机号'),
- 'time' => array('name' => 'time', 'type' => 'string', 'desc' => '时间戳'),
- 'sign' => array('name' => 'sign', 'type' => 'string', 'default'=>'', 'desc' => '签名'),
- ),
- 'getCountrys'=>array(
- 'field' => array('name' => 'field', 'type' => 'string', 'default'=>'', 'desc' => '搜索json串'),
- ),
- );
- }
-
- /**
- * 会员登录
- * @desc 用于用户登陆
- * @return int code 操作码,0表示成功
- * @return array info 用户信息
- * @return string info[0].id 用户ID
- * @return string info[0].user_nicename 昵称
- * @return string info[0].avatar 头像
- * @return string info[0].avatar_thumb 头像缩略图
- * @return string info[0].sex 性别
- * @return string info[0].signature 签名
- * @return string info[0].coin 用户余额
- * @return string info[0].login_type 注册类型
- * @return string info[0].province 省份
- * @return string info[0].city 城市
- * @return string info[0].birthday 生日
- * @return string info[0].token 用户Token
- * @return string msg 提示信息
- */
- public function userLogin() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $user_login=checkNull($this->user_login);
- $code=checkNull($this->code);
- $source=checkNull($this->source);
- $mobileid=checkNull($this->mobileid);
- if(!$user_login){
- $rs['code']=1001;
- $rs['msg']='请填写手机号';
- return $rs;
- }
- $ismobile=checkMobile($user_login);
- if(!$ismobile){
- $rs['code']=1001;
- $rs['msg']='请输入正确的手机号';
- return $rs;
- }
- if($code==''){
- $rs['code'] = 1001;
- $rs['msg'] = '请填写验证码';
- return $rs;
- }
- if($mobileid==''){
- $rs['code'] = 1001;
- $rs['msg'] = '缺少设备码';
- return $rs;
- }
- if(!$_SESSION['login_mobile']){
- $rs['code'] = 1001;
- $rs['msg'] = '请获取验证码';
- return $rs;
- }
- if($user_login!=$_SESSION['login_mobile']){
- $rs['code'] = 1001;
- $rs['msg'] = '手机号码错误';
- return $rs;
- }
- if($code!=$_SESSION['login_mobile_code']){
- $rs['code'] = 1001;
- $rs['msg'] = '验证码错误';
- return $rs;
- }
- $domain = new Domain_Login();
- $info = $domain->userLogin($user_login,$source,$mobileid);
- if($info==1001){
- $rs['code'] = 1001;
- $rs['msg'] = '同一设备同一IP下注册账号过多';
- return $rs;
- }
- if($info==1002){
- $rs['code'] = 1002;
- $rs['msg'] = '该账号已被禁用';
- return $rs;
- }
- if($info==1003){
- $rs['code'] = 1003;
- $rs['msg'] = '该账号已注销';
- return $rs;
- }
- if($info==1004){
- $rs['code'] = 1004;
- $rs['msg'] = '管理员账号无法登陆';
- return $rs;
- }
-
- $rs['info'][0] = $info;
-
-
-
- return $rs;
- }
-
- /**
- * 获取登录短信验证码
- * @desc 用于登录获取短信验证码
- * @return int code 操作码,0表示成功,2发送失败
- * @return array info
- * @return string msg 提示信息
- */
-
- public function getLoginCode() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $country_code = checkNull($this->country_code);
- $mobile = checkNull($this->mobile);
- $time=checkNull($this->time);
- $sign=checkNull($this->sign);
- if(!$mobile){
- $rs['code']=1001;
- $rs['msg']='请填写手机号';
- return $rs;
- }
- $configpri=getConfigPri();
- $code_switch=$configpri['code_switch'];
-
- $aly_sendcode_type=$configpri['aly_sendcode_type'];
- if($aly_sendcode_type==1){ //国内验证码
- if($country_code!=86){
- $rs['code']=1001;
- $rs['msg']='平台只允许选择中国大陆';
- return $rs;
- }
- $ismobile=checkMobile($mobile);
- if(!$ismobile){
- $rs['code']=1001;
- $rs['msg']='请输入正确的手机号';
- return $rs;
- }
- }else if($aly_sendcode_type==2){ //海外/港澳台 验证码
- if($country_code==86){
- $rs['code']=1001;
- $rs['msg']='平台只允许选择除中国大陆外的国家/地区';
- return $rs;
- }
- }
-
- $checkdata=array(
- 'mobile'=>$mobile,
- 'time'=>$time,
- );
-
- $issign=checkSign($checkdata,$sign);
- if(!$issign){
- $rs['code']=1001;
- $rs['msg']='签名错误';
- return $rs;
- }
- //验证手机号是否被禁用
- $status=checkMoblieCanCode($mobile);
- if($status==0){
- $rs['code']=1001;
- $rs['msg']='该账号已被禁用';
- return $rs;
- }
- if($_SESSION['country_code']==$country_code && $_SESSION['login_mobile']==$mobile && $_SESSION['login_mobile_expiretime']> time() ){
- $rs['code']=1002;
- $rs['msg']='验证码5分钟有效,请勿多次发送';
- return $rs;
- }
-
- $limit = ip_limit();
- if( $limit == 1){
- $rs['code']=1003;
- $rs['msg']='您已当日发送次数过多';
- return $rs;
- }
- $mobile_code = random(6,1);
-
- /* 发送验证码 */
- $result=sendCode($country_code,$mobile,$mobile_code);
- if($result['code']===0){
- $_SESSION['country_code'] = $country_code;
- $_SESSION['login_mobile'] = $mobile;
- $_SESSION['login_mobile_code'] = $mobile_code;
- $_SESSION['login_mobile_expiretime'] = time() +60*5;
- }else if($result['code']==667){
- $_SESSION['country_code'] = $country_code;
- $_SESSION['login_mobile'] = $mobile;
- $_SESSION['login_mobile_code'] = $result['msg'];
- $_SESSION['login_mobile_expiretime'] = time() +60*5;
-
- $rs['code']=$result['code'];
- $rs['msg']='验证码为:'.$result['msg'];
- return $rs;
- }else{
- $rs['code']=1002;
- $rs['msg']=$result['msg'];
- return $rs;
- }
-
- $rs['msg']="发送成功";
- return $rs;
- }
- /**
- * 获取国家列表
- * @desc 用于获取国家列表
- * string field 搜索内容
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string name 国家中文名称
- * @return string name_name 国家英文名称
- * @return string tel 国家区号
- * @return string msg 提示信息
- */
- public function getCountrys() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $field=checkNull($this->field);
-
- $key='getCountrys';
- $info=getcaches($key);
- if(!$info){
- $country=API_ROOT.'/../data/config/country.json';
- // 从文件中读取数据到PHP变量
- $json_string = file_get_contents($country);
- // 用参数true把JSON字符串强制转成PHP数组
- $data = json_decode($json_string, true);
- $info=$data['country']; //国家
-
- setcaches($key,$info);
- }
- if($field){
- $rs['info']=$this->country_searchs($field,$info);
- return $rs;
- }
-
- $rs['info']=$info;
- return $rs;
- }
- private function country_searchs($field,$data) {
- $arr=array();
- foreach($data as $k => $v){
-
- $lists=$v['lists'];
-
- foreach ($lists as $k => $v) {
-
- if(strstr($v['name'], $field) !== false){//英文搜索替换为:$v['name_en']
-
- array_push($arr, $v);
- }
- }
-
- }
- return $arr;
- }
- }
|