• 支付宝支付接口的调用


    1.准备工作

    第一步就是先要注册一个支付宝的账号(注册这里不说,不是重点),然后登入官方首页,去到应用列表里面找到沙箱应用
    基本信息的APPID很重要,后续配置文件要配置的app_id就是这个。
    在这里插入图片描述
    系统密钥,查看公钥模式,merchant_private_key就是应用私钥;alipay_public_key支付宝公钥;支付宝网关地址https://openapi.alipaydev.com/gateway.do因为是沙箱测试环境,这里是dev标识加以区分;签名方式这里是RSA2

    沙箱账号有商家和买家的账号支付密码和余额,后续付款会用得到的
    在这里插入图片描述

    2.获取Demo (JAVA版)

    支付宝文档中心支付应用SDK&&DEMO下载代码demo,用来在本地加以调试就行。
    在这里插入图片描述

    3.导入本地运行测试

    本地环境是Eclipse+JDK1.8 及以上+Tomcat8.0,导入本地。
    在这里插入图片描述
    本地下载一个tomcat服务器,本地配置好添加进去,启动tomcat就可以正常启动访问项目。
    在这里插入图片描述

    AlipayConfig文件主要是配置,APPID,私钥等这些信息,具体配置参考下文

    package com.alipay.config;
    
    import java.io.FileWriter;
    import java.io.IOException;
    
    /* *
     *类名:AlipayConfig
     *功能:基础配置类
     *详细:设置帐户有关信息及返回路径
     *修改日期:2017-04-05
     *说明:
     *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
     *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
     */
    
    public class AlipayConfig {
    	
    //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    
    	// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号 https://open.alipay.com/develop/sandbox/app 这个链接查找
    	public static String app_id = "XXX";
    	
    	// 商户私钥,您的PKCS8格式RSA2私钥
        public static String merchant_private_key = "XXX";
    	
    	// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
        public static String alipay_public_key = "XXX";
    
    	// 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    	public static String notify_url = "http://127.0.0.1:8080/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";
    
    	// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    	public static String return_url = "http://127.0.0.1:8080/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";
    
    	// 签名方式
    	public static String sign_type = "RSA2";
    	
    	// 字符编码格式
    	public static String charset = "utf-8";
    	
    	// 支付宝网关 https://openapi.alipaydev.com/gateway.do
    	public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
    	
    	// 支付宝网关
    	public static String log_path = "C:\\";
    
    
    //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
    
        /** 
         * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
         * @param sWord 要写入日志里的文本内容
         */
        public static void logResult(String sWord) {
            FileWriter writer = null;
            try {
                writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
                writer.write(sWord);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (writer != null) {
                    try {
                        writer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    index.jsp是支付宝电脑网站支付体验入口页,访问链接http://127.0.0.1:8080/alipay.trade.page.pay-JAVA-UTF-8/index.jsp
    在这里插入图片描述
    点击付款触发访问alipay.trade.page.pay.jsp在这个jsp页面调用支付接口
    在这里插入图片描述

    点击付款按钮跳转到付款页面,这个页面不是本地的页面在这里插入图片描述

    输入用户名和支付密码点击下一步完成付款,点击确认付款
    在这里插入图片描述
    付款成功页面,这个页面显示之后等待几秒会跳转到return_url页面,展示商家设定的页面
    在这里插入图片描述
    http://127.0.0.1:8080/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp
    在这里插入图片描述

  • 相关阅读:
    找出缺失和重复的数字 - (LeetCode)
    SpringBoot SpringBoot 开发实用篇 6 监控 6.5 health 端点指标控制
    [附源码]java毕业设计-室内田径馆预约管理系统
    【面经】如何查看服务器内存和磁盘空间占用
    3D RPG Course | Core 学习日记四:鼠标控制人物移动
    DDS协议介绍
    【slowfast 损失函数改进】深度学习网络通用改进方案:slowfast的损失函数(使用focal loss解决不平衡数据)改进
    【web课程设计网页规划与设计】基于HTML+CSS+JavaScript火车票网上预订系统网站(4个页面)
    EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项
    React入门笔记(一)
  • 原文地址:https://blog.csdn.net/qq_37200262/article/details/125708560