查询微信账单接口实现

 /**
  * 查询微信账单
  * @param bill_date 日期   yyyyMMdd
  * @return  结果
  */
 public static List downWxBill(String bill_date)
 {

  String uri = BatchNumber.getValue("wx_uri");//wx_uri=https://api.mch.weixin.qq.com/payx/downxxxx
  String appid = BatchNumber.getValue("wx_appid");//wx_appid=wxc99daxxxxxx
  String bill_type = "ALL";//
  String mch_id = BatchNumber.getValue("wx_mch_id");//wx_mch_id=1x149xxxx
  String nonce_str = RandomStringUtils.randomAlphanumeric(30);
  String key = BatchNumber.getValue("wx_key");//wx_key=rsfg13sxx1g5sr1g65sd123xxxx
  String a = "appid=" + appid + "&bill_date=" + bill_date + "&bill_type="
          + bill_type + "&mch_id=" + mch_id + "&nonce_str=" + nonce_str;

  String signTemp = a + "&key=" + key;
  String sign = DecriptUtil.md5(signTemp).toUpperCase();

  String requestHeader = "application/xml";
  StringBuilder sb = new StringBuilder();
  sb.append("");
  sb.append("" + appid + "");
  sb.append("" + bill_date + "");
  sb.append("" + bill_type + "");
  sb.append("" + mch_id + "");
  sb.append("" + nonce_str + "");
  sb.append("" + sign + "");
  sb.append("");

  String requestBody = sb.toString();

  List brList = new ArrayList();

  try
  {
   String result = HttpClientUtil.postdata(uri, requestHeader,
           requestBody, null);
   System.out.println("time:"
           + DateUtil.getCurrentTimeStringUsingDefaultFormat());
  /* System.out.println("result=" + result);*/

   if (null != result && result.length() > 0)
   {
    String[] resArr = result.split("\n");

    if (resArr.length > 3)
    {
     for (int i = 1; i < resArr.length; i++)
     {
      String consumeStr = resArr[i].replaceAll("`", "");

      String[] consumeArr = consumeStr.split(",");
      if (consumeArr.length > 10)
      {
       // 交易时间
       String trade_time = consumeArr[0];
       // 商户订单号


       String trade_no = consumeArr[6];
       // 交易状态


       String trade_status = consumeArr[9];
       // 总金额


       String trade_money = consumeArr[12];

       BillRecord br = new BillRecord();
       br.setTrade_money(Double.parseDouble(trade_money));
       br.setTrade_no(trade_no);
       br.setTrade_status(trade_status);
       br.setTrade_time(trade_time);

       brList.add(br);

       /*System.out.println();*/
      }

     }

    }

   }

   return brList;

  }
  catch (Exception e)
  {
   e.printStackTrace();
  }

  return brList;

 }

 

你可能感兴趣的:(java)