資源簡(jiǎn)介
獲取微信沙箱操作的key,代碼中返回的沙箱key值替換原有的key做簽名就可以了,下載后有不清楚的可以私我

代碼片段和文件信息
package?test;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStreamReader;
import?java.io.OutputStreamWriter;
import?java.net.HttpURLConnection;
import?java.net.URL;
import?java.net.URLConnection;
//發(fā)起post請(qǐng)求,并且獲取服務(wù)器返回
public?class?HttpUtil?{
private?final?static?int?CONNECT_TIMEOUT?=?5000;//
private?final?static?String?DEFAULT_ENCODING=“UTF-8“;
public?static?String?postData(String?urlStrString?data)?{
return?postData(urlStr?datanull);
}
public?static?String?postData(String?urlStrString?dataString?contentType)?{
BufferedReader?reader?=?null;
try?{
URL?url?=?new?URL(urlStr);
// URLConnection?coon?=url.openConnection();
HttpURLConnection?coon?=?(HttpURLConnection)?url.openConnection();
coon.setRequestMethod(“POST“);
coon.setDoOutput(true);//為true后可使用.getOutputStrean
coon.setConnectTimeout(CONNECT_TIMEOUT);//設(shè)置連接主機(jī)超時(shí)(ms)
coon.setReadTimeout(CONNECT_TIMEOUT);//設(shè)置從主機(jī)讀取數(shù)據(jù)超時(shí)(ms)
if(contentType!=null)?{
coon.setRequestProperty(“content_type“?contentType);
}
OutputStreamWriter?writer?=?new?OutputStreamWriter(coon.getOutputStream()DEFAULT_ENCODING);//將寫入的字符編碼成字節(jié)后寫入一個(gè)字節(jié)流
if(data==null)?{
data=““;
}
writer.write(data);
writer.flush();
writer.close();
reader?=?new?BufferedReader(new?InputStreamReader(coon.getInputStream()?DEFAULT_ENCODING));//緩沖字符輸入流
StringBuilder?sb?=?new?StringBuilder();
String?line?=?null;
while((line?=?reader.readLine())!=null)?{
sb.append(line);
sb.append(“\r\n“);
}
return?sb.toString();
}catch?(IOException?e)?{??
????????????//logger.error(“Error?connecting?to?“?+?urlStr?+?“:?“?+?e.getMessage());?
e.printStackTrace();
????????}?finally?{??
????????????try?{??
????????????????if?(reader?!=?null)??
????????????????????reader.close();??
????????????}?catch?(IOException?e)?{??
????????????}??
????????}??
????????return?null;??
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????1039??2018-10-08?09:31??getSignKey.txt
?????文件???????2098??2018-08-29?09:00??HttpUtil.java
-----------?---------??----------?-----??----
?????????????????3137????????????????????2
評(píng)論
共有 條評(píng)論