java支付宝支付,支付手机支付,pc网站支付
2017-04-20 17:27
429 查看
1:在撸代码之前 先去开通支付宝支付的账户 提交私钥 公钥一系列反锁的 事情 下面简单介绍一下我的支付过程
以下是整个项目的结构 只是做了个支付的测试 所有结构很简单 大神勿喷:
上面的 lib里面的 jar 大部分都可以在 支付宝的官方dome里面下载
当然 在写完文章 我会附上我的源码地址: 在这里 主要贴出 两个主要类的 代码 和 web.mlx 的配置 还index.html的按钮
CsPay.Java
[java] view
plain copy
print?
public class CsPay extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 参数目前都是 写死的 根据业务需求 写活
Map<String, String> maps = new HashMap<String, String>();
maps.put("out_trade_no", UtilDate.getOrderNum());
maps.put("total_amount", "0.01");
maps.put("subject", "Iphone6 16G");
maps.put("body", "Iphone6 16G");
maps.put("product_code", "QUICK_WAP_PAY");
// 下面两个 参数的 KEY 不要乱写 要和工具类里面对应
maps.put("ReturnUrl", "http://domain.com/CallBack/return_url.jsp");
maps.put("NotifyUrl", "http://domain.com/CallBack/notify_url.jsp");
try {
AlipayClientFactory ali = new AlipayClientFactory();
String form = ali.ydAndPc_Pay(maps);
if (!form.equals("err")) {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(form);// 直接将完整的表单html输出到页面
response.getWriter().flush();
}
} catch (AlipayApiException e) {
e.printStackTrace();
}
}
}
调用 支付工具类 AlipayClientFactory.java :里面包含 支付 订单查询 订单退款 扫描支付 等等 ...
我这里只贴 支付那一块代码 想看全的 待会贴上下载地址:
[java] view
plain copy
print?
// 手机网页支付 网站支付
public String ydAndPc_Pay(Map<String, String> maps)
throws AlipayApiException {
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
String NotifyUrl = maps.get("NotifyUrl");
String ReturnUrl = maps.get("ReturnUrl");
// 后台回调
if (!StringUtils.isEmpty(NotifyUrl)) {
alipayRequest.setNotifyUrl(NotifyUrl);
// bizContent 中不需要 公共参数
maps.remove("NotifyUrl");
}
// 页面回调
if (!StringUtils.isEmpty(ReturnUrl)) {
alipayRequest.setReturnUrl(ReturnUrl);
// bizContent 中不需要 公共参数
maps.remove("ReturnUrl");
}
String bizCon = JSON.toJSONString(maps);
alipayRequest.setBizContent(bizCon);
String form = "";
try {
form = AlipayClientFactory.getAlipayClientInstance()
.pageExecute(alipayRequest).getBody();
} catch (AlipayApiException e) {
form = "err";
e.printStackTrace();
} // 调用SDK生成表单
return form;
}
web.xml 配置:
[html] view
plain copy
print?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ACPSample_WuTiaoZhuan</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>csPay</servlet-name>
<servlet-class>com.cs.alipay.CsPay</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>csPay</servlet-name>
<url-pattern>/csPay</url-pattern>
</servlet-mapping>
</web-app>
index.html:
[java] view
plain copy
print?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="http://localhost:8080/csalipay/csPay">AAAAA</a>
</body>
下面是 点击按钮 手机端调支付的效果图:
下面是 PC端 调用支付的效果:
一下 是点击跳转过后的页面: 支付宝自定义组装返回的支付页面:
最后 附上源码的下载地址:http://download.csdn.NET/detail/wangbo54979/9630419
新手发帖 大神勿喷
以下是整个项目的结构 只是做了个支付的测试 所有结构很简单 大神勿喷:
上面的 lib里面的 jar 大部分都可以在 支付宝的官方dome里面下载
当然 在写完文章 我会附上我的源码地址: 在这里 主要贴出 两个主要类的 代码 和 web.mlx 的配置 还index.html的按钮
CsPay.Java
[java] view
plain copy
print?
public class CsPay extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 参数目前都是 写死的 根据业务需求 写活
Map<String, String> maps = new HashMap<String, String>();
maps.put("out_trade_no", UtilDate.getOrderNum());
maps.put("total_amount", "0.01");
maps.put("subject", "Iphone6 16G");
maps.put("body", "Iphone6 16G");
maps.put("product_code", "QUICK_WAP_PAY");
// 下面两个 参数的 KEY 不要乱写 要和工具类里面对应
maps.put("ReturnUrl", "http://domain.com/CallBack/return_url.jsp");
maps.put("NotifyUrl", "http://domain.com/CallBack/notify_url.jsp");
try {
AlipayClientFactory ali = new AlipayClientFactory();
String form = ali.ydAndPc_Pay(maps);
if (!form.equals("err")) {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(form);// 直接将完整的表单html输出到页面
response.getWriter().flush();
}
} catch (AlipayApiException e) {
e.printStackTrace();
}
}
}
调用 支付工具类 AlipayClientFactory.java :里面包含 支付 订单查询 订单退款 扫描支付 等等 ...
我这里只贴 支付那一块代码 想看全的 待会贴上下载地址:
[java] view
plain copy
print?
// 手机网页支付 网站支付
public String ydAndPc_Pay(Map<String, String> maps)
throws AlipayApiException {
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
String NotifyUrl = maps.get("NotifyUrl");
String ReturnUrl = maps.get("ReturnUrl");
// 后台回调
if (!StringUtils.isEmpty(NotifyUrl)) {
alipayRequest.setNotifyUrl(NotifyUrl);
// bizContent 中不需要 公共参数
maps.remove("NotifyUrl");
}
// 页面回调
if (!StringUtils.isEmpty(ReturnUrl)) {
alipayRequest.setReturnUrl(ReturnUrl);
// bizContent 中不需要 公共参数
maps.remove("ReturnUrl");
}
String bizCon = JSON.toJSONString(maps);
alipayRequest.setBizContent(bizCon);
String form = "";
try {
form = AlipayClientFactory.getAlipayClientInstance()
.pageExecute(alipayRequest).getBody();
} catch (AlipayApiException e) {
form = "err";
e.printStackTrace();
} // 调用SDK生成表单
return form;
}
web.xml 配置:
[html] view
plain copy
print?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ACPSample_WuTiaoZhuan</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>csPay</servlet-name>
<servlet-class>com.cs.alipay.CsPay</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>csPay</servlet-name>
<url-pattern>/csPay</url-pattern>
</servlet-mapping>
</web-app>
index.html:
[java] view
plain copy
print?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="http://localhost:8080/csalipay/csPay">AAAAA</a>
</body>
下面是 点击按钮 手机端调支付的效果图:
下面是 PC端 调用支付的效果:
一下 是点击跳转过后的页面: 支付宝自定义组装返回的支付页面:
最后 附上源码的下载地址:http://download.csdn.NET/detail/wangbo54979/9630419
新手发帖 大神勿喷
相关文章推荐
- java支付宝支付,支付手机支付,pc网站支付
- 支付宝PC即时到账和手机网站支付同步
- Java版支付宝手机网站支付
- java接入支付宝手机网站支付
- Java支付宝支付-PC电脑网站支付接口
- 新版支付宝手机网站支付、支付宝pc支付、支付宝无密退款实现
- 微信公众平台开发(39)支付宝手机网站支付
- 支付宝手机网站支付 错误代码 insufficient-isv-permissions 错误原因: ISV权限不足
- 呕心之作:支付宝的手机网站支付接口的应用
- 支付宝接口开发-手机网站支付-沙箱测试
- 支付宝手机网站支付接口API之C#版
- 支付宝中的手机网站支付接口,php版 notify_url.php 异步通知页面未成功执行
- alipay支付宝 wap手机网站支付错误提示: 通用参数中少了如service、partner等必填参数
- 支付宝接口手机网站支付验证返回字符串以及签名验证不通过的原因总结
- 支付宝手机网站支付
- 微信公众平台开发(39)支付宝手机网站支付
- 支付宝——手机网站支付接口研究
- 支付宝手机网站支付教程
- 支付宝支付之手机网站支付
- erdaicms旅游网站程序模板免费下载(PC站自带手机站,自带3套模板可切换,对接支付宝和微信支付)