public static TreeMap<String, String> unifiedorder(
     String body, String ip, String total_fee, String out_trade_no)
     throws URIException, UnsupportedEncodingException {
   TreeMap<String, String> paramsMap = new TreeMap<String, String>();
   TreeMap<String, String> resultMap = new TreeMap<String, String>();
   String nonce_str = System.currentTimeMillis() + "";
   // 统一下单
   paramsMap.put("appid", appid);
   paramsMap.put("body", body); // 商品描述
   paramsMap.put("mch_id", mch_id);
   paramsMap.put("nonce_str", nonce_str); // 随机字符串
   paramsMap.put("notify_url", notify_url); // 通知地址
   paramsMap.put("out_trade_no", out_trade_no); // 商户订单号
   paramsMap.put("spbill_create_ip", ip); // 终端IP
   paramsMap.put("total_fee", total_fee); // 总金额
   paramsMap.put("trade_type", "APP"); // 交易类型
   String xml = sendPost(paramsMap, key, unifiedorder);
   ReceiveXmlEntity xmlEntity = new ReceiveXmlProcess().getMsgEntity(xml);
   if ("FAIL".equals(xmlEntity.getReturn_code())) return resultMap;
   // 调起支付 返回app端参数
   resultMap.put("appid", appid);
   resultMap.put("partnerid", mch_id); // 商户号
   resultMap.put("prepayid", xmlEntity.getPrepay_id()); // 统一下单返回回话Id
   resultMap.put("package", "Sign=WXPay"); // 暂时固定值
   resultMap.put("noncestr", nonce_str); // 随机字符串,不长于32位
   resultMap.put("timestamp", nonce_str); // 时间戳
   String paramsStr = toQueryString(resultMap);
   resultMap.put("sign", MD5(paramsStr).toUpperCase()); // 签名
   return resultMap;
 }
 public static void main(String[] args) throws Exception {
   TreeMap<String, String> paramsMap = new TreeMap<String, String>();
   TreeMap<String, String> resultMap = new TreeMap<String, String>();
   String nonce_str = System.currentTimeMillis() + "";
   // 统一下单
   // String app = ConfigUtil.getConfigParam("WX.APPID");
   paramsMap.put("appid", "wx210fd7c732469f74");
   paramsMap.put("body", "app测试第二次"); // 商品描述
   paramsMap.put("mch_id", "1259144401");
   paramsMap.put("nonce_str", nonce_str); // 随机字符串
   paramsMap.put(
       "notify_url", "http://101.200.231.150:8080/flowers/customer/async_inform.do"); // 通知地址
   paramsMap.put("out_trade_no", nonce_str); // 商户订单号
   paramsMap.put("spbill_create_ip", "10.10.11.240"); // 终端IP
   paramsMap.put("total_fee", "1"); // 总金额
   paramsMap.put("trade_type", "APP"); // 交易类型
   String xml =
       sendPost(
           paramsMap,
           "92529b042a053742dd38a899802544c6",
           "https://api.mch.weixin.qq.com/pay/unifiedorder");
   ReceiveXmlEntity xmlEntity = new ReceiveXmlProcess().getMsgEntity(xml);
   if ("FAIL".equals(xmlEntity.getReturn_code())) return;
   System.out.println(
       "返回结果 " + xmlEntity.getReturn_code() + " prepay_id  " + xmlEntity.getPrepay_id());
   // 调起支付 返回app端参数
   resultMap.put("appid", "wx210fd7c732469f74");
   resultMap.put("partnerid", "1259144401"); // 商户号
   resultMap.put("prepayid", xmlEntity.getPrepay_id()); // 统一下单返回回话Id
   resultMap.put("package", "Sign=WXPay"); // 暂时固定值
   resultMap.put("noncestr", nonce_str); // 随机字符串,不长于32位
   resultMap.put("timestamp", nonce_str); // 时间戳
   String paramsStr = toQueryString(resultMap);
   System.out.println(paramsStr);
   paramsMap.put("sign", MD5(paramsStr).toUpperCase()); // 签名
 }
 /**
  * 微信支付 异步通知商户支付结果
  *
  * @param request
  * @param response
  * @param out
  * @return
  * @throws Exception
  */
 @HttpListening(urlPattern = "/customer/async_inform.do", isCheckSession = true)
 public Response async_inform(
     HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception {
   // 请求返回的数据
   InputStream in = request.getInputStream();
   byte[] data1 = new byte[in.available()];
   in.read(data1);
   // 转成字符串
   String xml = new String(data1);
   log.info(" 微信返回信息 :" + xml);
   ReceiveXmlEntity xmlEntity = new ReceiveXmlProcess().getMsgEntity(xml);
   if ("FAIL".equals(xmlEntity.getReturn_code())) return Response.stationary("异步通知失败");
   StringBuilder sb = new StringBuilder("<xml>").append("\n");
   sb.append("<return_code><![CDATA[SUCCESS]]></return_code>");
   sb.append(" <return_msg><![CDATA[OK]]></return_msg>");
   sb.append("</xml>");
   // 查询此数据是否被接受处理过
   Session session = HibernateSessionFactory.getSession();
   Query query =
       session
           .createSQLQuery(
               "select * from "
                   + Transactionwx.class.getSimpleName()
                   + " where openid=? and out_trade_no=?")
           .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
           .setString(0, xmlEntity.getOpenid())
           .setString(1, xmlEntity.getOut_trade_no());
   List list = query.list();
   if (list != null || list.size() > 0) { // 被处理过的数据
     return Response.stationary(sb);
   }
   // 没有处理过存储数据       支付成功修改订单号
   if ("SUCCESS".equals(xmlEntity.getReturn_code())) {
     Transactionwx transaction = new Transactionwx();
     transaction.openid = xmlEntity.getOpenid();
     transaction.bank_type = xmlEntity.getBank_type();
     transaction.cash_fee = xmlEntity.getCash_fee();
     transaction.coupon_count = xmlEntity.getCoupon_count();
     transaction.coupon_fee = xmlEntity.getCoupon_fee();
     transaction.coupon_fee_$n = xmlEntity.getCoupon_fee_$n();
     transaction.out_trade_no = xmlEntity.getOut_trade_no();
     transaction.total_fee = xmlEntity.getTotal_fee();
     transaction.transaction_id = xmlEntity.getTransaction_id();
     Transaction t = session.beginTransaction();
     session.save(transaction);
     t.commit();
     // 修改订单状态
     String id = xmlEntity.getOut_trade_no();
     String _id = id.substring(0, 1);
     if ("j".equals(_id)) { // 竞价单  修改我的花仓
       // 得到竞价用户  和  商品实体id
       Map<String, Object> entityIdAndUid = CustomerGoodsAuctionBidHelper.getEntityIdAndUid(id);
       GoodsEntity goodEntity = new GoodsEntity();
       goodEntity.id = entityIdAndUid.get("goodsAcutionId").toString();
       goodEntity.uid = entityIdAndUid.get("uid").toString();
       t = session.beginTransaction();
       session.update(goodEntity);
       t.commit();
     }
     if ("o".equals(_id)) { // 修改订单单
       GoodsOrder order = new GoodsOrder();
       order.orderid = id;
       order.state = OrderState.getEnum(2);
       t = session.beginTransaction();
       session.update(order);
       t.commit();
     }
   }
   return Response.stationary(sb);
 }