资源简介
获取微信沙箱操作的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;
//发起post请求,并且获取服务器返回
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);//设置连接主机超时(ms)
coon.setReadTimeout(CONNECT_TIMEOUT);//设置从主机读取数据超时(ms)
if(contentType!=null) {
coon.setRequestProperty(“content_type“ contentType);
}
OutputStreamWriter writer = new OutputStreamWriter(coon.getOutputStream()DEFAULT_ENCODING);//将写入的字符编码成字节后写入一个字节流
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;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1039 2018-10-08 09:31 getSignKey.txt
文件 2098 2018-08-29 09:00 HttpUtil.java
----------- --------- ---------- ----- ----
3137 2
- 上一篇:报警声音大全__WAV
- 下一篇:基于LabVIEW的虚拟振动测试仪
评论
共有 条评论