zhiqiang9267
鸿蒙道
2017-04-05 04:36

微信支付返回xml格式错误

  • 支付
  • xml
  • 微信

微信支付统一下单返回

 <xml><return_code><![CDATA[FAIL]]></return_code>
           <return_msg><![CDATA[XML格式错误]]></return_msg>
           </xml>

,如何解决,我是用 public static byte[] httpPost(String url, String entity) {
if (url == null || url.length() == 0) {

        return null;
    }

    HttpClient httpClient = getNewHttpClient();

    HttpPost httpPost = new HttpPost(url);



    try {
        httpPost.setEntity(new StringEntity(entity));
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");

        HttpResponse resp = httpClient.execute(httpPost);
        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {

            return null;
        }

        return EntityUtils.toByteArray(resp.getEntity());
    } catch (Exception e) {

        e.printStackTrace();
        return null;
    }
}

private static HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

访问微信的api的,请大神帮忙。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐