• 支付宝支付核心需要的参数是(APPID,PRIVATE_KEY,ALIPAY_PUBLIC_KEY)
  1. APPID:创建应用后就有的APPID。
  2. PRIVATE_KEY:应用私钥
  3. ALIPAY_PUBLIC_KEY:支付宝公钥
  • 上面的2,3的参数得自己弄到,参考文档:https://docs.open.alipay.com/291/105971/
  • 下载好工具后所需要干的事情:(获取到的应用公钥配置到:蚂蚁金服开放平台中在 “应用信息” - “开发设置” - “加签方式”处点击 “设置应用公钥”。获取到的应用私钥就是:PRIVATE_KEY。支付宝公钥ALIPAY_PUBLIC_KEY:当设置应用公钥完成后就可以查看支付宝公钥内容。)

    <!-- 支付宝SDK -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>3.7.4.ALL</version>
</dependency>
  • 配置支付所需配置文件
/**
* 支付宝支付配置文件
*/
public class AlipayConfig {
// 1.商户创建应用后获取的appid
public static String APPID = "********";
// 2.应用私钥
public static String PRIVATE_KEY ="*******";
// 3.支付宝公钥
public static String ALIPAY_PUBLIC_KEY = "******";
// 4.回调接口全路径(支付完成异步通知)
public static String notify_url = "https://******";
// 5.页面跳转同步通知页面路径(支付完成后跳转的页面)
public static String return_url = "https://******";
// 6.请求支付宝的网关地址
public static String URL = "https://openapi.alipay.com/gateway.do";
// 7.编码
public static String CHARSET = "UTF-8";
// 8.返回格式
public static String FORMAT = "json";
// 9.加密类型
public static String SIGNTYPE = "RSA2";
}
  • 业务层预下单
import com.aone.app.common.ali.pay.AlipayConfig;
import com.aone.app.service.AliH5PayService; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.request.AlipayTradeWapPayRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; @Service
public class AliH5PayServiceImpl implements AliH5PayService { private static final Logger logger = LoggerFactory.getLogger("AliH5PayServiceImpl"); //H5支付宝支付预下单(预下单)
public Map<String, String> dounifiedOrder(String type, String out_trade_no, String money, HttpServletRequest request) throws Exception{
Map<String, String> map=new HashMap<>(); //获得初始化的AlipayClient
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID,
AlipayConfig.PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,
AlipayConfig.SIGNTYPE); //设置请求参数passback_params
String content = "{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"total_amount\":\""+ "0.01" +"\","
+ "\"subject\":\""+ "订单" +"\","
+ "\"timeout_express\":\""+ "30m" +"\","
+ "\"body\":\""+ "支付宝H5支付" +"\","
+ "\"passback_params\":\""+type +"\","
+ "\"product_code\":\""+"QUICK_WAP_WAY"+"\"}";
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
alipayRequest.setReturnUrl(AlipayConfig.return_url);
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
alipayRequest.setBizContent(content); //请求
String result = alipayClient.pageExecute(alipayRequest).getBody();
logger.error("result{}",request.toString());
if(StringUtils.isEmpty(request)){
map.put("code","201");
map.put("msg","请求失败");
map.put("result",null);
}else{
map.put("code","200");
map.put("msg","请求成功");
map.put("result",result);
}
return map;
} }
  • 控制层下单接口以及回调接口
import com.aone.app.common.wx.XMLUtils;
import com.aone.app.service.AliH5PayService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.util.HashMap;
import java.util.Map; @RestController
@RequestMapping("h5pay")
@Api("H5支付")
public class PayH5Controller { private static final Logger log = LoggerFactory.getLogger("PayH5Controller"); @Autowired
private AliH5PayService aliH5PayService; /**
* H5支付统一下单
* @param request
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping(value = "wxPay")
public Map<String, String> weixinPay(HttpServletRequest request) throws Exception{
String type= request.getParameter("type");
String orderNo= request.getParameter("orderNo");
String money= request.getParameter("money");
return aliH5PayService.dounifiedOrder(type,orderNo,money,request);
} /**
* H5微信支付异步结果通知
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "notify")
public void weixinPayNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
BufferedReader reader = request.getReader();
String line = "";
Map map = new HashMap();
String xml = "<xml><return_code><![CDATA[FAIL]]></xml>";;
StringBuffer inputString = new StringBuffer();
while ((line = reader.readLine()) != null) {
inputString.append(line);
}
request.getReader().close();
log.error("----接收到的报文---{}",inputString.toString());
if(inputString.toString().length()>0){
map = XMLUtils.parseXmlToList(inputString.toString());
}else{
log.error("接受微信报文为空");
}
log.error("map={}",map);
if(map!=null && "SUCCESS".equals(map.get("result_code"))){
//成功的业务。。。
xml = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
String type=map.get("attach").toString();
String orderNo=map.get("out_trade_no").toString();
log.error("订单号{}",map.get("out_trade_no"));log.error("其它必须参数{}",map.get("attach"));
if(StringUtils.isEmpty(type)||StringUtils.isEmpty(orderNo)){
log.error("当前参数类型异常");
}else{
//回调业务逻辑 }
}else{
//失败的业务。。。
}
//告诉微信端已经确认支付成功
response.getWriter().write(xml);
}
}
  • 回调接口中解析微信通知XML的工具类XMLUtils,参考微信H5支付,缺少其它东西也可参考其它记录。

支付宝手机网站支付(基于Java实现支付宝手机网站支付)的更多相关文章

  1. 支付宝APP支付(基于Java实现支付宝APP支付)

    贴一下支付核心代码,以供后续参考: 业务层 import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; ...

  2. 微信APP支付(基于Java实现微信APP支付)

    步骤: 导入maven依赖 <!--微信支付--> <dependency> <groupId>com.github.wxpay</groupId> & ...

  3. 微信H5支付(基于Java实现微信H5支付)

    微信的H5支付区别与APP支付,主要在于预下单(返回的参数不一样),其它大体相同(基本没什么区别,区别在于有些人加密喜欢用MD5有些人喜欢用官方提供的加密方式加密,我用的是官方的),贴一下H5支付预下 ...

  4. Azure 网站上的 Java

     编辑人员注释:本文章由Windows Azure 网站团队的项目经理Chris Compy 撰写. Microsoft 已推出针对 Azure 网站上基于 Java 的网站的支持.此功能旨在通过 ...

  5. pay-spring-boot 开箱即用的Java支付模块,整合支付宝支付、微信支付

    关于 使用本模块,可轻松实现支付宝支付.微信支付对接,从而专注于业务,无需关心第三方逻辑. 模块完全独立,无支付宝.微信SDK依赖. 基于Spring Boot. 依赖Redis. 我能做什么 支付宝 ...

  6. Java第三方支付接入案例(支付宝)

    开源项目链接 Kitty 开源权限管理系统 项目地址:https://gitee.com/liuge1988/kitty 演示地址:http://139.196.87.48:9002/kitty 用户 ...

  7. java实现支付宝电脑支付(servlet版本)

    前期准备: 蚂蚁金融开放平台 进行登录操作 进入我的开放平台 在上方找到沙箱,进入沙箱(网络编程虚拟执行环境). 这里的RSA2密钥设置下,我已经设置好了,所以便有了支付宝公钥(公钥是对外公开的,私钥 ...

  8. java实现微信支付宝等多个支付平台合一的二维码支付(maven+spring springmvc mybatis框架)

    首先申明,本人实现微信支付宝等支付平台合多为一的二维码支付,并且实现有效时间内支付有效,本人采用的框架是spring springmvc mybatis 框架,maven管理.其实如果支付,不需要my ...

  9. 手把手教你完成App支付JAVA后台-支付宝支付JAVA

    接着上一篇博客,我们暂时完成了手机端的部分支付代码,接下来,我们继续写后台的代码. 后台基本需要到以下几个参数,我都将他们写在了properties文件中: 支付宝参数 AliPay.payURL = ...

随机推荐

  1. RabbitMQ 清除全部队列及消息

    前言 安装RabbitMQ后可访问:http://{rabbitmq安装IP}:15672使用(默认的是帐号guest,密码guest.此账号只能在安装RabbitMQ的机器上登录,无法远程访问登录. ...

  2. android webview带cookie访问url

    问题描述在原生和h5混合开发的时候会遇到这么一个问题,用webview加载某个url时,你只是app登录了账号,但是网页却没有,所有会禁止访问此url,webview就会显示白屏.所以要访问此url, ...

  3. 转 How to Resolve ORA-16009: remote archive log destination must be a STANDBY

    ###sample A primary B STANDBY C STANDBY   问题A 库一直报错 ORA-16009: remote archive log destination must b ...

  4. deployment.yaml 带同步时区

    [root@lab2 dandang]# cat dandang.v1.yaml apiVersion: v1 kind: ReplicationController metadata: name: ...

  5. Win10安装Oracle Database 18c (18.3)

    下载链接:https://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html 我这里选择最新的 ...

  6. 组件文档系统-md-react-styleguidist

    推荐指数:

  7. AtCoder Beginner Contest 147 E. Balanced Path

    思路: dp,使用了bitset优化. 实现: #include <bits/stdc++.h> using namespace std; ; const int INF = 0x3f3f ...

  8. mysql函数concat与group_concat使用说明

    mysql函数concat与group_concat使用说明concat()函数<pre>mysql> select concat(',',name,',') from `user` ...

  9. Jenkins控制台乱码修改

    原文地址:https://www.jianshu.com/p/8b9df45df401 方案一. 设置jenkins所在服务器环境变量,右键我的电脑→属性→高级系统设置→环境变量,添加JAVA_TOO ...

  10. Linux DHCP 服务器配置与管理

    一.环境介绍: 运行软件:VMware Workstation Pro 14 系统环境:CentOS-7-x86_64-1810 二.操作配置: 1.DHCP 服务器搭建 1)安装DHCP yum i ...