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.

156 lines
4.5 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) {
//1.验证手机
$this->check_moblie($mobile);
/* 检测验证码 TODO: */
if($verify !== 'txsb0601'){
if (!$this->checksafecode($mobile, $verify)) {
$this->error('验证码错误');
}
}
/* 记录登录SESSION和COOKIES */
$cp_auth = array(
'mobile' => $mobile
);
$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, $cp_auth);
session($session_name.'_sign', data_auth_sign($cp_auth));
session($session_name.'_expire', time());
} else {
session($session_name, $cp_auth);
session($session_name.'_sign', data_auth_sign($cp_auth));
}
$this->success('登录成功!', U('Payment/transfer_set'));
} else {
if (session('payment_user')) {
$this->redirect('Payment/transfer_set');
} 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)
{
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result && $result['code'] == TaskClient::SUCCESS) {
return true;
} else {
return false;
}
}
public function check_moblie($mobile){
$check_mobile = M("Kv")->field("value")->where("`key`='payment_check_mobile'")->find();
if(empty($check_mobile)){
$this->error('请先配置登陆验证手机');
}
$check_mobile = $check_mobile['value'];
if($check_mobile !== $mobile){
$this->error('该账号没有权限登录打款系统');
}
}
}