Webhook签名

Webhook 签名的生成演示

public class MerSignCheckUtil { private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String getMerSign(String appId, String appSecret, String signStr) { return encode("sha1", appId + appSecret + signStr); } private static String encode(String algorithm, String value) { if (value == null) { return null; } try { MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(value.getBytes()); return getFormattedText(messageDigest.digest()); } catch (Exception e) { throw new RuntimeException(e); } } private static String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); for (int j = 0; j < len; j++) { buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } } // 生成 sign public static void main(String[] args) { String signStrOnRamp = appId+orderNo+crypto+network+address; String signStrOffRamp = orderNo+crypto+network+address; System.out.println(MerSignCheckUtil.getMerSign("f83Is2**********", "4Yn*************", signStr)); }
//node v14.15.1 const sha1 = require('js-sha1'); signStrOnRamp = appId+orderNo+crypto+network+address signStrOffRamp = orderNo+crypto+network+address function getMerSign(appId, appSecret, signStr) { return sha1(appId + appSecret + String(signStr)); }
#Python 3.7.4 import hashlib def getMerSign(appId, appSecret, signStr): strr = appId + appSecret + signStr encoded_str = strr.encode() hash_obj = hashlib.sha1(encoded_str) hexa_value = hash_obj.hexdigest() return hexa_value sign_str_OnRamp = appId+orderNo+crypto+network+address sign_str_OffRamp = orderNo+crypto+network+address res = getMerSign("f83Is2**********", "4Yn*************", signStr) print(res)
//PHP 8.0.7 <?php function getMerSign($appId, $appSecret, $signStr){ $str = $appId.$appSecret.$signStr; return sha1($str); } $signStr = $appid.$orderNo.$crypto.$network.$address printf("timestamp = %d\n", $signStr); $res = getMerSign("f83Is2**********", "4Yn*************", $signStr); print($res); ?>
//go version go1.18.2 package main import ( "crypto/sha1" "encoding/hex" "strconv" ) func getMerSign(appId string, appSecret string, signStr string) string { signStrOnRamp := appId+orderNo+crypto+network+address signStrOffRamp := orderNo+crypto+network+address s := appId + appSecret + signStr h := sha1.New() h.Write([]byte(s)) //io.WriteString(h, s) return hex.EncodeToString(h.Sum(nil)) }

Did this page help you?