master
ELF 5 years ago
parent 7bc6cac01a
commit d29984aaeb

@ -55,6 +55,20 @@ class HomeController extends Controller
$secret = 'd3219c70a45c5e1954be4608b288d38b'; $secret = 'd3219c70a45c5e1954be4608b288d38b';
$tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret; $tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
$content = file_get_contents(RUNTIME_PATH . 'Data/wechat_ticket');
$ticketData = null;
if ($content) {
$ticketData = json_decode($content, true);
}
$isExpired = false;
if ($ticketData) {
$isExpired = time() > $ticketData['expired_at'] ? true : false;
}
$ticket = '';
if (!$ticketData || $isExpired) {
$ticket = $ticketData['ticket'];
$result = file_get_contents($tokenUrl); $result = file_get_contents($tokenUrl);
$result = json_decode($result, true); $result = json_decode($result, true);
if (!$result || isset($result['errcode'])) { if (!$result || isset($result['errcode'])) {
@ -75,6 +89,8 @@ class HomeController extends Controller
]); ]);
} }
$ticket = $result['ticket']; $ticket = $result['ticket'];
file_put_contents(RUNTIME_PATH . 'Data/wechat_ticket', json_encode(['ticket' => $ticket, 'expired_at' => time() + 3600]));
}
$randStr = 'aaabbbxeclsx'; $randStr = 'aaabbbxeclsx';
$time = time(); $time = time();

Loading…
Cancel
Save