zoukankan      html  css  js  c++  java
  • 微信支付

    public WeChatPayResponseData placeOrder(final WeChatPayRequestData request) {
        OneLevelOnlyXML xml = new OneLevelOnlyXML();
        xml.createRootElement("xml");
        for (StringPair param : sign(request.getSortedParameters())) {
          xml.createChild(param.getFirst(), param.getSecond());
        }
        String str = xml.toXMLString();
        LOG.info("Order request: {}", str);
        String ret = http.post("api.mch.weixin.qq.com", 443, "https", "/pay/unifiedorder", str);
        LOG.info("Order response: {}", ret);
        try {
          WeChatPayResponseData response = WeChatPayResponseData.parse(ret);
          String sign = signMD5(response.getAllData().getSorted("sign"));
          if (!sign.equalsIgnoreCase(response.getString("sign"))) {
            LOG.warn("Failed to verify sign");
            return null;
          }
          if (!"SUCCESS".equalsIgnoreCase(response.getString("return_code"))
              || !"SUCCESS".equalsIgnoreCase(response.getString("result_code"))) {
            LOG.warn("Error returned {}", response.getString("return_msg"));
            return null;
          }
          // return response.getString("prepay_id");
          response.setXml(ret);
          return response;
        } catch (UnsupportedEncodingException e) {
          LOG.warn("Cannot parse result", e);
          return null;
        } catch (ParserConfigurationException e) {
          LOG.warn("Cannot parse result", e);
          return null;
        } catch (SAXException e) {
          LOG.warn("Cannot parse result", e);
          return null;
        } catch (IOException e) {
          LOG.warn("Cannot parse result", e);
          return null;
        }
      }
  • 相关阅读:
    2016 Multi-University Training Contest 5 ATM Mechine
    2016 Multi-University Training Contest 5 Divide the Sequence
    UVA 10082 WERTYU
    UVA 272 TEX Quotes
    紫书理解
    Codeforces Round #363 (Div. 2) One Bomb
    BestCoder Round #85 hdu5778 abs(素数筛+暴力)
    计算几何模板
    BestCoder Round #85 hdu5777 domino
    BestCoder Round #85 hdu5776 sum
  • 原文地址:https://www.cnblogs.com/wjlstation/p/5973932.html
Copyright © 2011-2022 走看看