1.你应该知道的前提知识1.1沙箱环境
沙箱环境 (Beta) 是支付宝开放平台为您提供的与线上环境完全隔离的联调测试环境,在沙箱环境中完成的调用不会对线上数据造成任何影响,尤其适合涉及资金链路的能力的调试。
1.2 配置沙箱应用环境
开放平台-沙箱环境 (alipay.com)
使用支付宝,扫描后,进行简单用户注册
使用开发者账号登录 开放平台控制台 > 开发服务,(用支付宝扫码,授权登录,然后根据页面输入注册信息)
输入注册后,即可点击 研发服务 即可进入 沙箱环境。
1.3 三个重要的信息
商户UID,公钥 ,私钥,程序中需要使用:
点击3 可以看公私匙
![](支付宝支付的开发步骤.assets/image-20211203204239614.png
2.创建maven web项目
以商品购买为例演示,请忽略页面样式效果
3.额外添加依赖包
配置类,用来封装支付宝的三个重要信息: 商户UID,公钥 ,私钥
package com.bobo.utils;public class AlipayConfig {public static String app_id = "20210118*****";//uidpublic static String merchant_private_key = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCckRs3v/nnhbjyg3obpNuf+r9a7VvmVpj0pc/z4WiF001xSxSqA2WLL5SF2xvfsVqc0LifTu0yQwFGtsgOrEN62LNmObcNr1gJPN6DVWrL8+BritRc0/VukaHx6YbXM90NvUv6Or/rOVoH6hXHICaBOC1dxHo8yXXk4w58EtBSAuTMOTaO1zHNnb3gSO0VtjF0MIMpWG1cBUVKFWihD6+BVen3CVrtIVc9yv4PtLCNviOMiVX3a7bU3jwYrhov2RZmPHdaNNMFICioGgdOUtufMxrstk6UdtjUV07EKqRcpilJIm2r4ZPAgiYVAB69WyZp9NpZRPwWO+dMlZnYlXSzAgMBAAECggEAPXJxxTKSKPyBdqSFMv5DuAjYOx529/K6uyGseOHZfNROS42VAZitrK+y0coJqYRYtLzyCIwYaaaEhLVN1Pxky3zrA87Y+gT8PzvldJP8gykmxe5JpFkHtSpw7ZmicymGs1K80+tk0TPEEuEbRPhoRETBAVEQTHUg0QEP+UAFBHpDC5S5+F+oXm+UzaT7PLi3g/ZkTlebTw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vuUyc6SO4CwpeHx1nHyKrYw5alwoBVIjb6hV15N2ntOCradUk7Tp69nm08yLE9W6nIv/H8CrKVMv/FX7zJOugT4EGQbqs3rADpQLu2of8YqCz4aXISktKO//g5SeMH4ejWUk/P3TWNplJrbqkAuzRrCxRHWj8AAeFiBNxlUeJFdGMWnXIrr3doBVhAoD+SjPnchOFFxAjZ6MR/75FZKMjU/M8pmG5fcD8dS/9OtSbVDa8NFn19SVeyzwpOHuA4eOdCc3cacOYGutke5dR0CRJxPMQUTeeQebkfgKnA3EjCjGovSryu7gKIiQCbBHvc61s9K1wYWh97odtzngfHlBwIDAQAB";public static String notify_url = "";//public static String return_url = "";//支付完回调地址,用来查询订单支付状态public static String sign_type = "RSA2";public static String charset = "utf-8";public static String gatewayUrl = "";}4.2 AlibabapayGateWayUtils
支付和查询支付状态类
package com.bobo.utils;import com.alibaba.fastjson.JSON;import com.alipay.api.AlipayApiException;import com.alipay.api.AlipayClient;import com.alipay.api.DefaultAlipayClient;import com.alipay.api.request.AlipayTradePagePayRequest;import com.alipay.api.request.AlipayTradeQueryRequest;import com.alipay.api.response.AlipayTradeQueryResponse;import java.util.HashMap;import java.util.Map;public class AlibabapayGateWayUtils {/***调用支付接口* @param orderID 订单号* @param total_amount 支付金额* @param subject 商品名称* @param body 商品描述* @return*/public static String createOrder(String orderID,String total_amount,String subject,String body) throws AlipayApiException {Map
去支付
@ResponseBody@RequestMapping(value = "goPay", produces = "text/html; charset=UTF-8")public String goPay(Orders orders) throws AlipayApiException {String s = AlibabapayGateWayUtils.createOrder(orders.getId(), orders.getTotalMoney()+"", "测试数据", "描述");return s;}6.效果6.1 商品列表
6.2 购买
6.3 跳转到订单页面
6.4 点击支付宝支付6.4.1跳转到支付页面
如果使用点下一步,则进入下图
6.4.2 支付页面
输入密码:111111
6.4.3 交易成功
6.4.4 自动跳转到 回调页面
即AilipayConfig的配置的回调地址
6.4.5 订单信息
立即咨询: 13716188458 / 18588225959,助您抢占市场先机。项目经理在线