添加获取微店订单和修改发货状态

This commit is contained in:
mass
2026-05-17 16:15:48 +08:00
parent f4fce5a363
commit 8b16d70259
10 changed files with 550 additions and 0 deletions
@@ -6,9 +6,11 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
@@ -203,6 +205,84 @@ public class HttpUtils
return result.toString();
}
/**
* 向指定 URL 发送POST方法的请求,支持自定义请求头。
*
* @param url 发送请求的 URL
* @param param 请求参数,application/x-www-form-urlencoded 格式
* @param headers 自定义请求头,key 为 Header 名称,value 为 Header 值
* @return 响应结果字符串,请求失败时返回空字符串
*/
public static String sendPostWithHeaders(String url, String param, Map<String, String> headers)
{
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try
{
log.info("sendPostWithHeaders - {}", url);
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
if (headers != null)
{
for (Map.Entry<String, String> entry : headers.entrySet())
{
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = in.readLine()) != null)
{
result.append(line);
}
log.info("recv - {}", result);
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendPostWithHeaders ConnectException, url=" + url, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendPostWithHeaders SocketTimeoutException, url=" + url, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendPostWithHeaders IOException, url=" + url, e);
}
catch (Exception e)
{
log.error("调用HttpUtils.sendPostWithHeaders Exception, url=" + url, e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
if (in != null)
{
in.close();
}
}
catch (IOException ex)
{
log.error("调用in.close Exception, url=" + url, ex);
}
}
return result.toString();
}
public static String sendSSLPost(String url, String param)
{
return sendSSLPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);