qrcode.inc.php
3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: qrcode.inc.php 34716 2014-07-14 08:28:32Z nemohou $
*/
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$dir = DISCUZ_ROOT.'./data/cache/qrcode/';
$_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
if($_GET['access']) {
dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 86400).' GMT');
require_once DISCUZ_ROOT . './source/plugin/wechat/wsq.class.php';
$url = wsq::$WSQ_DOMAIN.'siteid='.$_G['wechat']['setting']['wsq_siteid'].'&c=index&a=';
if($_GET['threadqr']) {
$tid = dintval($_GET['threadqr']);
include_once template('wechat:wechat_threadqr');
} elseif($_GET['tid']) {
$qrsize = !empty($_GET['qrsize']) ? $_GET['qrsize'] : 4;
if(empty($_GET['pid'])) {
$tid = dintval($_GET['tid']);
$dtid = sprintf("%09d", $tid);
$dir1 = substr($dtid, 0, 3);
$dir2 = substr($dtid, 3, 2);
$dir3 = substr($dtid, 5, 2);
$dir = $dir.$dir1.'/'.$dir2.'/'.$dir3.'/';
$file = $dir.'/qr_t'.$tid.'.jpg';
if(!file_exists($file) || !filesize($file)) {
if(!C::t('forum_thread')->fetch($tid)) {
exit;
}
dmkdir($dir);
require_once DISCUZ_ROOT.'source/plugin/mobile/qrcode.class.php';
QRcode::png($url.'viewthread&tid='.$_GET['tid'].'&source=pcscan', $file, QR_ECLEVEL_Q, $qrsize);
}
dheader('Content-Disposition: inline; filename=qrcode_t'.$tid.'.jpg');
dheader('Content-Type: image/pjpeg');
@readfile($file);
} else {
require_once DISCUZ_ROOT.'source/plugin/mobile/qrcode.class.php';
QRcode::png($url.'showactivity&tid='.$_GET['tid'].'&viewpid='.$_GET['pid'].'&source=pcscan', false, QR_ECLEVEL_Q, $qrsize);
}
} elseif($_GET['fid']) {
$qrsize = !empty($_GET['qrsize']) ? $_GET['qrsize'] : 2;
$fid = dintval($_GET['fid']);
$file = $dir.'qr_'.$fid.'.jpg';
if(!file_exists($file) || !filesize($file)) {
if(!C::t('forum_forum')->fetch($fid)) {
exit;
}
dmkdir($dir);
require_once DISCUZ_ROOT.'source/plugin/mobile/qrcode.class.php';
QRcode::png($url.'index&fid='.$_GET['fid'].'&source=pcscan', $file, QR_ECLEVEL_Q, $qrsize);
}
dheader('Content-Disposition: inline; filename=qrcode_'.$fid.'.jpg');
dheader('Content-Type: image/pjpeg');
@readfile($file);
} else {
$qrsize = !empty($_GET['qrsize']) ? $_GET['qrsize'] : 2;
$file = $dir.'qr_index.jpg';
if(!file_exists($file) || !filesize($file)) {
dmkdir($dir);
require_once DISCUZ_ROOT.'source/plugin/mobile/qrcode.class.php';
QRcode::png($url.'index&source=pcscan', $file, QR_ECLEVEL_Q, $qrsize);
}
dheader('Content-Disposition: inline; filename=qrcode_index.jpg');
dheader('Content-Type: image/pjpeg');
@readfile($file);
}
exit;
}
require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
$wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']);
list($ticket, $code) = explode("\t", authcode($_G['cookie']['wechat_ticket'], 'DECODE'));
if($ticket) {
$file = $dir.md5($ticket).'_'.$code.'.jpg';
if(!file_exists($file) || !filesize($file)) {
dmkdir($dir);
$qrcode = dfsockopen($wechat_client->getQrcodeImgUrlByTicket($ticket));
$fp = @fopen($file, 'wb');
@fwrite($fp, $qrcode);
@fclose($fp);
}
dheader('Content-Disposition: inline; filename=qrcode.jpg');
dheader('Content-Type: image/pjpeg');
@readfile($file);
}