跳到主要内容

快速开始

Jpay 支持 API 接入,也支持 Wordpress、Shoplazza 等第三方平台(见扩展或联系工作人员)。

生成签名

The signature value is an uppercase MD5 hash of a sorted, URL-encoded parameter string concatenated with your merchant API key. Include the resulting value in the sign or pay_md5sign field of each request.

Signature data

Collect all request parameters with non-empty values (excluding sign and pay_md5sign), sort them by parameter name in ASCII order, and join them as key1=value1&key2=value2.... Append &key={merchantApiKey} to form stringSignTemp.

Only top-level scalar fields participate in signing. Nested objects and arrays are sent in the request body but are not included in the signature string.

Example data

FieldDescriptionTest data
pay_orderidMerchant order ID.ORDER123456
pay_amountPayment amount.100.00
pay_memberidMerchant ID.10010
pay_applydateOrder timestamp.2024-01-01 12:00:00
pay_bankcodeBank code.901
pay_notifyurlAsync notification URL.https://example.com/notify
pay_callbackurlReturn URL after payment.https://example.com/callback
keyMerchant API key appended during signing.7e4nicn14nhyup146dfbi8hpnpus9juz

Steps

  1. Filter out empty values and the sign / pay_md5sign fields from the request parameters.
  2. Sort the remaining parameter names in ascending ASCII order and join them as URL key-value pairs.
  3. Append &key={merchantApiKey} to build stringSignTemp.
  4. Compute MD5(stringSignTemp) and convert the result to uppercase.

Expected stringSignTemp with the test data above

stringSignTemp
pay_amount=100.00&pay_applydate=2024-01-01 12:00:00&pay_bankcode=901&pay_callbackurl=https://example.com/callback&pay_memberid=10010&pay_notifyurl=https://example.com/notify&pay_orderid=ORDER123456&key=7e4nicn14nhyup146dfbi8hpnpus9juz

Expected signature with the test data above

sign
F8E5D99685501D1676CA95A3871581EA

Code examples

import { md5 } from "js-md5";

const KEY = "7e4nicn14nhyup146dfbi8hpnpus9juz";

const params = {
  pay_orderid: "ORDER123456",
  pay_amount: "100.00",
  pay_memberid: "10010",
  pay_applydate: "2024-01-01 12:00:00",
  pay_bankcode: "901",
  pay_notifyurl: "https://example.com/notify",
  pay_callbackurl: "https://example.com/callback",
};

function generateSign(data, key) {
  const signData = [];
  Object.keys(data)
    .filter((name) => data[name] !== "" && data[name] != null)
    .sort()
    .forEach((name) => signData.push(`${name}=${data[name]}`));
  signData.push(`key=${key}`);
  return md5(signData.join("&")).toUpperCase();
}

const sign = generateSign(params, KEY);
console.log(sign); // F8E5D99685501D1676CA95A3871581EA