Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/OTapi/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const crypto = require('crypto');
/**
* Generate OTAPI Signature and Timestamp
* @param {string} methodName - The name of the OTAPI method (e.g., "GetCategoryInfo")
* @param {Object} params - Key-value object of parameters (excluding signature & timestamp)
* @param {string} secret - Your OTAPI secret key (provided by OTAPI support)
* @returns {{ signature: string, timestamp: string }}
*/
function generateOtapiSignature(methodName, params, secret) {
// Generate timestamp in UTC (yyyyMMddHHmmss)
const now = new Date();
const pad = (n) => String(n).padStart(2, '0');
const timestamp = `${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}`;
// Add timestamp to the parameters object
const fullParams = { ...params, timestamp };
// Sort parameters by name
const sortedKeys = Object.keys(fullParams).sort();
// Concatenate values in order (without URL encoding)
const concatenatedValues = sortedKeys.map(key => fullParams[key]).join('');
// Final string to hash
const stringToHash = `${methodName}${concatenatedValues}${secret}`;
// Generate SHA256 hash in hex format
const signature = crypto.createHash('sha256').update(stringToHash).digest('hex');
return { signature, timestamp };
}
// 🔧 Example usage
const methodName = 'BatchSearchItemsFrame';
const xmlParameters = `<SearchItemsParameters>
<ItemTitle>adidas</ItemTitle>
<Provider>Alibaba1688</Provider>
<Order>TotalVolumeDesc</Order>
</SearchItemsParameters>`;
const params = {
instanceKey: "c4e85fb9-7f86-4091-8d38-73a7b4db3d79",
language: '',
framePosition: 0,
frameSize: 50,
xmlParameters: xmlParameters,
// timestamp: timestamp, // <-- Add this line
blockList: '',
sessionId: '',
};
const secret = 'df54991d57503f6d1b88e0279cbf0c25'; // Replace with your real OTAPI secret
const result = generateOtapiSignature(methodName, params, secret);
console.log('Timestamp:', result.timestamp);
console.log('Signature:', result.signature);
// Optionally, construct the full URL
const queryString = Object.entries({ ...params, timestamp: result.timestamp, signature: result.signature })
.map(([key, val]) => `${key}=${encodeURIComponent(val)}`)
.join('&');
const fullUrl = `http://otapi.net/service/${methodName}?${queryString}`;
console.log('Request URL:', fullUrl);
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.012 ]-- |