Embedded Wallet API Doc

Embedded Wallet API Doc


签名计算过程(Java 版本)

<p>import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets;</p> <p>public class HmacSha256Util { public static String generateSignature(String merchantId, String userName, String timestamp, String apiKey) { try { // 参数校验 if (merchantId == null || userName == null || timestamp == null || apiKey == null) { throw new IllegalArgumentException(&quot;Parameters cannot be null&quot;); }</p> <pre><code> // 拼接数据 String rawData = merchantId + userName + timestamp; // 初始化 HMAC-SHA256 Mac hmacSHA256 = Mac.getInstance(&amp;quot;HmacSHA256&amp;quot;); SecretKeySpec secretKey = new SecretKeySpec(apiKey.getBytes(StandardCharsets.UTF_8), &amp;quot;HmacSHA256&amp;quot;); hmacSHA256.init(secretKey); // 计算哈希 byte[] hash = hmacSHA256.doFinal(rawData.getBytes(StandardCharsets.UTF_8)); // 转换为十六进制字符串 return bytesToHex(hash); } catch (Exception e) { throw new RuntimeException(&amp;quot;Failed to generate HMAC-SHA256 signature&amp;quot;, e); } } private static String bytesToHex(byte[] bytes) { StringBuilder hexString = new StringBuilder(bytes.length * 2); for (byte b : bytes) { hexString.append(String.format(&amp;quot;%02x&amp;quot;, b)); } return hexString.toString(); } public static void main(String[] args) { // 示例 String merchantId = &amp;quot;123456&amp;quot;; String userName = &amp;quot;testUser&amp;quot;; String timestamp = &amp;quot;1700000000&amp;quot;; String apiKey = &amp;quot;mySecretKey&amp;quot;; String signature = generateSignature(merchantId, userName, timestamp, apiKey); System.out.println(&amp;quot;Generated Signature: &amp;quot; + signature); }</code></pre> <p>}</p>

页面列表

ITEM_HTML