You've already forked FrameTour-BE
微信退款、退款回调
This commit is contained in:
@ -11,6 +11,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
@ -99,6 +100,7 @@ public class HttpService {
|
||||
HttpGet get = new HttpGet(requestUrl);
|
||||
// 请求首部--可选的,User-Agent对于一些服务器必选,不加可能不会返回正确结果
|
||||
get.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64;rv:39.0) Gecko/20100101 Firefox/39.0");
|
||||
get.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64;rv:39.0) Gecko/20100101 Firefox/39.0");
|
||||
// Exec Request
|
||||
CloseableHttpResponse resp = httpClient.execute(get);
|
||||
// 获得起始行
|
||||
@ -118,4 +120,49 @@ public class HttpService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String doPost(String requestUrl, String jsonData, Map<String, String> headers, String encoding) throws Exception {
|
||||
String result = HttpServiceUtil.REQUEST_NO_RESULT; // 默认返回值
|
||||
CloseableHttpClient httpClient = null;
|
||||
try {
|
||||
// 使用自定义 SSL 工具类创建支持 HTTPS 的 HttpClient
|
||||
httpClient = SslUtil.sslHttpClientBuild();
|
||||
|
||||
// 清理 URL 中的空格字符
|
||||
requestUrl = requestUrl.replaceAll("\\s*", "");
|
||||
HttpPost post = new HttpPost(requestUrl);
|
||||
|
||||
// 设置请求头
|
||||
if (headers != null && !headers.isEmpty()) {
|
||||
for (Map.Entry<String, String> header : headers.entrySet()) {
|
||||
post.setHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置请求体
|
||||
if (jsonData != null) {
|
||||
StringEntity entity = new StringEntity(jsonData, encoding);
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
}
|
||||
|
||||
// 执行请求
|
||||
CloseableHttpResponse response = httpClient.execute(post);
|
||||
|
||||
// 获取响应状态码及响应数据
|
||||
StatusLine status = response.getStatusLine();
|
||||
if (HttpServiceUtil.success(status)) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
result = EntityUtils.toString(entity, encoding);
|
||||
EntityUtils.consume(entity); // 确保释放资源
|
||||
}
|
||||
response.close(); // 关闭响应对象
|
||||
} finally {
|
||||
if (httpClient != null) {
|
||||
httpClient.close(); // 关闭 HttpClient
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user