This commit is contained in:
tanghc
2020-06-12 08:38:28 +08:00
parent 5f0a1d1a43
commit 0fb884c451
5 changed files with 81 additions and 132 deletions

View File

@@ -1,7 +1,6 @@
package com.gitee.sop.test;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.test.alipay.AlipayApiException;
import com.gitee.sop.test.alipay.AlipaySignature;
import org.junit.Test;
@@ -37,6 +36,8 @@ public class AlipayClientPostTest extends TestBase {
@Test
public void testGet() throws Exception {
// 接口实现见com.gitee.sop.storyweb.controller.AlipayController.getStory
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);
@@ -71,123 +72,4 @@ public class AlipayClientPostTest extends TestBase {
}
// 忽略验证,不校验签名,只需传接口名、版本号、业务参数
@Test
public void testIgnore() {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("method", "story.get");
params.put("version", "2.1");
// 业务参数
Map<String, String> bizContent = new HashMap<>();
bizContent.put("id", "222");
bizContent.put("name", "忽略验证name");
params.put("biz_content", JSON.toJSONString(bizContent));
System.out.println("----------- 返回结果 -----------");
String responseData = post(url, params);// 发送请求
System.out.println(responseData);
}
@Test
public void testStoryget() throws AlipayApiException {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);
params.put("method", "story.get");
params.put("version", "2.2");
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<>();
bizContent.put("id", "222");
bizContent.put("name", "忽略验证22");
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 = post(url, params);// 发送请求
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<>();
bizContent.put("name", "Jim");
bizContent.put("age", "2");
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);
}
@Test
public void testGetJson() throws AlipayApiException {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);
params.put("method", "getJson");
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<>();
bizContent.put("name", "Jim");
bizContent.put("age", "2");
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);
}
}