mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
1.13.5
This commit is contained in:
@@ -111,7 +111,7 @@ public class HttpTool {
|
||||
* @throws IOException
|
||||
*/
|
||||
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
|
||||
Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value());
|
||||
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
|
||||
// 添加header
|
||||
addHeader(requestBuilder, header);
|
||||
|
||||
@@ -153,21 +153,21 @@ public class HttpTool {
|
||||
}
|
||||
}
|
||||
|
||||
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
|
||||
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
|
||||
switch (method) {
|
||||
case "get":
|
||||
case GET:
|
||||
return new Request.Builder()
|
||||
.url(buildHttpUrl(url, form))
|
||||
.get();
|
||||
case "head":
|
||||
case HEAD:
|
||||
return new Request.Builder()
|
||||
.url(buildHttpUrl(url, form))
|
||||
.head();
|
||||
case "put":
|
||||
case PUT:
|
||||
return new Request.Builder()
|
||||
.url(url)
|
||||
.put(buildFormBody(form));
|
||||
case "delete":
|
||||
case DELETE:
|
||||
return new Request.Builder()
|
||||
.url(url)
|
||||
.delete(buildFormBody(form));
|
||||
|
@@ -231,4 +231,35 @@ public class AlipayClientPostTest extends TestBase {
|
||||
System.out.println(responseData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStory2() throws AlipayApiException {
|
||||
// 公共请求参数
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("app_id", appId);
|
||||
params.put("method", "getStory2");
|
||||
params.put("version", "1.0");
|
||||
params.put("format", "json");
|
||||
params.put("charset", "utf-8");
|
||||
params.put("sign_type", "RSA2");
|
||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
// 业务参数
|
||||
Map<String, String> bizContent = new HashMap<>();
|
||||
|
||||
params.put("biz_content", JSON.toJSONString(bizContent));
|
||||
|
||||
System.out.println("----------- 请求信息 -----------");
|
||||
System.out.println("请求参数:" + buildParamQuery(params));
|
||||
System.out.println("商户秘钥:" + privateKey);
|
||||
String content = AlipaySignature.getSignContent(params);
|
||||
System.out.println("待签名内容:" + content);
|
||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8");
|
||||
System.out.println("签名(sign):" + sign);
|
||||
|
||||
params.put("sign", sign);
|
||||
|
||||
System.out.println("----------- 返回结果 -----------");
|
||||
String responseData = get(url, params);// 发送请求
|
||||
System.out.println(responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -49,7 +49,41 @@ public class PostJsonTest extends TestBase {
|
||||
params.put("sign", sign);
|
||||
|
||||
System.out.println("----------- 返回结果 -----------");
|
||||
String responseData = get(url, params);// 发送请求
|
||||
String responseData = postJson(url, params);// 发送请求
|
||||
System.out.println(responseData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostJson2() throws Exception {
|
||||
|
||||
// 公共请求参数
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("app_id", appId);
|
||||
params.put("method", "demo.post.json");
|
||||
params.put("format", "json");
|
||||
params.put("charset", "utf-8");
|
||||
params.put("sign_type", "RSA2");
|
||||
params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
params.put("version", "1.2");
|
||||
|
||||
// 业务参数
|
||||
Map<String, String> bizContent = new HashMap<>();
|
||||
bizContent.put("name", "葫芦娃");
|
||||
|
||||
params.put("biz_content", JSON.toJSONString(bizContent));
|
||||
|
||||
System.out.println("----------- 请求信息 -----------");
|
||||
System.out.println("请求参数:" + buildParamQuery(params));
|
||||
System.out.println("商户秘钥:" + privateKey);
|
||||
String content = AlipaySignature.getSignContent(params);
|
||||
System.out.println("待签名内容:" + content);
|
||||
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8");
|
||||
System.out.println("签名(sign):" + sign);
|
||||
|
||||
params.put("sign", sign);
|
||||
|
||||
System.out.println("----------- 返回结果 -----------");
|
||||
String responseData = postJson(url, params);// 发送请求
|
||||
System.out.println(responseData);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user