签名算法

MD5 签名

  1. 将所有非空参数(除 sign、sign_type 外)按参数名 ASCII 升序排序;
  2. 拼接为 k1=v1&k2=v2... 的字符串(不进行 URL 编码);
  3. 在字符串末尾拼接商户密钥,做 MD5 得到 32 位小写签名。
// PHP 示例
$params = $_POST;
unset($params['sign'], $params['sign_type']);
ksort($params);
$signStr = urldecode(http_build_query($params));
$sign = md5($signStr . $merchantKey);

RSA2 签名

使用商户 RSA 私钥对同样的待签名字符串做 SHA256withRSA 签名并 Base64 编码,平台使用商户公钥验签。签名结果放入 sign,sign_type 传 RSA。

开启 RSA 模式后,商户密钥接口将不可用,请在用户中心「安全设置」上传公钥后再切换。