签名与回调

环境地址

生产环境: https://open-api.shouqianba.com

金额单位

所有金额传递均为 Long,单位为

公共请求加签(用户 → 收钱吧)

sign = MD5( body + appKey )

  • header: Content-Type: application/json
  • header: Authorization: appid + " " + sign(注意用空格字符连接)

Java 示例

public static String httpPost(String url, String body, String sign, String appid) throws IOException {
    // 1. 构建请求体(JSON 格式)
    RequestBody requestBody = RequestBody.create(body, null);
    // 2. 构建请求头(sn + " " + sign)
    String authHeader = appid + " " + sign;
    // 3. 创建请求
    Request request = new Request.Builder().url(url).post(requestBody)
            .addHeader("Authorization", authHeader)
            .addHeader("content-type", "application/json")
            .build();
    // 4. 发送请求并返回响应
    try (Response response = httpClient.newCall(request).execute()) {
        if (!response.isSuccessful()) {
            throw new IOException("请求失败: " + response.code() + " - " + response.message());
        }
        return response.body().string();
    }
}

公共推送验签(收钱吧 → 用户)

  • 报文一共有 5 个字段:signatureeventIdtimestampnoncecontentcontent 为最终推送业务数据报文,JSON 格式,nonce 为随机数)
  • plaintext = eventId + timestamp + nonce + content

Java 示例

public boolean verifySignatureSHA256WithRSA(String plaintext, String signature, String publicKey) {
    return verifySignatureSHA256WithRSA(plaintext.getBytes(StandardCharsets.UTF_8), signature, publicKey);
}

public boolean verifySignatureSHA256WithRSA(byte[] plaintextByte, String inputSignature, String pubKey) {
    try {
        X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(Base64
                .getDecoder().decode(pubKey));
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = keyFactory.generatePublic(bobPubKeySpec);
        byte[] signed = Base64.getDecoder().decode(inputSignature);
        Signature signature = Signature.getInstance("SHA256WithRSA");
        signature.initVerify(publicKey);
        signature.update(plaintextByte);
        return signature.verify(signed);
    } catch (Exception e) {
        // handle exception
    }
    return false;
}

results matching ""

    No results matching ""