Home > front end >  WeChat public pay order with unified interface docking, httpsRequest reads the result is null
WeChat public pay order with unified interface docking, httpsRequest reads the result is null

Time:10-22

Private static StringBuffer httpsRequest (String requestUrl,
String requestMethod, String output) {

StringBuffer buffer=new StringBuffer ();

System. The out. Println (" -- -- -- -- -- -- -- -- httpsRequest -- -- -- -- -- -- -- -- ");

Try {
//create the SSLContext object, and use our designated trust manager initialization
TrustManager [] tm={new MyX509TrustManager ()};
SSLContext SSLContext=SSLContext. GetInstance (" SSL ", "SunJSSE");
SslContext. Init (null, tm, new Java. Security. SecureRandom ());
//from the SSLContext object SSLSocketFactory objects
SSLSocketFactory SSF=sslContext. GetSocketFactory ();

URL the URL=new URL (requestUrl);
HttpsURLConnection httpUrlConn url=(HttpsURLConnection)
The openConnection ();
HttpUrlConn. SetSSLSocketFactory (SSF);

HttpUrlConn. SetDoOutput (true);
HttpUrlConn. SetDoInput (true);
HttpUrlConn. SetUseCaches (false);
//set the request (GET/POST)
HttpUrlConn. SetRequestMethod (requestMethod);

If (" POST ". EqualsIgnoreCase (requestMethod))
HttpUrlConn. The connect ();

//when data needs to be submitted when
if (null !=the output) {
OutputStream OutputStream=httpUrlConn. GetOutputStream ();
//note that coding format, to prevent Chinese garbled
OutputStream. Write (output. GetBytes (" utf-8 "));
OutputStream. Close ();
}

//returns the input stream into a string
InputStream InputStream=httpUrlConn. GetInputStream ();
InputStreamReader InputStreamReader=new InputStreamReader (
InputStream, "utf-8");
BufferedReader BufferedReader=new BufferedReader (
InputStreamReader);

String STR=null;
While ((STR=bufferedReader readLine ())!=null) {
buffer.append(str);
}
BufferedReader. The close ();
InputStreamReader. Close ();
//release resources
inputStream.close();
InputStream=null;
HttpUrlConn. Disconnect ();

System. The out. Println (" -- -- -- -- -- - the buffer -- -- -- -- -- - ");
System. The out. Println (buffer. The toString ());
{} the catch (ConnectException ce)
Ce. PrintStackTrace ();
} the catch (Exception e) {
e.printStackTrace();
}
The return buffer;
}



String requestUrl="https://api.mch.weixin.qq.com/pay/unifiedorder";
String requestMethod="POST";
String output=


Buffer to null is going on?

CodePudding user response:

Online, etc., have a great spirit passing

CodePudding user response:

In the same reservation method to add a
"
String reqXml=util. XSteram. Xstream. ToXML (pay);
ReqXml=reqXml. ReplaceAll (" (", "_");
"
XML format is wrong, tags in the middle of the long ___ obviously
  • Related