Example #1
0
 /**
  * @descrpition 验证码
  */
 public function captcha()
 {
     $width = 130;
     $height = 30;
     $total = 6;
     $font = 5;
     $str = '0123456789qazwsxedcrfvtgbyhnujmkpAZWSXEDCRFVTGBHNUJMKP';
     $im = imagecreatetruecolor($width, $height);
     //背景
     $white = imagecolorallocate($im, 255, 255, 255);
     imagefill($im, 0, 0, $white);
     //边框
     $brodeColor = imagecolorallocate($im, 95, 158, 160);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $brodeColor);
     //字体
     $text = '';
     $fontColor = array();
     $fontColor[] = imagecolorallocate($im, 199, 21, 133);
     //mediumvioletred(适中的紫罗兰红)
     $fontColor[] = imagecolorallocate($im, 128, 0, 128);
     //RGB(128,0,128)purple(紫)
     $fontColor[] = imagecolorallocate($im, 75, 0, 130);
     //RGB(75,0,130)indigo(靓青)
     $fontColor[] = imagecolorallocate($im, 65, 105, 225);
     //RGB(65,105,225)royalblue(皇家蓝)
     $fontColor[] = imagecolorallocate($im, 220, 20, 60);
     //RGB(220,20,60) crimson(腥红)
     for ($i = 0; $i < $total; $i++) {
         $w = 10 + $i * 20;
         $h = rand(5, 15);
         $latter = substr($str, rand(0, strlen($str)), 1);
         $text .= $latter;
         imagestring($im, $font, $w, $h, $latter, $fontColor[array_rand($fontColor)]);
     }
     //干扰点
     $red = imagecolorallocate($im, 255, 0, 0);
     $blue = imagecolorallocate($im, 0, 0, 255);
     $black = imagecolorallocate($im, 0, 0, 0);
     for ($i = 0; $i < 50; $i++) {
         imagesetpixel($im, rand(0, $width), rand(0, $height), $blue);
         imagesetpixel($im, rand(0, $width), rand(0, $height), $black);
         imagesetpixel($im, rand(0, $width), rand(0, $height), $red);
     }
     //干扰线
     $green = imagecolorallocate($im, 0, 255, 0);
     $randColor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
     imageline($im, 0, 0, 130, 30, $green);
     imageline($im, 0, 10, rand(20, 130), 30, $randColor);
     Response::setSession('captcha', strtolower($text));
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
Example #2
0
 /**
  * @descrpition 获取微信ACCESS_TOKEN
  * @return Ambigous|bool
  */
 public static function getAccessToken()
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . WECHAT_APPID . '&secret=' . WECHAT_APPSECRET;
     $accessToken = CurlBusiness::callWebServer($url, '', 'GET');
     if (!isset($accessToken['access_token'])) {
         return MsgCommon::returnErrMsg(MsgConstant::ERROR_GET_ACCESS_TOKEN, '获取ACCESS_TOKEN失败');
     }
     $accessToken['time'] = time();
     //存入SESSION
     Response::setSession('wechat_access_token', $accessToken);
     return $accessToken;
 }
Example #3
0
 /**
  * @descrpition 后台登录 ...
  */
 public function login()
 {
     $loginInfo = Request::getSession($this->sessionId);
     if (!empty($loginInfo) && !empty($loginInfo['username']) && !empty($loginInfo['id'])) {
         View::showAdminMessage('/admin.php/index/main', '已经登录!');
     }
     //表单提交处理
     if (Request::getRequest('dosubmit', 'str')) {
         $username = Request::getRequest('username', 'str');
         $password = Request::getRequest('password', 'str');
         $password = md5($username . PASSWORD_INTERFERE . $password);
         $result = $this->adminUserObj->getByUsername($username);
         if (isset($result) && $result['password'] == $password) {
             $session = array();
             $session['id'] = $result['id'];
             $session['username'] = $result['username'];
             Response::setSession($this->sessionId, $session);
             View::jsJump('/admin.php/index/main');
         } else {
             View::showAdminErrorMessage('/admin.php/admin/login', '登录后台失败!');
         }
     }
     View::showAdminTpl('login');
 }