// 对返回来的数据进行加密,并且和传过来的密文进行比较,如果OK则说明数据没有被篡改 public boolean checkBackData(BackData backData) { String joinParam = this.joinBackDataParam(backData); // 加密后得到自己的密文 String md5 = DigestUtil.hmacSign(joinParam.toString(), YeepayConfig.key); // 密文和传过来密文比较 return md5.equals(backData.getHmac()); }
public Map<String, Object> saveDataToRequest(Map<String, Object> request, SendData sendData) { // 返回了被追加的字符串 String joinParam = joinSendDataParam(sendData); // 把明文与密文都存储到相应的requestMap中 request.put("p0_Cmd", sendData.getP0_Cmd()); request.put("p1_MerId", sendData.getP1_MerId()); request.put("p2_Order", sendData.getP2_Order()); request.put("p3_Amt", sendData.getP3_Amt()); request.put("p4_Cur", sendData.getP4_Cur()); request.put("p5_Pid", sendData.getP5_Pid()); request.put("p6_Pcat", sendData.getP6_Pcat()); request.put("p7_Pdesc", sendData.getP7_Pdesc()); request.put("p8_Url", sendData.getP8_Url()); request.put("p9_SAF", sendData.getP9_SAF()); request.put("pa_MP", sendData.getPa_MP()); request.put("pd_FrpId", sendData.getPd_FrpId()); request.put("pr_NeedResponse", sendData.getPr_NeedResponse()); request.put("hmac", DigestUtil.hmacSign(joinParam, YeepayConfig.key)); return request; }
public SendData saveData(SendData sendData) { // 返回了被追加的字符串 String joinParam = joinSendDataParam(sendData); sendData.setHmac(DigestUtil.hmacSign(joinParam, YeepayConfig.key)); return sendData; }