赞
踩
沙箱环境是支付宝开放平台为开发者提供的与生产环境完全隔离的联调测试环境,开发者在沙箱环境中完成的接口调用不会对生产环境中的数据造成任何影响。
沙箱为开放的产品提供有限功能范围的支持,可以覆盖产品的绝大部分核心链路和对接逻辑,便于开发者快速学习/尝试/开发/调试。
首先使用开发者账号登录 开放平台控制台 > 滑到网页最下面,开发工具推荐,点击 沙箱 即可进入沙箱环境。
APPID为沙箱环境下模拟的应用id,加签可选择系统默认或自定义,这里选择系统默认证书模式。
进入沙箱账号,使用买家账号登陆沙箱版支付宝,使用安卓手机或模拟器扫描二维码下载沙箱版支付宝。
获取SDK工具:网址:SDK & Demo 获取 | 网页&移动应用
在订单服务接口工程中引入支付宝SDK和支付宝SDK依赖的日志依赖。
- <!-- 支付宝SDK -->
- <dependency>
- <groupId>com.alipay.sdk</groupId>
- <artifactId>alipay-sdk-java</artifactId>
- <version>3.7.73.ALL</version>
- </dependency>
-
- <!-- 支付宝SDK依赖的日志 -->
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.2</version>
- </dependency>
在订单服务接口工程创建 PayTestController
测试接口
首先编写AlipayConfig
配置类,用来定义一些参数
- public class AlipayConfig {
- // 商户appid
- public static String APPID = "2021000122610173";
- // 私钥 pkcs8格式的
- public static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDHdyplmVQ+kN9tSteSDA5PkVL4V1poOwTr9+q06So4Ea778RlJ3YphS2kUA0bPOnDcI0qCiXvGlv7DA34NDJZMN6YhZsZ/2P8qZUvgA8fZlBvXLI6KK7W3lh7YtgzUwgEoWm8/zYEW2bIR0LupjOIVAKWT22g3Wb8cjbzDmaEtZJdHiwNpF2NOg6pgV4dU8BxX5/YPzn+zwRAOArSTwFV8KbWkBZAFqiYNmBWGkJPj8QG7YzdIZe/ucI6njfh1roqB+xGeHsT85b1rKY7WJgwvXCj8rLLIeb+Rd2VJ3TIJ9Z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vETNWa02XmjhcA7RrGrm8QKBgB3/zQiz7xOCkurr3fTcz8pBS2YXkbHL9ahNEv3hQIKuSQox6IjCmR+aJt+8gHnrhsPYQEakQTdIXdYYC0M161DIU92LquWBZBy0Z4Q2TWAea6mfSoWaOLkvlp8J8jBi+m9K0VL1LFxBtWf+MZgkswA9rCKTH9tO0PSB0uz7P3TR";
-
- // 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
- public static String notify_url = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/notify_url.jsp";
- // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
- public static String return_url = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/return_url.jsp";
- // 请求网关地址
- public static String URL = "https://openapi.alipaydev.com/gateway.do";
- // 编码
- public static String CHARSET = "UTF-8";
- // 返回格式
- public static String FORMAT = "json";
- // 支付宝公钥
- public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoc9dm1HhmoowL3aHeW6M/vo1Yg4NOd5kG4cG69lQBJG5u/IgUa++ndVCdAAQtxHSike1qgjoC6sQj18rp+vapQxWeduV0fD/L4wRIUfOE4tYg300iAtfSPsdjTZRBCbIIN2Cl0kW0tpEsIS/5iD46aj2MxNOV0XoppRtD80FRHr6VVgEKQsOXpm3VUIOA8SMdGOiEz2/IMBtwBEq6rFc1opSpTOr3qW/ZhjiNx9e4uNKQtHC4JdLu+HXOSLsVN9izWjK93+lNA8RlvUmrRsnMmKIRkHO5hLDTx3gTb45UqI+//KbS4SxiwQiLWcZJPw3xKNMzSCU8zt1rScOBI/w5QIDAQAB";
- // 日志记录目录
- public static String log_path = "/log";
- // RSA2
- public static String SIGNTYPE = "RSA2";
- }
- @Controller
- public class PayTestController {
-
- @RequestMapping("/alipaytest")
- public void doPost(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse) throws ServletException, IOException, AlipayApiException {
- //获得初始化的AlipayClient
- AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.APP_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
- //创建API对应的request
- AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
- // alipayRequest.setReturnUrl("http://domain.com/CallBack/return_url.jsp");
- // alipayRequest.setNotifyUrl("http://domain.com/CallBack/notify_url.jsp");//在公共参数中设置回跳和通知地址
- alipayRequest.setBizContent("{" +
- " \"out_trade_no\":\"202210100010101002\"," +
- " \"total_amount\":0.1," +
- " \"subject\":\"Iphone6 16G\"," +
- " \"product_code\":\"QUICK_WAP_WAY\"" +
- " }");//填充业务参数
- String form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单
- httpResponse.setContentType("text/html;charset=" + AlipayConfig.CHARSET);
- httpResponse.getWriter().write(form);//直接将完整的表单html输出到页面
- httpResponse.getWriter().flush();
- }
- }
- <!-- 二维码生成&识别组件 -->
- <dependency>
- <groupId>com.google.zxing</groupId>
- <artifactId>core</artifactId>
- <version>3.3.3</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.zxing</groupId>
- <artifactId>javase</artifactId>
- <version>3.3.3</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
在本项目基础公共包的工具包下创建下面两个工具类。
- public class QRCodeUtil {
- /**
- * 生成二维码
- *
- * @param content 二维码对应的URL
- * @param width 二维码图片宽度
- * @param height 二维码图片高度
- * @return
- */
- public String createQRCode(String content, int width, int height) throws IOException {
- String resultImage = "";
- //除了尺寸,传入内容不能为空
- if (!StringUtils.isEmpty(content)) {
- ServletOutputStream stream = null;
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- //二维码参数
- @SuppressWarnings("rawtypes")
- HashMap<EncodeHintType, Comparable> hints = new HashMap<>();
- //指定字符编码为“utf-8”
- hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
- //L M Q H四个纠错等级从低到高,指定二维码的纠错等级为M
- //纠错级别越高,可以修正的错误就越多,需要的纠错码的数量也变多,相应的二维吗可储存的数据就会减少
- hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
- //设置图片的边距
- hints.put(EncodeHintType.MARGIN, 1);
-
- try {
- //zxing生成二维码核心类
- QRCodeWriter writer = new QRCodeWriter();
- //把输入文本按照指定规则转成二维吗
- BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
- //生成二维码图片流
- BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
- //输出流
- ImageIO.write(bufferedImage, "png", os);
- /**
- * 原生转码前面没有 data:image/png;base64 这些字段,返回给前端是无法被解析,所以加上前缀
- */
- resultImage = new String("data:image/png;base64," + EncryptUtil.encodeBase64(os.toByteArray()));
- return resultImage;
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("生成二维码出错");
- } finally {
- if (stream != null) {
- stream.flush();
- stream.close();
- }
- }
- }
- return null;
- }
-
- public static void main(String[] args) throws IOException {
- QRCodeUtil qrCodeUtil = new QRCodeUtil();
- System.out.println(qrCodeUtil.createQRCode("http://www.baidu.com", 200, 200));
- }
- }
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import java.io.UnsupportedEncodingException;
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- import java.util.Base64;
-
- public class EncryptUtil {
- private static final Logger logger = LoggerFactory.getLogger(EncryptUtil.class);
-
- public static String encodeBase64(byte[] bytes){
- String encoded = Base64.getEncoder().encodeToString(bytes);
- return encoded;
- }
-
- public static byte[] decodeBase64(String str){
- byte[] bytes = null;
- bytes = Base64.getDecoder().decode(str);
- return bytes;
- }
-
- public static String encodeUTF8StringBase64(String str){
- String encoded = null;
- try {
- encoded = Base64.getEncoder().encodeToString(str.getBytes("utf-8"));
- } catch (UnsupportedEncodingException e) {
- logger.warn("不支持的编码格式",e);
- }
- return encoded;
-
- }
-
- public static String decodeUTF8StringBase64(String str){
- String decoded = null;
- byte[] bytes = Base64.getDecoder().decode(str);
- try {
- decoded = new String(bytes,"utf-8");
- }catch(UnsupportedEncodingException e){
- logger.warn("不支持的编码格式",e);
- }
- return decoded;
- }
-
- public static String encodeURL(String url) {
- String encoded = null;
- try {
- encoded = URLEncoder.encode(url, "utf-8");
- } catch (UnsupportedEncodingException e) {
- logger.warn("URLEncode失败", e);
- }
- return encoded;
- }
-
-
- public static String decodeURL(String url) {
- String decoded = null;
- try {
- decoded = URLDecoder.decode(url, "utf-8");
- } catch (UnsupportedEncodingException e) {
- logger.warn("URLDecode失败", e);
- }
- return decoded;
- }
-
- public static void main(String [] args){
- String str = "abcd{'a':'b'}";
- String encoded = EncryptUtil.encodeUTF8StringBase64(str);
- String decoded = EncryptUtil.decodeUTF8StringBase64(encoded);
- System.out.println(str);
- System.out.println(encoded);
- System.out.println(decoded);
-
- String url = "== wo";
- String urlEncoded = EncryptUtil.encodeURL(url);
- String urlDecoded = EncryptUtil.decodeURL(urlEncoded);
-
- System.out.println(url);
- System.out.println(urlEncoded);
- System.out.println(urlDecoded);
- }
- }
运行QRCodeUtil
类中main方法,控制台生成:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADIAQAAAACFI5MzAAABR0lEQVR42u2YPbLDIAyExbhw+Y6Qo/ho9tE4So6Q0gWD3mqB/DjzXpViPROKOPC5yKKVBDH/a9iX/EtuFmPGY602u2fOL+rkgh9fZr9iPuFrXvFx0yfZUoGeZesk1J2EQA+iYD8nIzANgoHZSQi9E0vV+Di4SpP0PMVS4gtvGaxIxrguG2W9V0tFwn0vsLpv7jsf5e4qYeJbnbhk0x4RwMzkCRoP3ZLbUje+OoGe1LafBT30DO9IEzejdypT9KXuqBL2SZpmbVHA0m7qhPtOIdby1J9cJUuiXSanLJom26Na6pJ7nkZ1obrmf23SB06Dnmh1T2VEQZc83Rd6yw9Z8mTcFxbUxAiGJ3/URF3Sz7CRoG1M/nq6VSaZ9wXIanX9FCSaZ5RwGn+cXZTJuAdHTWyd/+AqRTLydGk1cfF6zGBB8v0n67PkFw9du/mFytSFAAAAAElFTkSuQmCC
在浏览器打开生成前往百度的二维码,扫码成功前往百度则测试成功。现在将百度地址改为本项目订单接口地址:http://192.168.2.14:8080/alipaytest,ip不能写localhost,要写本机ip,查看方法:win+R,输入cmd进入控制台,控制台输入ipconfig
回车即可查看。
更换成接口地址后生成二维码用沙箱版支付宝扫描,成功进入支付界面即成功:
刚才订单付款成功,可以使用out_trade_no商品订单号或支付宝的交易流水号trade_no
去查询支付结果。
out_trade_no
商品订单号: 是在下单请求时指定的商品订单号。
支付宝的交易流水号trade_no
:是支付完成后支付宝通知支付结果时发送的trade_no
。
这里我们使用out_trade_no
商品订单号去查询,代码如下:
- import com.alibaba.fastjson.JSONObject;
- import com.alipay.api.AlipayApiException;
- import com.alipay.api.AlipayClient;
- import com.alipay.api.DefaultAlipayClient;
- import com.alipay.api.request.AlipayTradeQueryRequest;
- import com.alipay.api.response.AlipayTradeQueryResponse;
- import org.junit.jupiter.api.Test;
- import org.springframework.boot.test.context.SpringBootTest;
-
- /**
- * @description 支付宝查询接口
- */
- @SpringBootTest
- public class AlipayApplicationTests {
-
- // 商户appid
- public static String APP_ID = "2021000122610173";
- public static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDHdyplmVQ+kN9tSteSDA5PkVL4V1poOwTr9+q06So4Ea778RlJ3YphS2kUA0bPOnDcI0qCiXvGlv7DA34NDJZMN6YhZsZ/2P8qZUvgA8fZlBvXLI6KK7W3lh7YtgzUwgEoWm8/zYEW2bIR0LupjOIVAKWT22g3Wb8cjbzDmaEtZJdHiwNpF2NOg6pgV4dU8BxX5/YPzn+zwRAOArS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uFAhn2pifGEoiWgH5o7u6xDGSmHJo4V6vXS6HSy88/z6C7vSSfo76vQyENd/8RPQS/1+4BOtL+lq93lvJtkr97MlXIPAjBsJYIvETNWa02XmjhcA7RrGrm8QKBgB3/zQiz7xOCkurr3fTcz8pBS2YXkbHL9ahNEv3hQIKuSQox6IjCmR+aJt+8gHnrhsPYQEakQTdIXdYYC0M161DIU92LquWBZBy0Z4Q2TWAea6mfSoWaOLkvlp8J8jBi+m9K0VL1LFxBtWf+MZgkswA9rCKTH9tO0PSB0uz7P3TR";
- public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoc9dm1HhmoowL3aHeW6M/vo1Yg4NOd5kG4cG69lQBJG5u/IgUa++ndVCdAAQtxHSike1qgjoC6sQj18rp+vapQxWeduV0fD/L4wRIUfOE4tYg300iAtfSPsdjTZRBCbIIN2Cl0kW0tpEsIS/5iD46aj2MxNOV0XoppRtD80FRHr6VVgEKQsOXpm3VUIOA8SMdGOiEz2/IMBtwBEq6rFc1opSpTOr3qW/ZhjiNx9e4uNKQtHC4JdLu+HXOSLsVN9izWjK93+lNA8RlvUmrRsnMmKIRkHO5hLDTx3gTb45UqI+//KbS4SxiwQiLWcZJPw3xKNMzSCU8zt1rScOBI/w5QIDAQAB";
-
- static String CHARSET = "utf-8";
- static String serverUrl = "https://openapi.alipaydev.com/gateway.do";
- //签名算法类型
- static String sign_type = "RSA2";
-
- @Test
- public void queryPayResult() throws AlipayApiException {
- AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, APP_ID, APP_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);//获得初始化的AlipayClient
- AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
- JSONObject bizContent = new JSONObject();
- bizContent.put("out_trade_no", "202210100010101002");
- //bizContent.put("trade_no", "2014112611001004680073956707");
- request.setBizContent(bizContent.toString());
- AlipayTradeQueryResponse response = client.execute(request);
- if(response.isSuccess()){
- System.out.println("调用成功");
- } else {
- System.out.println("调用失败");
- }
- }
- }
- @GetMapping("/alipaytest")
- public void alipaytest(HttpServletRequest httpRequest,
- HttpServletResponse httpResponse) throws ServletException, IOException {
- //构造sdk的客户端对象
- AlipayClient alipayClient = new DefaultAlipayClient(serverUrl, APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, sign_type); //获得初始化的AlipayClient
- AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();//创建API对应的request
- // alipayRequest.setReturnUrl("http://domain.com/CallBack/return_url.jsp");
- alipayRequest.setNotifyUrl("http://www.baidu.com");//在公共参数中设置回跳和通知地址
-
- //接收通知
- @PostMapping("/paynotify")
- public void paynotify(HttpServletRequest request) throws UnsupportedEncodingException, AlipayApiException {
- Map<String,String> params = new HashMap<String,String>();
- Map requestParams = request.getParameterMap();
- for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
- String name = (String) iter.next();
- String[] values = (String[]) requestParams.get(name);
- String valueStr = "";
- for (int i = 0; i < values.length; i++) {
- valueStr = (i == values.length - 1) ? valueStr + values[i]
- : valueStr + values[i] + ",";
- }
- //乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
- //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk");
- params.put(name, valueStr);
- }
-
- //商户订单号
-
- String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
- //支付宝交易号
-
- String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
-
- //交易状态
- String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
-
- //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以上仅供参考)//
- //计算得出通知验证结果
- //boolean AlipaySignature.rsaCheckV1(Map<String, String> params, String publicKey, String charset, String sign_type)
- boolean verify_result = AlipaySignature.rsaCheckV1(params, ALIPAY_PUBLIC_KEY, CHARSET, "RSA2");
-
- if(verify_result) {//验证成功
- //
- //请在这里加上商户的业务逻辑程序代码
-
- //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
-
- if (trade_status.equals("TRADE_FINISHED")) {//交易结束
- //判断该笔订单是否在商户网站中已经做过处理
- //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
- //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
- //如果有做过处理,不执行商户的业务程序
-
- //注意:
- //如果签约的是可退款协议,退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
- //如果没有签约可退款协议,那么付款完成后,支付宝系统发送该交易状态通知。
- } else if (trade_status.equals("TRADE_SUCCESS")) {//交易成功
- System.out.println(trade_status);
- //判断该笔订单是否在商户网站中已经做过处理
- //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
- //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
- //如果有做过处理,不执行商户的业务程序
-
- //注意:
- //如果签约的是可退款协议,那么付款完成后,支付宝系统发送该交易状态通知。
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。