Signature Description

When you decided to use page integration, you need to sign the parameters. Generating a signature is divided into two steps:

Step 1: Confirm the encrypted string participating in the signature

You need to sort the fields that need to be signed in the parameters you pass in by first letter to generate a signature string.

Step 2: Generate your signature

Generate a signature as below.

package com.example;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.TreeMap;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.util.Random;
public class nft {

    private final static String CHARSET = "UTF-8";

    public static String sign(String s, String key) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA1");
        SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(CHARSET), mac.getAlgorithm());
        byte[] hash = mac.doFinal(s.getBytes(CHARSET));
        return DatatypeConverter.printBase64Binary(hash);

    public static void main(String[] args) throws Exception {
        final String APP_ID = "ahzxh0klegv1fzol";
        final String APP_SECRET = "py2bwighth62ajq6";
				String signStr = "amount=3000&appId=ahzxh0klegv1fzol&callbackUrl="
        String signture = sign(signStr, APP_SECRET); // 公共参数
				System.out.println("signture is: " + signture);


//node v14.15.1
const crypto = require('crypto');

function encrypt(plainText, secretKeyData) {
  try {
    var hmac = crypto.createHmac("sha1", secretKeyData);
    var signed = hmac.update(Buffer.from(plainText, 'utf-8')).digest("base64");
    return signed;
  } catch (e) {
    console.log(`HmacSHA1 encrypting exception, msg is ${e.toString()}`);
  return null;

let key = "py2bwighth62ajq6";
const plaintext = "amount=3000&appId=ahzxh0klegv1fzol&callbackUrl=";
const ciphertext = encrypt(plaintext,"py2bwighth62ajq6"); //appSecret
console.log("sign is ",ciphertext);
const urlEncodeText = encodeURIComponent(ciphertext)
console.log("encode sign is ",urlEncodeText);
#Python 3.7.4 
import base64
import urllib
import requests
import base64
import hashlib
import hmac

def encrypt(key, s, method):
    hmac_str ="utf8"), s.encode("utf8"), method).digest()
    return base64.b64encode(hmac_str)

rawdata = rawData = "amount=3000&appId=ahzxh0klegv1fzol&callbackUrl="
sign = encrypt(secret_key, rawData, hashlib.sha1)
print("sign is:", sign)
urlEncodeData = urllib.parse.quote_plus(sign)
print("encode sign is: ", urlEncodeData)
//PHP 8.0.7
function encrypt($plaintext,$secretKey){
    $plaintextData = utf8_encode($plaintext);
    $secretKeyData = utf8_encode($secretKey);
    $ciphertext = hash_hmac('sha1', $plaintextData, $secretKeyData,true);
    return base64_encode($ciphertext);

$data = "amount=3000&appId=ahzxh0klegv1fzol&callbackUrl=";
$key = 'py2bwighth62ajq6';
$sign = encrypt($data,$key);
printf("sign is: %s\n",$sign);
$urlEncodeData = urlencode($sign);
printf("encode sign is:: %s",$urlEncodeData);
//go version go1.18.2
package main

import (

func encrypt(message string, secret string) string {
	key := []byte(secret)
	h := hmac.New(sha1.New, key)
	return base64.StdEncoding.EncodeToString([]byte(h.Sum(nil)))

func main() {
	rawData := "amount=3000&appId=ahzxh0klegv1fzol&callbackUrl="
	key := "py2bwighth62ajq6"
	sign := encrypt(rawData, key)
	fmt.Printf("sign is %s \n", sign)
	encodeSign := url.QueryEscape(sign)
	fmt.Printf("encode sign is %s \n", encodeSign)