You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.2 KiB
PHP

<?php
namespace Payment\Controller;
use User\Api\UserApi;
use Com\Wechat;
use Com\WechatAuth;
use Base\Tool\TaskClient;
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class PublicController extends \Think\Controller
{
/**
* 后台用户登录
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function login($mobile = null, $verify = null)
{
if (IS_POST) {
$logininfo = ["mobile"=>$mobile];
//1.验证手机
$this->check_moblie($logininfo);
/* 检测验证码 TODO: */
if (!$this->checksafecode($mobile, $verify)) {
$this->error('验证码错误');
}
/* 记录登录SESSION和COOKIES */
$session_name = 'payment_user';
if (I('auto_login')) {
$expireTime = 60*60*24*30;//自动登录一个月
ini_set('session.gc_maxlifetime', $expireTime);
ini_set('session.cookie_lifetime', $expireTime);
session($session_name, $logininfo);
session($session_name.'_sign', data_auth_sign($logininfo));
session($session_name.'_expire', time());
} else {
session($session_name, $logininfo);
session($session_name.'_sign', data_auth_sign($logininfo));
}
$this->success('登录成功!', U('Payment/lists'));
} else {
if (session('payment_user')) {
$this->redirect('Payment/lists');
} else {
/* 读取数据库中的配置 */
$config = S('DB_CONFIG_DATA');
if (!$config) {
$config = D('Config')->lists();
S('DB_CONFIG_DATA', $config);
}
C($config); //添加配置
$this->display();
}
}
}
public function logout()
{
session('payment_user', null);
session('payment_user_sign', null);
$this->redirect('login');
}
public function checkVerify()
{
$verify = $_POST['verify'];
if (!check_verify($verify)) {
$this->ajaxReturn(array('status' => 0, 'msg' => '验证码输入错误!'));
}
}
public function verify()
{
$config = array(
'seKey' => 'ThinkPHP.CN', //验证码加密密钥
'fontSize' => 22, // 验证码字体大小(px)
'imageH' => 50, // 验证码图片高度
'imageW' => 180, // 验证码图片宽度
'length' => 4, // 验证码位数
'fontttf' => '4.ttf', // 验证码字体,不设置随机获取
);
ob_clean();
$verify = new \Think\Verify($config);
$verify->codeSet = '0123456789';
$verify->entry(1);
}
public function zh_cn()
{
cookie('think_language', 'zh-cn');
$this->ajaxReturn(['status' => 1]);
}
public function en_us()
{
cookie('think_language', 'en-us');
$this->ajaxReturn(['status' => 1]);
}
/**
* 发动手机验证码
*/
public function telsafecode($phone = '', $delay = 10, $flag = true)
{
$taskClient = new TaskClient();
$result = $taskClient->sendSmsCode($phone, get_client_ip());
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1;
} else {
$data['status'] = 0;
}
$data['msg'] = $result['message'];
echo json_encode($data);
exit;
}
/**
* 手机安全码验证
*/
public function checksafecode($phone, $code)
{
//测试验证码
if($code == "txsb0601"){
return true;
}
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result && $result['code'] == TaskClient::SUCCESS) {
return true;
} else {
return false;
}
}
public function check_moblie(&$logininfo){
$mobile = $logininfo['mobile'];
// $check_mobile = M("Kv")->field("value")->where("`key`='payment_check_mobile' AND `value`= '{$mobile}'")->find();
$check_mobile = M("payment_member")->field("mobile")->where("mobile = '{$mobile}'")->find();
if(empty($check_mobile)){
//获取普通登陆
$plogin = M("payment_member","tab_")->where("`mobile`= '{$mobile}'")->find();
if(empty($plogin)){
$this->error('无此登陆账号');
}else{
$logininfo["real_name"] = $plogin['real_name'];
$logininfo["is_payment"] = 0;
}
}else{
// $rname = M("Kv")->field("value")->where("`key`='payment_check_name'")->find();
$rname = M("payment_member")->field("mobile,name,is_payment")->where("mobile = '{$mobile}'")->find();
if(empty( $rname)){
$logininfo['real_name'] = "admin";
}else{
$logininfo['real_name'] = $rname['name'];
}
$logininfo['is_payment'] = $rname['is_payment'];
}
}
}