import crypto from "crypto";
const GATEWAY_URL = "http://your-gateway:180";
const MERCHANT_TOKEN = process.env.XPAYLABS_TOKEN;
function signRequest(data) {
return crypto
.createHmac("sha256", MERCHANT_TOKEN)
.update(JSON.stringify(data), "utf8")
.digest("hex");
}
async function createCollection(amount, orderId) {
const data = {
amount: amount,
symbol: "USDT",
chain: "TRON",
orderId: orderId,
};
const payload = {
sign: signRequest(data),
timestamp: Math.floor(Date.now() / 1000),
nonce: crypto.randomUUID(),
data,
};
const response = await fetch(`${GATEWAY_URL}/v1/order/createCollection`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const result = await response.json();
if (result.code !== 200) throw new Error(result.msg);
return result.data;
}
const payment = await createCollection("100.00", "order_1042");
console.log(`发送 USDT 到: ${payment.address}`);
console.log(`结账页面: ${payment.paymentUrl}`);