Exemple #1
0
  /**
   * 是否财付通签名,规则是:按参数名称a-z排序,遇到空值的参数不参加签名。
   *
   * @return boolean
   */
  public boolean isTenpaySign() {
    StringBuffer sb = new StringBuffer();
    Set es = this.parameters.entrySet();
    Iterator it = es.iterator();
    while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      String k = (String) entry.getKey();
      String v = (String) entry.getValue();
      if (!"sign".equals(k) && null != v && !"".equals(v)) {
        // if(!k.equals("PcacheTime")){
        sb.append(k + "=" + v + "&");
        // }
      }
    }

    sb.append("key=" + this.getKey());

    // 算出摘要
    String enc = TenpayUtil.getCharacterEncoding(this.request, this.response);
    String sign = MD5Util.MD5Encode(sb.toString(), enc).toLowerCase();

    String tenpaySign = this.getParameter("sign").toLowerCase();

    // debug信息
    this.setDebugInfo(sb.toString() + " => sign:" + sign + " tenpaySign:" + tenpaySign);

    return tenpaySign.equals(sign);
  }
Exemple #2
0
  /**
   * 设置uri编码
   *
   * @param uriEncoding
   * @throws UnsupportedEncodingException
   */
  public void setUriEncoding(String uriEncoding) throws UnsupportedEncodingException {
    if (!"".equals(uriEncoding.trim())) {
      this.uriEncoding = uriEncoding;

      // 编码转换
      String enc = TenpayUtil.getCharacterEncoding(request, response);
      Iterator it = this.parameters.keySet().iterator();
      while (it.hasNext()) {
        String k = (String) it.next();
        String v = this.getParameter(k);
        v = new String(v.getBytes(uriEncoding.trim()), enc);
        this.setParameter(k, v);
      }
    }
  }