<?php
ob_start();
header('Content-Type: application/json');
require_once '../config.php';

$code = str_pad(rand(0, 999999), 6, '0', STR_PAD_LEFT);
$token = md5(uniqid(rand(), true));
$expire_at = date('Y-m-d H:i:s', time() + 300);

$db->query("INSERT INTO wechat_login_tokens (token, code, expire_at) VALUES ('$token', '$code', '$expire_at')");

echo json_encode([
    'code' => 0,
    'token' => $token,
    'verify_code' => $code
]);
exit;