<?php
|
|
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\facade\Config;
|
use think\captcha\facade\Captcha;
|
use app\BaseController;
|
|
class Login extends BaseController {
|
public function index() {
|
header('Content-Type:text/html;charset=utf-8');
|
$Opadmin = new Opadmin();
|
if ($Opadmin->islogin()) {
|
$this->redirect(url('/admin/')->build());
|
}
|
return View::fetch();
|
}
|
|
/**
|
* 登录
|
* @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)) {
|
$result['url'] = url('/admin/index/index')->build();
|
} else {
|
$result['url'] = $backurl;
|
}
|
}
|
} catch (Exception $exc) {
|
$result = [
|
'code' => $exc->getCode(),
|
'des' => $exc->getMessage(),
|
];
|
}
|
return $result;
|
}
|
|
public function logout() {
|
$Opadmin = new Opadmin();
|
$Opadmin->loginout();
|
$this->redirect(url('/admin/login/index')->build());
|
}
|
|
|
public function captcha() {
|
return Captcha::create();
|
}
|
|
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->errorResponse(lang('captcha_is_incorrect'));
|
}
|
return $this->successResponse(lang('captcha_success'));
|
}
|
|
public function captchaCheckAndMsg() {
|
if (!Request::isPost()) {
|
return $this->errorResponse(lang('request_method_incorrect'));
|
}
|
|
try {
|
$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 = [
|
['phone', '=', $phone],
|
['add_time', '>=', $localTime - 120],
|
['type', '=', 1],
|
];
|
$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->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
$clientProfile = new \TencentCloud\Common\Profile\ClientProfile();
|
$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法
|
$clientProfile->setHttpProfile($httpProfile);
|
// 实例化要请求产品(以sms为例)的client对象,clientProfile是可选的
|
// 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8
|
$client = new \TencentCloud\Sms\V20210111\SmsClient($cred, "ap-guangzhou", $clientProfile);
|
// 实例化一个 sms 发送短信请求对象,每个接口都会对应一个request对象。
|
$req = new \TencentCloud\Sms\V20210111\Models\SendSmsRequest();
|
/* 填充请求参数,这里request对象的成员变量即对应接口的入参
|
* 您可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义
|
* 基本类型的设置:
|
* 帮助链接:
|
* 短信控制台: https://console.cloud.tencent.com/smsv2
|
* 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */
|
/* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
|
// 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
|
$req->SmsSdkAppId = Config::get('qcloud.Qcloud.SmsSdkAppId');
|
/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
|
// 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
|
$req->SignName = Config::get('qcloud.Qcloud.SignName');
|
/* 模板 ID: 必须填写已审核通过的模板 ID */
|
// 模板 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 = [$phoneCode, '2'];
|
/* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
|
* 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
|
$req->PhoneNumberSet = ["+86" . $phone];
|
/* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
|
$req->SessionContext = "";
|
/* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
|
$req->ExtendCode = "";
|
/* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。*/
|
$req->SenderId = "";
|
// 通过client对象调用SendSms方法发起请求。注意请求方法名与请求对象是对应的
|
// 返回的resp是一个SendSmsResponse类的实例,与请求对象对应
|
$resp = $client->SendSms($req);
|
// 输出json格式的字符串回包
|
// print_r($resp->TotalCount);
|
// print_r($resp->toJsonString());
|
// exit();
|
|
$newdata = [
|
'phone' => $phone,
|
'code' => $phoneCode,
|
'type' => 1,
|
'is_use' => 0,
|
'add_time' => $localTime,
|
];
|
$id = Db::name('phone_msg')->insertGetId($newdata);
|
$result = [
|
'id' => $id,
|
// 'phonecode' => $phoneCode,
|
'msg' => 'ok',
|
];
|
return $this->successResponse($result);
|
} catch (\Exception $e) {
|
return $this->errorResponse($e->getMessage());
|
}
|
}
|
|
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();
|
if (!$list) {
|
$list = [];
|
}
|
$result['list'] = $list;
|
return $this->successResponse($result);
|
} catch (Exception $exc) {
|
return $this->errorResponse($exc->getMessage());
|
}
|
}
|
}
|