예제 #1
0
 public function wx_get_jsapi_ticket()
 {
     $ticket = "";
     do {
         $ticket = S('wx_ticket');
         if (!empty($ticket)) {
             break;
         }
         $token = S('access_token');
         if (empty($token)) {
             $this->wx_get_token();
         }
         $token = S('access_token');
         if (empty($token)) {
             logErr("get access token error.");
             break;
         }
         $url2 = sprintf("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi", $token);
         $res = file_get_contents($url2);
         $res = json_decode($res, true);
         $ticket = $res['ticket'];
         // 注意:这里需要将获取到的ticket缓存起来(或写到数据库中)
         // ticket和token一样,不能频繁的访问接口来获取,在每次获取后,我们把它保存起来。
         S('wx_ticket', $ticket, 7000);
     } while (0);
     return $ticket;
 }
예제 #2
0
/**
 * Creates the square image from the given image in maximum size.
 * Scales the image up or down and makes the non-covered parts transparent.
 *
 * @param string  $origPath   Full path to original image
 * @param string  $ext        File extension ("jpg" or "png")
 * @param string  $targetPath Full path to target image file
 * @param integer $maxSize    Maxium image size the server supports
 *
 * @return boolean True if all went well, false if there was an error
 */
function createSquare($origPath, $ext, $targetPath, $maxSize)
{
    if ($ext == 'png') {
        $imgOrig = imagecreatefrompng($origPath);
    } else {
        if ($ext == 'jpg' || $ext == 'jpeg') {
            $imgOrig = imagecreatefromjpeg($origPath);
        } else {
            //unsupported format
            return false;
        }
    }
    if ($imgOrig === false) {
        logErr('Error loading image file: ' . $origPath);
        return false;
    }
    $imgSquare = imagecreatetruecolor($maxSize, $maxSize);
    imagealphablending($imgSquare, false);
    imagefilledrectangle($imgSquare, 0, 0, $maxSize - 1, $maxSize - 1, imagecolorallocatealpha($imgSquare, 0, 0, 0, 127));
    imagealphablending($imgSquare, true);
    $oWidth = imagesx($imgOrig);
    $oHeight = imagesy($imgOrig);
    if ($oWidth > $oHeight) {
        $flScale = $maxSize / $oWidth;
    } else {
        $flScale = $maxSize / $oHeight;
    }
    $nWidth = (int) ($oWidth * $flScale);
    $nHeight = (int) ($oHeight * $flScale);
    imagecopyresampled($imgSquare, $imgOrig, ($maxSize - $nWidth) / 2, ($maxSize - $nHeight) / 2, 0, 0, $nWidth, $nHeight, $oWidth, $oHeight);
    imagesavealpha($imgSquare, true);
    imagepng($imgSquare, $targetPath);
    imagedestroy($imgSquare);
    imagedestroy($imgOrig);
    return true;
}
예제 #3
0
파일: getjs.php 프로젝트: PHPPlay/xbackdoor
function updateUser($uid, $mysqli)
{
    //TODO save an history of (different) ip and ua for each user
    $ip = getUserIP();
    $ua = sanitize($_SERVER['HTTP_USER_AGENT']);
    $hd = getHeaders();
    $d = date("Y-m-d H:i:s");
    if ($mysqli->query("UPDATE users SET ip='" . $ip . "', ua='" . $ua . "',lastupdate='" . $d . "',status=1,lastonline='" . $d . "',headers='" . $hd . "' WHERE id=" . $uid . ";") === FALSE) {
        logErr("Failed to update information of the user [" . $ip . "]");
    }
}