<?php if(!defined('ONGPHP'))exit('Error ONGSOFT');
plus( array('p','jiami','jianli','mima','shanchu','qcurl','qfopen','x','memcc','txtcc','db','isutf8','setsession','pagec','pinyin','ip','post','funciton','sslget','sslpost','vcode','update','mysqlcc') );
$Memsession =  $Mem = new txtcc();
$Mem1 = new txtcc(ONGPHP.'/mode/');
$shezhi = $Mem1 -> g('shezhi');
//setsession( $CONN['sessiontime'] );


$uid = $_GET['uid'];
$user = uid( $uid , 1 );

//dump($shezhi['beijing']);exit;
$beijing = WZHOST.$shezhi['beijing'];
$base_name = $beijing;


list($width, $height) = getimagesize($base_name);

$left = (int)$width-220;
$left = $left/2;

$top = (int)$height-220;
$top = $top/2+90;
$youxi = $shezhi['youxiyuming'];
$appid = $shezhi['appid'];
$appsecret = $shezhi['appsecret'];

$tfuid = $uid."--".$user['adminid'];
$data1 = urlencode ($shezhi['tiaozhuan']);
$data2 = urlencode ('weixin.php?tfuid=');
$data3 = urlencode ($tfuid);


$data = $data1.$data2.$data3;


$data ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."%26redirect_uri=".$data."%26response_type=code%26scope=snsapi_userinfo%26state=1#wechat_redirect";
//$data11 ="https://121323434324343243243243243243243243432432432432434sadsdsdsfdsfdsfdsfdsfdsfsdfdsfsd.com/?appid=".$appid."%26redirect_uri=".$data."&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
//$data = "baidu.com";
$url = "http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=".$data;

//$url = "http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=http://tw06.top/?tuid=3";
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url );
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回，而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行命令
$data = curl_exec($curl);
//$result = curl_getinfo($curl);
//关闭URL请求
curl_close($curl);

$data = explode('[',$data);
$data = explode(']',$data['1']);

$data = json_decode($data['0']);
$data =  json_decode( json_encode( $data),true);


$url = $data['url_short'];

    if ($shezhi['tiaozhuan']) {
        
        $e = WZHOST.'ewm.php?data='.$url;

    }else{
       $e = WZHOST.'ewm.php?data='.WZHOST.'tg.php?tuid='.$uid.'%26fenxiao='.$user['adminid'];
	   
    }

    // Content type
    header('Content-Type: image/jpeg');

    // Load
    
    $thumb = @imagecreatefromjpeg($base_name);
    
    // Resize
    if(!empty($uid)){
        
        list($width, $height) = getimagesize($e);
        
        
        $e_p = imagecreatefrompng($e);
        //imagecopyresized($thumb, $e_p, $left-40, $top+100, 0, 0, 220, 220, $width, $height);
        //imagecopyresized($thumb, $e_p, $left-70, $top+75, 0, 0,360,360, $width, $height);
		imagecopyresized($thumb, $e_p, $left-30, $top-120, 0, 0,280,280, $width, $height);
		//加水印文字
		$color = imagecolorallocate($thumb,70, 80,0);
		$str = "ID:".$uid;
		$str = mb_convert_encoding($str, "html-entities","utf-8");
		//imagettftext($thumb,30, 0, $left+45, top+55, $color, 'simkai.ttf', $str);
		//imagettftext($thumb,30, 0, $left+46, top+55, $color, 'simkai.ttf', $str);
		imagettftext($thumb,30, 0,35, top+55, $color, 'simkai.ttf', $str);
		imagettftext($thumb,30, 0,36, top+55, $color, 'simkai.ttf', $str);

        
    }
    
    //header('Content-Type: image/jpeg');
    
    // Load
    
    //$thumb = @imagecreatefromjpeg($base_name);
    
    //$thumb = @imagecreatefromjpeg($thumb);
    // Output
    
    imagejpeg($thumb);
    imagedestroy($thumb);
?>




