Initiate Recharge Request
The recharge process involves communication between a child iframe (game page) and the parent page. This ensures a seamless and secure user experience for initiating and completing recharge transactions.
Step 1: Send Recharge Information
Overview:
• The game (child iframe) sends a recharge request to the UMIVERSE platform (parent page) using the postMessage API.
• This request contains critical information such as the order ID, recharge amount, merchant ID, timestamp, and a secure signature for verification.
Recharge Request Format
The following is the format of the recharge request sent from the child iframe to the parent page:
const jsonData = {
orderId: "ORDER12345", // Unique order ID
amount: "50", // Amount in USD
merchantId: "MERCHANT01", // UMI-MERCHANTID
ts: Math.floor(Date.now() / 1000), // Current timestamp in seconds
sign: "generated_signature", // Signature for request verification
extraParams: "game-specific-data", // Additional data (optional)
};
window.parent.postMessage(jsonData, "*");
How to Send the Request:
Use the postMessage method in JavaScript to send the recharge information from the iframe to the parent page.
window.parent.postMessage(jsonData, "*");
Signature Generation
The sign field is crucial for ensuring the integrity and authenticity of the request. The signature is generated as follows:
1. Algorithm:
• Concatenate the values of the parameters in the jsonData object (in the order they appear) into a single string.
• Append the current timestamp (ts) and the secret key (UMI-API-KEY) to the string.
• Use the MD5 hashing algorithm to generate the signature.
2. Code Implementation:
function createSign(ts, param = null, key = "UMI-API-KEY") {
let str = `${param['merchantId']}${param['orderId']${param['amount']${param['description']}}}`
str += `${ts}${key}`;
const sign = MD5(str).toString();
return sign;
}
3. Example Usage:
const jsonData = {
orderId: "ORDER12345",
amount: "50",
merchantId: "MERCHANT01",
ts: Math.floor(Date.now() / 1000),
extraParams: "optional-data",
};
// Generate the signature
jsonData.sign = createSign(jsonData.ts, jsonData, "UMI-API-SECRET");
// Send the recharge request
window.parent.postMessage(jsonData, "*");
Last updated