> 文章列表 > 支付宝支付功能使用

支付宝支付功能使用

支付宝支付功能使用

1、进入“蚂蚁金服开放平台”

https://open.alipay.com/https://open.alipay.com/

2、下载支付宝官方 demo,进行配置和测试

文档地址

手机网站支付 DEMO | 网页&移动应用支付宝文档中心https://opendocs.alipay.com/open/02no47

demo下载

网页&移动应用支付宝文档中心https://opendocs.alipay.com/open/270/106291/

源码目录结构说明

├─src│  └─com.alipay│      └─config│          ├─AlipayConfig        配置类│      └─util│          ├─logFile        日志类├─WebContent│  └─META-INF│  └─ wappay 手机网站支付│          ├─close.jsp 统一收单交易关闭接口调试入口页面│          ├─downloadurl.jsp 查询对账单下载地址接口调试入口页面│          ├─ pay.jsp 支付宝手机网站支付接口(alipay.trade.wap.pay)接口调试入口页面│          ├─query.jsp 统一收单线下交易查询调试入口页面│          ├─refund.jsp 统一收单交易退款接口调试入口页面│          ├─ refundquery.jsp 统一收单交易退款查询调试入口页面│  └─ META-INF│      └─ lib 依赖类库│          ├─alipay-sdk-java-3.3.0.jar│          ├─alipay-sdk-java-3.3.0-source.jar│          ├─ commons-logging-1.1.1.jar│          ├─ commons-logging-1.1.1-sources.jar│       ├─index.html│       ├─notify_url.jsp│       ├─ return_url.jsp

AlipayConfig  配置类示例代码 

package com.alipay.config;public class AlipayConfig {// 商户appidpublic static String APPID = "";// 私钥 pkcs8格式的public static String RSA_PRIVATE_KEY = "";// 服务器异步通知页面路径 需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.alipay.com/gateway.do";// 编码public static String CHARSET = "UTF-8";// 返回格式public static String FORMAT = "json";// 支付宝公钥public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjrEVFMOSiNJXaRNKicQuQdsREraftDA9Tua3WNZwcpeXeh8Wrt+V9JilLqSa7N7sVqwpvv8zWChgXhX/A96hEg97Oxe6GKUmzaZRNh0cZZ88vpkn5tlgL4mH/dhSr3Ip00kvM4rHq9PwuT4k7z1DpZAf1eghK8Q5BgxL88d0X07m9X96Ijd0yMkXArzD7jg+noqfbztEKoH3kPMRJC2w4ByVdweWUT2PwrlATpZZtYLmtDvUKG/sOkNAIKEMg3Rut1oKWpjyYanzDgS7Cg3awr1KPTl9rHCazk15aNYowmYtVabKwbGVToCAGK+qQ1gT3ELhkGnf3+h53fukNqRH+wIDAQAB";// 日志记录目录定义在 logFile 中public static String log_path = "/log";// RSA2public static String SIGNTYPE = "RSA2";}

index.html 说明 

<div id="main"><div id="body" style="clear:left"><dl class="content"><dt></dt><dd id="btn-dd"><span class="new-btn-login-sp"><button class="new-btn-login" style="text-align:center;" onclick="window.open('./wappay/pay.jsp')">手机网站2.0支付(接口名:alipay.trade.wap.pay)</button></span></dd><dt></dt><dd id="btn-dd"><span class="new-btn-login-sp"><button class="new-btn-login" style="text-align:center;" onclick="window.open('./wappay/query.jsp')">手机网站2.0订单查询 (接口名:alipay.trade.query)</button></span></dd><dt></dt><dd id="btn-dd"><span class="new-btn-login-sp"><button class="new-btn-login" style="text-align:center;" onclick="window.open('./wappay/refund.jsp')">手机网站2.0订单退款  (接口名:alipay.trade.refund)</button></span></dd><dt></dt><dd id="btn-dd"><span class="new-btn-login-sp"><button class="new-btn-login" style="text-align:center;" onclick="window.open('./wappay/refundquery.jsp')">手机网站2.0订单退款查询(接口名:alipay.trade.fastpay.refund.query)</button></span></dd><dt></dt><dd id="btn-dd"><span class="new-btn-login-sp"><button class="new-btn-login" style="text-align:center;" onclick="window.open('./wappay/downloadurl.jsp')">手机网站2.0账单下载(接口名:alipay.data.dataservice.bill.downloadurl.query)</button></span></dd></dl></div>

3、配置使用沙箱进行测试

1、使用 RSA 工具生成签名

2、下载沙箱版钱包

3、运行官方 demo 进行测试

4、什么是公钥、私钥、加密、签名和验签?

公钥私钥

公钥和私钥是一个相对概念 它们的公私性是相对于生成者来说的。

一对密钥生成后,保存在生成者手里的就是私钥, 生成者发布出去大家用的就是公钥

加密和数字签名

 加密是指:

        我们使用一对公私钥中的一个密钥来对数据进行加密,而使用另一个密钥来进行解 密的技术。

 公钥和私钥都可以用来加密,也都可以用来解密。

 但这个加解密必须是一对密钥之间的互相加解密,否则不能成功。

 加密的目的是:

         为了确保数据传输过程中的不可读性,就是不想让别人看到。

签名:

 给我们将要发送的数据,做上一个唯一签名(类似于指纹)

 用来互相验证接收方和发送方的身份;

 在验证身份的基础上再验证一下传递的数据是否被篡改过。因此使用数字签名可以 用来达到数据的明文传输。

验签

 支付宝为了验证请求的数据是否商户本人发的,

 商户为了验证响应的数据是否支付宝发的