响应OR通知验签说明

签名方式:RSA

签名算法:SHA1WithRSA

排序拼接方式:按照首字母顺序排序,以key1=value1&key2=value2&key3=value3.....形式组装加签串,value为空字段不参与签名

验签公钥:盛付通公钥(针对不同环境,请联系钱包产品获取)

加签代码示例:

public static void main(String[] args) throws Exception {
    // 字段按照字母序排序并使用key=value&方式拼接
    Map<String, String> paramsMap = new TreeMap<>();
    paramsMap.put("openId", "2398724h98y912");
    paramsMap.put("appId", "djgeiq978y933");
    paramsMap.put("appName", "2324424214124124");
    paramsMap.put("mchId", "93745648");
    paramsMap.put("outTradeNo", "hiuhei09023j12j40206");
    paramsMap.put("timeStart", "20180801160000");
    paramsMap.put("timeExpire", "20180801180000");
    paramsMap.put("totalFee", "100");
    paramsMap.put("notifyUrl", "https://notify.shengpay.com/notify");
    paramsMap.put("nonceStr", "pWUVWVYWNQhnTXpQzhIzMGCwqBkZclzg");
    paramsMap.put("goodsTag", "WIFI_DISCOUNT_001");
    paramsMap.put("body", "抓娃娃机-游戏充值");
    paramsMap.put("detail", "{\"goodsDetails\":[{\"goodsId\":\"goodsId1\",\"goodsName\":\"goodsIName1\",\"price\":100,\"quantity\":1}]}");
    paramsMap.put("attach", "{\"memo\":\"test\"}");
    paramsMap.put("tradeType", "APP");
    paramsMap.put("signType", "RSA");
    // Joiner 是 guava提供工具类
    String origStr = Joiner.on("&").withKeyValueSeparator("=").join(paramsMap);
    System.out.println(origStr);
    String sign = "W7ujnhg4B/wGzVbgMHZrUx0YSkGoIoc8edFOB+Mxdq0h/5M93aa4dyTcutHXcUh73H8PEM4oHBB/LbWegP1J8JlI7dwEz2Wf8/8GWs6OBwdrRmS1BRXJTjjpprbKr3vp5JAEu1XU9cNjav/RaiwL66CNsuFZfgYDLVl6mTC5QYI=";

    // 验签算法
    String publicKey = "RSA公钥";
    byte[] keyBytes = Base64Utils.decode(publicKey);
    X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    PublicKey publicK = keyFactory.generatePublic(keySpec);
    Signature signature = Signature.getInstance("SHA1WithRSA");
    signature.initVerify(publicK);
    signature.update(origStr.getBytes());
    boolean verifyFlag = signature.verify(Base64Utils.decode(sign));
    System.out.println(verifyFlag);
}

演示demo:

请求JSON:

{
    "openId":"2398724h98y912",
    "appId":"djgeiq978y933",
    "appName":"2324424214124124",
    "mchId":"93745648",
    "outTradeNo":"hiuhei09023j12j40206",
    "timeStart":"20180801160000",
    "timeExpire":"20180801180000",
    "totalFee":100,
    "notifyUrl":"https://notify.shengpay.com/notify",
    "nonceStr":"pWUVWVYWNQhnTXpQzhIzMGCwqBkZclzg",    
    "goodsTag":"WIFI_DISCOUNT_001",
    "body":"抓娃娃机-游戏充值",
    "detail":"{\"goodsDetails\":[{\"goodsId\":\"goodsId1\",\"goodsName\":\"goodsIName1\",\"price\":100,\"quantity\":1}]}",
    "attach":"{\"memo\":\"test\"}",
    "tradeType":"APP",
    "limitPay":"",
    "signType":"RSA",
    "sign":"W7ujnhg4B/wGzVbgMHZrUx0YSkGoIoc8edFOB+Mxdq0h/5M93aa4dyTcutHXcUh73H8PEM4oHBB/LbWegP1J8JlI7dwEz2Wf8/8GWs6OBwdrRmS1BRXJTjjpprbKr3vp5JAEu1XU9cNjav/RaiwL66CNsuFZfgYDLVl6mTC5QYI="
}

排序拼接后的加签原串:

appId=djgeiq978y933&appName=2324424214124124&attach={"memo":"test"}&body=抓娃娃机-游戏充值&detail={"goodsDetails":[{"goodsId":"goodsId1","goodsName":"goodsIName1","price":100,"quantity":1}]}&goodsTag=WIFI_DISCOUNT_001&mchId=93745648&nonceStr=pWUVWVYWNQhnTXpQzhIzMGCwqBkZclzg&notifyUrl=https://notify.shengpay.com/notify&openId=2398724h98y912&outTradeNo=hiuhei09023j12j40206&signType=RSA&timeExpire=20180801180000&timeStart=20180801160000&totalFee=100&tradeType=APP