当然是 GD 生成啊
[code]
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$level_register_up = (float)$affiliate['config']['level_register_up'];
$rank_points = $GLOBALS['db']->getOne("SELECT rank_points FROM " . $GLOBALS['ecs']->
table('users') . "where user_id=" . $user_id);
if ($rank_points < $level_register_up)
{
$msgType = "text";
$contentStr = "您还不是分销商,暂时不能获取推广二维码.";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
$this->universal($fromUsername, $base_url);
$this->insert_wmessage($db, $fromUsername, $contentStr, $time, $belong);
echo $resultStr;
exit;
}
$ArticleCount = 1;
$scene_id = $user_id;
$affiliate = $user_id;
$gourl = $base_url . 'wechat/egg/index1.php?scene_id=' . $scene_id;
$type = 'tj';
$qr_path = $db->getOne("SELECT `qr_path` FROM `wxch_qr` WHERE `scene_id`='$scene_id'");
$user_name = $db->getOne("SELECT `user_name` FROM `ecs_users` WHERE `user_id`='$scene_id'");
$scene = $user_name;
$qr_path = $db->getOne("SELECT `qr_path` FROM `wxch_qr_tianxin100` WHERE `scene_id`='$scene_id'");
/**/
if (!empty($qr_path))
{
$surl = $qr_path;
$data = dirname(__FILE__) . "/qrcode/" . $surl;
} else
{
$action_name = "QR_LIMIT_SCENE";
$json_arr = array('action_name' => $action_name, 'action_info' => array('scene' =>
array('scene_id' => $scene_id)));
$data = json_encode($json_arr);
$this->access_token($db);
$ret = $db->getRow("SELECT `access_token` FROM `wxch_config`");
$access_token = $ret['access_token'];
if (strlen($access_token) >= 64)
{
$url = '
https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token;
$res_json = $this->curl_grab_page($url, $data);
$json = json_decode($res_json);
}
$ticket = $json->ticket;
if ($ticket)
{
$ticket_url = urlencode($ticket);
$ticket_url = '
https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket_url;
$imageinfo = $this->downloadimageformweixin($ticket_url);
$time = time();
$url = $_SERVER['HTTP_HOST'];
$path = '../images/qrcode/' . $time . '.jpg';
$surl = "http://" . $url . '/images/qrcode/' . $time . '.jpg';
$local_file = fopen($path, 'a');
$h_path = '../images/qrcode/head/' . $time . '.jpg';
$h_local_file = fopen($h_path, 'a');
$headimgurl = $db->getOne("SELECT `headimgurl` FROM `wxch_user` WHERE `wxid`='$fromUsername'");
$h_imageinfo = $this->downloadimageformweixin($headimgurl);
if (false !== $local_file)
{
if (false !== fwrite($local_file, $imageinfo) && false !== fwrite($h_local_file,
$h_imageinfo))
{
fclose($local_file);
//将生成的二维码图片的地址放到数据库中
$insert_sql = "INSERT INTO `wxch_qr` (`type`,`action_name`,`ticket`, `scene_id`, `scene` ,`qr_path`,`function`,`affiliate`,`endtime`,`dateline`) VALUES
('$type','$action_name', '$ticket',$scene_id, '$scene' ,'$surl','$function','$affiliate','$endtime','$dateline')";
$db->query($insert_sql);
}
}
}
$imgsrc = "../images/qrcode/" . $time . ".jpg";
$h_imgsrc = "../images/qrcode/head/" . $time . ".jpg";
$width = 230;
$height = 230;
$time = time();
$name = $this->resizejpg($imgsrc, $width, $height, $time);
$imgs = $name;
//处理头像
$width = 100;
$height = 100;
$h_time = $time . "_1";
$h_name = $this->resizejpg($h_imgsrc, $width, $height, $h_time);
$h_imgs = $h_name;
$target = '../qrcode/tianxin100.jpg'; //背景图片
$target_img = Imagecreatefromjpeg($target);
$source = Imagecreatefromjpeg($imgs);
$h_source = Imagecreatefromjpeg($h_imgs);
imagecopy($target_img, $source, 155, 462, 0, 0, 230, 230);
imagecopy($target_img, $h_source, 60, 28, 0, 0, 100, 100);
$fontfile = "simsun.ttf";
#水印文字
$nickname = $db->getOne("SELECT `nickname` FROM `wxch_user` WHERE `wxid`='$fromUsername'");
#打水印
$textcolor = imagecolorallocate($target_img, 0, 0, 255);
imagettftext($target_img, 18, 0, 268, 59, $textcolor, $fontfile, $nickname);
Imagejpeg($target_img, 'qrcode/' . $time . '.jpg');
$data = dirname(__FILE__) . "/qrcode/" . $time . ".jpg";
$s_data = $time . ".jpg";
$insert_sql = "INSERT INTO `wxch_qr_tianxin100` (`qr_path`,`scene`,`scene_id`, `nickname`) VALUES
('$s_data','$scene', '$scene_id','$nickname')";
$db->query($insert_sql);
}
$filedata = array("media" => "@" . $data);
$this->access_token($db);
$ret = $db->getRow("SELECT `access_token` FROM `wxch_config`");
$access_token = $ret['access_token'];
if (strlen($access_token) >= 64)
{
$url = '
http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $access_token .
'&type=image';
$res_json = $this->https_request($url, $filedata);
$json = json_decode($res_json);
}
$msgType = "image";
$iipp = $_SERVER["REMOTE_ADDR"];
$phone_state = $_SERVER['HTTP_USER_AGENT'];
$contentStr = $json->media_id;
$resultStr = sprintf($imageTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
$this->insert_wmessage($db, $fromUsername, $contentStr, $time, $belong);
$this->universal($fromUsername, $base_url);
echo $resultStr;
exit;
}
[/code]