getInfo(['account' => $data['account'], 'password' => $data['password']]); if (empty($info)) { return $this->return_code[20001]; } else { if ($info['start_time'] > time() || $info['end_time'] < time()) { return $this->return_code[20002]; } elseif ($info['status'] == 2) { return $this->return_code[20003]; } else { $res = $this->return_code[200]; $res['data'] = []; $res['data']['access_token'] = $this->_randVar(64,6); $res['data']['expires_in'] = 7200; $company_info = $AuthCompanyModel->getInfo(['company_code'=>$info['company_code']]); $insert['token'] = $res['data']['access_token']; $insert['start_time'] = time(); $insert['end_time'] = time()+7200; $insert['company_code'] = $info['company_code']; $insert['status'] = 1; $insert['db_json'] = $company_info['db_json']; $insert['sms_json'] = $company_info['sms_json']; //$TokenModel->save(['status'=>2],['company_code'=>$info['company_code']]); $TokenModel->insert($insert); return $res; } } } private function _randVar($length = 0, $type = 0) { $range = array( 0 => '0123456789', 1 => 'abcdefghijklmnopqrstuvwxyz', 2 => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 3 => '0123456789abcdefghijklmnopqrstuvwxyz', 4 => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', 5 => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 6 => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 7 => '3456789abcdefghijkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY'); if (false === array_key_exists($type, $range)) { $type = 6; } $character = ''; $maxLength = strlen($range[$type]) - 1; for ($i = 0; $i < $length; ++$i) { $character .= $range[$type][mt_rand(0, $maxLength)]; } return $character; } }