| | |
| | | |
| | | namespace app\admin\controller; |
| | | |
| | | use app\admin\util\Opadmin; |
| | | use think\Exception; |
| | | use think\facade\Db; |
| | | use think\facade\View; |
| | | use think\facade\Request; |
| | |
| | | use think\captcha\facade\Captcha; |
| | | use app\BaseController; |
| | | |
| | | class Login extends BaseController |
| | | { |
| | | public function index() |
| | | { |
| | | class Login extends BaseController { |
| | | public function index() { |
| | | header('Content-Type:text/html;charset=utf-8'); |
| | | $Opadmin = new \app\admin\util\Opadmin(); |
| | | $Opadmin = new Opadmin(); |
| | | if ($Opadmin->islogin()) { |
| | | $this->redirect(url('/admin/')->build()); |
| | | } |
| | | return View::fetch(); |
| | | } |
| | | public function login() |
| | | { |
| | | if (request()->isPost()) { |
| | | $Opadmin = new \app\admin\util\Opadmin(Request::post('username'), Request::post('password')); //////企业账号///////////// |
| | | $returnmsg = $Opadmin->login(); |
| | | if ($returnmsg['code'] == 400) { |
| | | return $returnmsg; |
| | | } elseif ($returnmsg['code'] == 200) { |
| | | |
| | | /** |
| | | * 登录 |
| | | * @return bool|array |
| | | */ |
| | | public function login(): bool|array { |
| | | try { |
| | | if (!request()->isPost()) { |
| | | throw new Exception("请求方式错误!"); |
| | | } |
| | | $Opadmin = new Opadmin(Request::post('username'), Request::post('password')); //////企业账号///////////// |
| | | |
| | | $result = $Opadmin->login(); |
| | | if ($result['code'] == 400) { |
| | | throw new Exception($result['message'], $result['code']); |
| | | } |
| | | if ($result['code'] == 200) { |
| | | $backurl = Request::post('backurl'); |
| | | if (empty($backurl)) { |
| | | $returnmsg['url'] = url('/admin/index/index')->build(); |
| | | $result['url'] = url('/admin/index/index')->build(); |
| | | } else { |
| | | $returnmsg['url'] = $backurl; |
| | | $result['url'] = $backurl; |
| | | } |
| | | return $returnmsg; |
| | | } |
| | | } else { |
| | | $d['code'] = 0; |
| | | $d['des'] = '参数有误!'; |
| | | return $d; |
| | | } catch (Exception $exc) { |
| | | $result = [ |
| | | 'code' => $exc->getCode(), |
| | | 'message' => $exc->getMessage(), |
| | | ]; |
| | | } |
| | | return $result; |
| | | } |
| | | |
| | | public function logout() |
| | | { |
| | | $Opadmin = new \app\admin\util\Opadmin(); |
| | | |
| | | public function logout() { |
| | | $Opadmin = new Opadmin(); |
| | | $Opadmin->loginout(); |
| | | $this->redirect(url('/admin/login/index')->build()); |
| | | } |
| | | |
| | | |
| | | public function captcha() |
| | | { |
| | | |
| | | |
| | | public function captcha() { |
| | | return Captcha::create(); |
| | | } |
| | | |
| | | public function captchaCheck() |
| | | { |
| | | |
| | | public function captchaCheck() { |
| | | if (!Request::isPost()) { |
| | | return $this->errorResponse(lang('request_method_incorrect')); |
| | | } |
| | | $code = trim(Request::post('captcha')); |
| | | |
| | | |
| | | // 检测输入的验证码是否正确,$value为用户输入的验证码字符串 |
| | | $captcha = new Captcha(); |
| | | if (!$captcha->check($code)) { |
| | |
| | | } |
| | | return $this->successResponse(lang('captcha_success')); |
| | | } |
| | | |
| | | public function captchaCheckAndMsg() |
| | | { |
| | | |
| | | public function captchaCheckAndMsg() { |
| | | if (!Request::isPost()) { |
| | | return $this->errorResponse(lang('request_method_incorrect')); |
| | | } |
| | | |
| | | |
| | | try { |
| | | $code = trim(Request::post('captcha')); |
| | | $code = trim(Request::post('captcha')); |
| | | $phone = trim(Request::post('phone')); |
| | | // echo $phone; |
| | | // exit(); |
| | | |
| | | |
| | | // 检测输入的验证码是否正确,$value为用户输入的验证码字符串 |
| | | // $captcha = new Captcha(); |
| | | if (!captcha_check($code)) { |
| | |
| | | throw new \Exception(lang('captcha_is_incorrect'), 400); |
| | | // return $this->errorResponse(lang('captcha_is_incorrect')); |
| | | } |
| | | |
| | | |
| | | //查询120秒内是否已有发送 |
| | | $localTime = time(); |
| | | $where = [ |
| | | $where = [ |
| | | ['phone', '=', $phone], |
| | | ['add_time', '>=', $localTime - 120], |
| | | ['type', '=', 1], |
| | | ]; |
| | | $info = Db::name('phone_msg')->field('*')->where($where)->find(); |
| | | $info = Db::name('phone_msg')->field('*')->where($where)->find(); |
| | | if ($info) { |
| | | throw new \Exception("二分钟内,只能发送一次", 400); |
| | | } |
| | | $phoneCode = randomkeys(4, 'regCode'); |
| | | |
| | | |
| | | $cred = new \TencentCloud\Common\Credential(Config::get('qcloud.Qcloud.SecretId'), Config::get('qcloud.Qcloud.SecretKey')); |
| | | |
| | | |
| | | // 实例化一个http选项,可选的,没有特殊需求可以跳过 |
| | | $httpProfile = new \TencentCloud\Common\Profile\HttpProfile(); |
| | | // 配置代理(无需要直接忽略) |
| | | // $httpProfile->setProxy("https://ip:port"); |
| | | $httpProfile->setReqMethod("GET"); // get请求(默认为post请求) |
| | | $httpProfile->setReqTimeout(10); // 请求超时时间,单位为秒(默认60秒) |
| | | $httpProfile->setReqMethod("GET"); // get请求(默认为post请求) |
| | | $httpProfile->setReqTimeout(10); // 请求超时时间,单位为秒(默认60秒) |
| | | $httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入) |
| | | // 实例化一个client选项,可选的,没有特殊需求可以跳过 |
| | | $clientProfile = new \TencentCloud\Common\Profile\ClientProfile(); |
| | |
| | | // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看 |
| | | $req->TemplateId = Config::get('qcloud.Qcloud.TemplateId'); |
| | | /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空*/ |
| | | $req->TemplateParamSet = array($phoneCode, '2'); |
| | | $req->TemplateParamSet = [$phoneCode, '2']; |
| | | /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] |
| | | * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/ |
| | | $req->PhoneNumberSet = array("+86" . $phone); |
| | | $req->PhoneNumberSet = ["+86" . $phone]; |
| | | /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */ |
| | | $req->SessionContext = ""; |
| | | /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */ |
| | |
| | | // print_r($resp->TotalCount); |
| | | // print_r($resp->toJsonString()); |
| | | // exit(); |
| | | |
| | | |
| | | $newdata = [ |
| | | 'phone' => $phone, |
| | | 'code' => $phoneCode, |
| | | 'type' => 1, |
| | | 'is_use' => 0, |
| | | 'phone' => $phone, |
| | | 'code' => $phoneCode, |
| | | 'type' => 1, |
| | | 'is_use' => 0, |
| | | 'add_time' => $localTime, |
| | | ]; |
| | | $id = Db::name('phone_msg')->insertGetId($newdata); |
| | | $result = [ |
| | | 'id' => $id, |
| | | $id = Db::name('phone_msg')->insertGetId($newdata); |
| | | $result = [ |
| | | 'id' => $id, |
| | | // 'phonecode' => $phoneCode, |
| | | 'msg' => 'ok', |
| | | ]; |
| | |
| | | return $this->errorResponse($e->getMessage()); |
| | | } |
| | | } |
| | | |
| | | public function getLanguageList() |
| | | { |
| | | |
| | | public function getLanguageList() { |
| | | //////// |
| | | try { |
| | | if (!Request::isPost()) { |
| | | throw new Exception(lang('request_method_incorrect')); |
| | | } |
| | | $condition['is_show'] = 1; |
| | | $order = 'order_id asc,id asc'; |
| | | $list = Db::name('language')->field("*")->where($condition)->order($order)->select()->toArray(); |
| | | $order = 'order_id asc,id asc'; |
| | | $list = Db::name('language')->field("*")->where($condition)->order($order)->select()->toArray(); |
| | | if (!$list) { |
| | | $list = []; |
| | | } |