Callback penerimaan
The merchant server is called only after a pay-in completes successfully; the callback status is always completed.
Only final payment results are sent. Any HTTP 2xx response stops delivery immediately. After the first failure, the platform retries in 1 minute; after another failure, it makes a final retry in 5 minutes, for up to 3 attempts total. Callback business times use Beijing time in YYYY/MM/DD HH:mm:ss format.
Header
| Kolom | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| content-type | application/json | Ya | Selalu aplikasi/json. |
| x-callback-timestamp | string | Ya | Panggilan balik timestamp dalam milidetik. |
| x-callback-nonce | string | Ya | Panggilan balik nonce. |
| x-callback-signature | string | Ya | HMAC-SHA256(apiKey, timestamp + "." + nonce + "." + rawBody)。 |
| x-callback-signature-algorithm | string | Ya | Selalu HMAC-SHA256. |
| x-callback-signature-version | string | Ya | Selalu v1. |
Parameter
| Kolom | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| merchantUid | string | Ya | Merchant UID. |
| orderNo | string | Ya | Nomor pesanan platform. |
| merchantOrderNo | string | null | Ya | Nomor pesanan pedagang. |
| bindKey | string | null | Ya | Kunci pengikatan untuk isi ulang anggota. Biasanya kosong untuk pesanan pembayaran bersama. |
| chainCode | string | null | Ya | Jaringan pesanan. |
| tokenSymbol | string | null | Ya | Token pesanan. |
| txHash | string | null | Ya | Hash transaksi yang cocok; null sebelum terdeteksi. |
| expectedAmount | string | null | Ya | Jumlah pesanan. |
| paidAmount | string | Ya | Jumlah pembayaran sebenarnya. |
| fromAddress | string | null | Ya | Alamat pengirim. |
| status | string | Ya | Final successful pay-in status; always completed. |
| mode | string | Ya | Mode: shared atau exclusive. |
| businessType | string | Ya | Jenis bisnis pesanan. |
| serviceFeeUsd | string | TIDAK | Biaya layanan penerimaan ini. |
| feeBalanceAfterUsd | string | TIDAK | Saldo akun biaya setelah pemotongan. |
| payerRiskStatus | string | Ya | Status penilaian risiko pembayar. |
| payerRiskLabel | string | null | Ya | Label penilaian risiko pembayar. |
Contoh permintaan
{
"merchantUid": "880001",
"orderNo": "PI1776193200123ABCD1234",
"merchantOrderNo": "M202604150001",
"bindKey": null,
"expectedAmount": "100.000000",
"paidAmount": "100.000000",
"chainCode": "TRON",
"tokenSymbol": "USDT",
"txHash": "f7f17891f52c35d0c93170f0d12bb347ac16ab34853b4bc8dcf7fd0a8c9aa321",
"fromAddress": "TS7b7iD8G2PaPqK1TqSmLJ9nrrYH4oKX1S",
"status": "completed",
"mode": "shared",
"businessType": "fixed",
"serviceFeeUsd": "0.000000",
"feeBalanceAfterUsd": "10.000000",
"payerRiskStatus": "low_risk",
"payerRiskLabel": "低风险"
}Kolom respons
| Kolom | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| HTTP Status | 200-299 | Ya | Setiap respons 2xx dianggap sukses. |
| Response Body | string | json | TIDAK | Respons body dapat disesuaikan. |
Contoh respons
HTTP/1.1 200 OK
Content-Type: application/json
{
"ok": true
}Contoh kode
Menjalankan: simpan Java sebagai UUGateExample.java (UUGateCallback.java untuk callback), lalu gunakan java nama file; PHP: php example.php; Go: go run example.go; Node.js: node example.mjs. Verifikasi callback membaca isi asli dari input standar.
import { createHmac, timingSafeEqual } from 'node:crypto';
function required(name) {
const value = process.env[name]?.trim();
if (!value) throw new Error(name + ' is required');
return value;
}
const key = required('UUGATE_API_KEY');
const timestamp = required('UUGATE_CALLBACK_TIMESTAMP'), nonce = required('UUGATE_CALLBACK_NONCE');
const signature = required('UUGATE_CALLBACK_SIGNATURE');
const chunks = [];
for await (const chunk of process.stdin) chunks.push(chunk);
const rawBody = Buffer.concat(chunks);
const expected = createHmac('sha256', key).update(timestamp + '.' + nonce + '.', 'utf8').update(rawBody).digest();
const actual = Buffer.from(signature, 'hex');
if (!/^[a-fA-F0-9]{64}$/.test(signature) || actual.length !== expected.length || !timingSafeEqual(expected, actual))
throw new Error('Invalid callback signature');
console.log('VERIFIED');import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HexFormat;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class UUGateCallback {
static String required(String name) {
String value = System.getenv(name);
if (value == null || value.isBlank()) throw new IllegalArgumentException(name + " is required");
return value.trim();
}
public static void main(String[] args) throws Exception {
String key = required("UUGATE_API_KEY");
String timestamp = required("UUGATE_CALLBACK_TIMESTAMP"), nonce = required("UUGATE_CALLBACK_NONCE");
String signature = required("UUGATE_CALLBACK_SIGNATURE");
byte[] rawBody = System.in.readAllBytes();
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
mac.update((timestamp + "." + nonce + ".").getBytes(StandardCharsets.UTF_8));
byte[] expected = mac.doFinal(rawBody);
if (!signature.matches("[a-fA-F0-9]{64}") ||
!MessageDigest.isEqual(expected, HexFormat.of().parseHex(signature)))
throw new IllegalArgumentException("Invalid callback signature");
System.out.println("VERIFIED");
}
}<?php
function required(string $name): string {
$value = trim((string) getenv($name));
if ($value === '') throw new RuntimeException($name . ' is required');
return $value;
}
$key = required('UUGATE_API_KEY');
$timestamp = required('UUGATE_CALLBACK_TIMESTAMP'); $nonce = required('UUGATE_CALLBACK_NONCE');
$signature = required('UUGATE_CALLBACK_SIGNATURE');
$rawBody = file_get_contents('php://stdin');
if ($rawBody === false) throw new RuntimeException('Cannot read raw body');
$expected = hash_hmac('sha256', $timestamp . '.' . $nonce . '.' . $rawBody, $key);
if (!preg_match('/^[a-fA-F0-9]{64}$/D', $signature) || !hash_equals($expected, strtolower($signature)))
throw new RuntimeException('Invalid callback signature');
echo 'VERIFIED', PHP_EOL;package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
"strings"
)
func required(name string) string {
value := strings.TrimSpace(os.Getenv(name))
if value == "" { panic(name + " is required") }
return value
}
func main() {
key := required("UUGATE_API_KEY")
timestamp, nonce := required("UUGATE_CALLBACK_TIMESTAMP"), required("UUGATE_CALLBACK_NONCE")
signature := required("UUGATE_CALLBACK_SIGNATURE")
rawBody, err := io.ReadAll(os.Stdin); if err != nil { panic(err) }
mac := hmac.New(sha256.New, []byte(key))
mac.Write([]byte(timestamp + "." + nonce + ".")); mac.Write(rawBody)
actual, err := hex.DecodeString(signature)
if err != nil || !hmac.Equal(mac.Sum(nil), actual) { panic("Invalid callback signature") }
fmt.Println("VERIFIED")
}Catatan
- Verifikasi panggilan balik menggunakan apiKey, bukan header permintaan tanda tangan x OpenAPI.
- Setelah verifikasi, cocokkan merchant, pesanan, aset, jaringan, dan jumlah. Simpan pembayaran serta hasil secara transaksional dan idempoten berdasarkan nomor platform sebelum merespons 2xx; notifikasi berulang tidak boleh menggandakan kredit atau pengiriman.
- Untuk isi ulang anggota, gunakan bindKey secara langsung sebagai pengenal anggota sehingga Anda tidak memerlukan tabel pemetaan orderNo-ke-anggota tambahan.
- Kode ini hanya memverifikasi callback. Kirim isi asli ke input standar dan petakan header ke UUGATE_CALLBACK_TIMESTAMP, UUGATE_CALLBACK_NONCE, UUGATE_CALLBACK_SIGNATURE. UUGATE_API_KEY harus sama dengan key saat membuat pesanan. Selanjutnya periksa pesanan dan simpan secara idempoten dalam transaksi sebelum mengembalikan HTTP 2xx.