From 3d906b5f7faf8b5bb3676b7d53d5da80d28e91af Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 27 Dec 2019 11:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitee/sop/test/AlipayToolPKCS1Test.java | 64 +++++++++++++++++++ .../gitee/sop/test/AlipayToolPKCS8Test.java | 64 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS1Test.java create mode 100644 sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS8Test.java diff --git a/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS1Test.java b/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS1Test.java new file mode 100644 index 00000000..86be80e7 --- /dev/null +++ b/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS1Test.java @@ -0,0 +1,64 @@ +package com.gitee.sop.test; + +import com.alibaba.fastjson.JSON; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * 使用支付宝工具生成签名,这里演示的是PKCS1(非java) + */ +public class AlipayToolPKCS1Test extends TestBase { + + String url = "http://localhost:8081"; + String appId = "201904035630907729292csharp"; + // 平台提供的私钥 + String privateKey = "MIIEowIBAAKCAQEA5+OvJxeSzf44NxQ/cl7Ii+BzPg2k6sRcvH4ffOtU5Dzq1/oEvg02nxIhmwOHBZmjbmuUu0aLsfglUTAwqfXftfAKZidshsgj9NNh0/kxk0avRZ1UoljWGz/FxVZA0ogbxxhohPZ9jWcD+eBQcIwF2DtHfAJqWWZrYFnCMeHD8mPzxo2kwXSvDzi0vf9I2tKiYvNG26a9FqeYtPOoi81sdS3+70HOMdxP8ejXtyfnKpKz7Dx506LCIRS5moWS3Q5eTLV3NGX/1CSJ8wpQA2DAQTjVhX5eVu7Yqz12t8W+sjWM/tHUR6cgwYYR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WQKBgEHRxrmER7btUF60/YgcqPHFc8RpYQB2ZZE0kyKGDqk2Data1XYUY6vsPAU28yRLAaWr/D2H17iyLkxP80VLm6QhifxCadv90Q/Wl1DFfOJQMW6avyQ0so6G0wFq/LJxaFK4iLXQn1RJnmTp6BYiJMmK2BhFbRzw8ssMoF6ad2rr"; + + // 公共请求参数 + Map params = new HashMap(); + + { + params.put("app_id", appId); + params.put("method", "alipay.story.get"); + params.put("format", "json"); + params.put("charset", "utf-8"); + params.put("sign_type", "RSA2"); + // 手动改下这里的时间,改成当前时间 + params.put("timestamp", "2019-12-28 11:23:29"); + params.put("version", "1.0"); + + // 业务参数 + Map bizContent = new HashMap<>(); + bizContent.put("id", "1"); + bizContent.put("name", "葫芦娃"); + + params.put("biz_content", JSON.toJSONString(bizContent)); + } + + /** + * 第一步:生成请求参数。 + * 生成后的字符串放到支付宝工具【请求参数】中,将上面的privateKey放到【商户应用私钥】中 + * 点击【开始签名】 + */ + @Test + public void testFirst() { + System.out.println("请求参数:"); + System.out.println(buildParamQuery(params)); + } + + /** + * 第二步:将生成到签名放到sign变量中,然后运行本方法 + */ + @Test + public void testSecond() { + String sign = "sOK1Kwoq6OmjFoneb6LRgUpX+/uQ9D9gsV1Cgi6aw/ErUWLYqMkESuJ148uV1rk5ms8ok9n4T4LpM7aJEYLo9IguW5eVCQ+ePe3ea6gjEQIZm2fiymfSdasSrrBDN/oLqhFwWRGzTQ5TWAgxpNCLH2zKMc+Z5ir7W6xeA0CcEmhZYXC3fB4MSnPcCbHj4V0LLAoQZZQ3voHpdh+6OYNzMKcrwJTTbukI6LbVPopO44ZanV11ehytKLJB71wGJlvFIMK+N3Gph01JKFvfzOlMmndGiDodOjgSz+aQBIjlcyCea/PXSzr2fa5efvWDX/5QayhWkWQ3/1ocBMj7/d4pMA=="; + // 这里用支付宝工具生成 + params.put("sign", sign); + System.out.println("----------- 返回结果 -----------"); + String responseData = get(url, params);// 发送请求 + System.out.println(responseData); + } + +} diff --git a/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS8Test.java b/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS8Test.java new file mode 100644 index 00000000..bf4a23c0 --- /dev/null +++ b/sop-test/src/test/java/com/gitee/sop/test/AlipayToolPKCS8Test.java @@ -0,0 +1,64 @@ +package com.gitee.sop.test; + +import com.alibaba.fastjson.JSON; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * 使用支付宝工具生成签名,这里演示的是PKCS8(java) + */ +public class AlipayToolPKCS8Test extends TestBase { + + String url = "http://localhost:8081"; + String appId = "2019032617262200001"; + // 平台提供的私钥 + String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; + + // 公共请求参数 + Map params = new HashMap(); + + { + params.put("app_id", appId); + params.put("method", "alipay.story.get"); + params.put("format", "json"); + params.put("charset", "utf-8"); + params.put("sign_type", "RSA2"); + // 手动改下这里的时间,改成当前时间 + params.put("timestamp", "2019-12-28 11:23:29"); + params.put("version", "1.0"); + + // 业务参数 + Map bizContent = new HashMap<>(); + bizContent.put("id", "1"); + bizContent.put("name", "葫芦娃"); + + params.put("biz_content", JSON.toJSONString(bizContent)); + } + + /** + * 第一步:生成请求参数。 + * 生成后的字符串放到支付宝工具【请求参数】中,将上面的privateKey放到【商户应用私钥】中 + * 点击【开始签名】 + */ + @Test + public void testFirst() { + System.out.println("请求参数:"); + System.out.println(buildParamQuery(params)); + } + + /** + * 第二步:将生成到签名放到sign变量中,然后运行本方法 + */ + @Test + public void testSecond() { + String sign = "Wt80mV3ojQ4++19yUhG1pjElGc5rWRJ0udoPv6yHjDG9h0Ai8/sQx9XaWBfiPR3YU6ZzTznr1gEYeXpJg3X9ptLjkMG3xx5NRkCMTYi9eZ40c8RU13O/mQDDr8can59jYgG3PUCTBSpymBnZsTxAzCuho3p26vm64napu+XlKiWEU1yQz46Ga8hW9EBRFFBWvwSsXqp0ZUuddXIj4nhuRr/miSsGgtGXByRMgOh+FLivZnIZJmjP1fS3Veq4Qp2Pv/V+7r+3DBBclos2OF72O1lrALWA8qrHhyjWyFPuNJv6b7PA0vKUenthSPeKH1qJTmMIqlokRrrrD5Ubt1pDJg=="; + // 这里用支付宝工具生成 + params.put("sign", sign); + System.out.println("----------- 返回结果 -----------"); + String responseData = get(url, params);// 发送请求 + System.out.println(responseData); + } + +}