1:首先你先下载好自己的软件 支付宝开放平台 2去支付宝开放平台申请自己的沙箱环境 3下载花生壳,内网穿透 4手机安装客户端调试工具 接下来去申请自己的沙箱环境 1首先进入到支付宝官方网页 2,入驻登入一下 3登入进来后选择这个 4进入到这后就差不多了 5打开你的支付宝开放平台开发助手生成私钥和公钥、
6复制公钥到这里生成应用公钥 现在环境基本上搭好了,现在去操作一波 引入pom依赖
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>ytzl</groupId> <artifactId>true_2020-8-28</artifactId> <version>0.0.1-SNAPSHOT</version> <name>true_2020-8-28</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java --> <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>4.10.111.ALL</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> package ytzl.true_2020828.controller; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; import com.alipay.api.domain.AlipayTradeAppPayModel; import com.alipay.api.request.AlipayTradeAppPayRequest; import com.alipay.api.response.AlipayTradeAppPayResponse; /** * 作者: XiaoGan * 时间: 2020/8/28 17:03 * 描述: */ public class AliPayController { /** * APP_ID 应用id */ private final static String APP_ID = ""; /** * 应用私钥 */ private final static String APP_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCh/+uuSen65VGO0MiaAljqgSMzofWMLtNPnelVLHr6ap3ERzI+rLT7YRwXNm9sQr66wgN0+JssimsdaT33v+djQYRLpZBCKcW5nv1qUit7NJe4WGYVmqdEl/8aD0PuTaDH2hNPWOuG+qWP/YnsinMvhJGjOEJmdMQnqDc1kTl/RYKSOuqpgQj7jf/z+Lldy4jXNfKoxgXrE1sfymYtvZoCKeswcm7EGBbIwfxaRDs2iRUNDPoheJlFq9dgyHESyCeDmfYirCYtO+91pMEj5igFo7m+4YKYsacRebEgKfpaza7FdMjtbBsnTEtybySkT+40ya0nza8VdUvpHtu4azezAgMBAAECggEAPme1xHgYuFvqZResjxdkZUHF67fyPUQ0hrEQF42A+kJj8B51Dou9VDD+fzqrBYtYqdzfNAoozKmtxbCq/GtimWu9qN5oifRJhM3oVTK+KUIDSDJVcPEYimX7EXDb/ErPKu2pDqH0aRTY/nTu0r4qzR1GdRfRDGLixVwZmHsPKSVf6r3c3BzOup2B4GqK0i5/Oj02ewRAqOuY9BfL4UvIg16ZKZzT72udkwBuQsCRUDYjrMQz6pYwCc6tcF+eYxuD//k8lNmR4FHzcldmAiP+cXrP4D/+t17wLa365P3BXoZsUgQAwp4FInxZinTbeOjyAD+jx7Nxks8ZqQCqX9+q8QKBgQD27zbMNuukYbL2Hg56gJiP6ibQR7BEsq++VGjKzpx+oieEg8s/IJewARCdtHQtprn7Q9L4jXxU3us/aSp30jgLSpn3pwjM1BvUpRwHQKv12Mdom1KJuxoKnu63dhBNTZFkH4SQUXv6eQrFqeDVmX6c6Vw3fS/WRzEAFh5hCTPc3QKBgQCn8nTxbN4rwsJFYTeVJmXsPkcfDQkP/3WVDOuI0v6xZeZT2h8114u1N/HuCeiXdfotcuoNwjQXyNI+yJN17dHZI+AgvFn3jpYedkw/DbwwDRa1+5ZImC0AXObrwzNtsVjRTk2lLy+1mEb1HWe8b/O0NeS1VV2QtMmn1eYPZTuVzwKBgQDo8rguJG1eEHCkb6xW8nN56HmfKNHnrO3Pzo9hK1JEwDIpd69IKTYP6qFDNRYYbt2qZMxkgAzXf8hLdKmEicMnG8Rt9Zx+pmZuzyfGy8KtVUigrU5K8j/Z3x7x4aX1VwSegIEtKEGeA4we9mhM+NWRry+4hReYvGZEX5lfDzBm3QKBgD5dOi+sTZPSbnF0+D7aU162gZJ2NLdMFU2TzqKwNwOI406f4JcNw0M30w6hf00+8feOhHs3ckCiwe+ua5OPDC2ltMRzLLVQrU4Cf62qXAc71QMeuV+boppP5TAG/EHvaRvQB+Ue8IhuU2sR0EOZDtYMbTEo0eW6PGemdhehb87hAoGANP7Lj+QFVsgvr6LrVDE3C67DeoFvWkHJ910NG0lqFCwShz8zlV5BdwCg4vghM1TmTkeAWsrB7cL9byAYoj2POxTthFy8sp36hOya9GfmfhVi3wHpyGmlh3YGSY7l75iGmlrsxgSXDIe4Grk9iY0p3QAqn8zxC58JgXUAB/TUZOs="; /** * 编码 */ private final static String CHARSET = "UTF-8"; /** * 支付宝公钥 */ private final static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAliIrxWKPl2EU542Z3a6anCLxPFvri5OUAztESwu1o8G3uKrl1wXFApDJzju0RoaCb2m+k8xhX3ScATp/u6VNhpnwvWS6LYOVB75IBnpbmwe32261SNoS54sOU1LBWCvy5Urzg01AJkRniNl0eG4ATjjM5hMBVyJcbVhIWb9582OkEpCaQicEOv/whnU5J8VHbRDvCA9Ga7JjlY8DVq9u4Aa4FYwxcAtIV2zK+B8pcNqfYI/uWGG1JXq/PwK3n7S2X+m8213/dlF/jV1QzO8GS3dJVoXoM1DASLKpnMld2Ts6iFluMfsMEvWI1kzWAUPhXA9NUYeQbvt27aSq+whvhwIDAQAB"; /* * 沙箱网关 */ private final static String GATEWAY_URL = ""; /** * 格式化 */ private final static String FORMAT = "json"; /** * 签名类型 */ private final static String SIGN_TYPE = "RSA2"; /** * 获取订单信息 */ public void getOrderInfo() { //实例化客户端 AlipayClient alipayClient = new DefaultAlipayClient(GATEWAY_URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE); //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); model.setBody("支付宝充值"); model.setSubject("官方特惠李白凤求凰"); model.setOutTradeNo("product_sh_20200709638820390"); model.setTimeoutExpress("30m"); model.setTotalAmount("168"); model.setProductCode("QUICK_MSECURITY_PAY"); request.setBizModel(model); request.setNotifyUrl("商户外网可以访问的异步地址"); try { //这里和普通的接口调用不同,使用的是sdkExecute AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。 } catch (AlipayApiException e) { e.printStackTrace(); } } public static void main(String[] args) { AliPayController aliPayController = new AliPayController(); aliPayController.getOrderInfo(); } }接下来你按照上面的修改就是了
私钥就是你开放平台助手生成的 公钥就是你在沙箱环境哪里生成的
将控制台生成的这串代码复制下来 代码放到你的小冰棒也就是你的客户端调试工具上 你的账号密码是这个 然后支付就行了 在你的沙箱支付宝可以看到详情 因为本人初学没多久,因此暂时只能搞这么简单的,觉得不过瘾的可以去看一下大神的