zoukankan      html  css  js  c++  java
  • WebService

    public String  queryCreditInfo(Parameter parameter, String type)
       throws Exception {
      String jsonResult = null;
      try {
       if ("person".equals(type)) {
        HttpClient http = new HttpClient();
        System.out.println(parameter.getSign("person")); //加密
        String url = "https://www.alit.cn/reportserver/rest/ylService/personReport?name="+URLEncoder.encode(parameter.getName(), "utf-8")+ "&idCard="+ parameter.getIdCard()+ "&card="+ parameter.getCard()+ "&confirmCard="+ parameter.getConfirmCard()+ "&member="+ parameter.getMember()+ "&sign="+parameter.getSign("person");
        Protocol myhttps = new Protocol("https", new MySSL(), 443);
        Protocol.registerProtocol("https", myhttps);
        GetMethod method = new GetMethod(url);
        http.executeMethod(method);
        jsonResult = method.getResponseBodyAsString();
       }else {
        throw new Exception("查询报告类型不能为空");
       } 
      } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      return jsonResult;
     }

    //加密方法

    public String getSign(String type) throws Exception {
      if("person".equals(type)){
        this.sign = Md5.md5(this.getName() + this.getIdCard() + this.getCard()+this.getConfirmCard() + this.getMember() + this.getKey());
       return sign;
      }else if("merchant".equals(type)){
       if(null==this.getBussesCode()||"".equals(this.getBussesCode())){
        this.bussesCode = null;
       }
       if(null==this.getMid()||"".equals(this.getMid())){
        this.mid = null;
       }
       this.sign = Md5.md5(this.getName() + this.bussesCode + this.getMid()+ this.getMember() + this.getKey());
       return sign;
      }else{
       throw new Exception("sign生成错误");
      }
     }

    //MD5加密类

    public class Md5 {  

    private static final String encryModel = "MD5";  

    /**   * md5加密方法   * @param str   * @return   */    

    public static String md5(String str) throws Exception {        

      return md5(encryModel, str.getBytes("utf-8"));    

    }

    public static String md5(String algorithm, byte[] data) {        

      try {            

        MessageDigest md = MessageDigest.getInstance(algorithm);            

        md.update(data);            

        StringBuffer sb = new StringBuffer();            

        byte[] bytes = md.digest();            

        for (int i = 0; i < bytes.length; i++) {                

          int b = bytes[i] & 0xFF;                

          if (b < 0x10) {                    

            sb.append('0');                

          }                

          sb.append(Integer.toHexString(b));            

        }            

      return sb.toString();        

    } catch (Exception e) {            

    return "";        

    }    

    }     

  • 相关阅读:
    从aptitude 换回 apt-get .
    ubuntu 通过安装TOMCAT7
    第一次ubuntu使用的故障排除 ...the public key is not available: NO_PUBKEY...
    DES加密算法应用:分组加密模式
    使用“牛顿迭代法”求解方程
    html当中如何引用js文件
    javascript当中火狐的firebug如何单步调试程序?
    给出一个javascript的Helloworld例子
    java中讲讲PrintWriter的用法,举例?
    卷积和神经网络有什么关系?
  • 原文地址:https://www.cnblogs.com/Defry/p/4607641.html
Copyright © 2011-2022 走看看