做好准备 直接上代码
支付前准备
我选用的是证书 也可以用秘钥 自己把证书转换成秘钥就可以了
jar
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.10.97.ALL</version>
</dependency>
配置类
package com.tm.forum.common.config.alipay;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* @author fei
*/
@Configuration
public class AlipayConfig {
/**
* 请求*****的地址
*/
@Value("${b2b3.b2b3_url}")
public String B2B3_URL;
/**
* 应用公钥证书路径
*/
@Value("${zfb.app_cert_path}")
public String APP_CERT_PATH;
/**
* 支付宝公钥证书路径
*/
@Value("${zfb.alipay_cert_path}")
public String ALIPAY_CERT_PATH;
/**
* 支付宝根证书路径
*/
@Value("${zfb.alipay_root_cert_path}")
public String ALIPAY_ROOT_CERT_PATH;
/**
* 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号,开发时使用沙箱提供的APPID,生产环境改成自己的APPID 正式 2021003157678066 沙箱 2021000121679063
*/
public String app_id = "2021003157678066";
/**
* 私钥,您的PKCS8格式RSA2私钥(应用私钥) 正式
*/
public String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDnb750aXOpnYmfHKm187xPrMtsiItqZrayCWRkshepCDHdd8V/WAnIXYrdrP8s4mrIZac8QxyhFymEEJfSPK0s2od7Idgl4A7h/uYAAT95px2Y857xN7gGvnRLKZKBb2ZNJ5jefGrFhm9Br2bxcLaWuvhF4LSHQ1IDufH7lM9tAkUYUPPUQb5Zacj7hjog1hQgy4hYqnyMAoRMY6nHj7WHb3Hv7HIDqDCFMFJYAQgvCBU+Q414sXx8ko3ZAIAnT1Cgogpq5DYG/K78pJxH/Id1km5PoI545+icG4FrHDQIPFIwMi68zxJYs0wmx76Gx/GWFGeXi20focM5dTNjPetRAgMBAAECggEAEw8Tuxh4Cu7LR4wfubkxt8n+EpkICiIdR3oYh2ZXJndjS96yJ/ODEroJVooJlZOr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Zn+T0l/xnpu8AlC1HPE5BEYPCXcmgMyB1ColMRDtFVIjD6QChemIkoPgqz00jBp4EbYRnX+feBnqxEkCh1icYESU4pkTk7RFE=";
// public String merchant_private_key = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQChqhAJoPs8Ulrl0hCvzSC1NRwv9jnlSR6bqDRHoalqPLHapT4+zH2Xsm7fo1J1Qbcmy+cronoPIzrkm8qHarMqcPWczNzL3CAoXR8CwXmVJfhXvDIkbKAyfLbiyGFjJGJjGjYeCFJX381Loi9m3Fv15+xgFyjlve4w3kS31aNCRR0PRQmbScVBb16pj/v8kgg0DxncNR4wQddTZyqyjlksbjb7sOSrIBuTxwWW+mk3qHyjbIKh/Gki0urWq3thPbj02OsxSkFC8ChUky9sYAO8Y/11AwHwQQc6+Ba8dEu8JNcdxL8JoxjFtHeYsMUQauAwtuN0DQLHP42piE4JnCHXAgMBAAECggEAfpO6BN//dgaBVyo3mH5Cmr7fuAnQ4N50UanMbT19eUnWc3woFWFlAI5b00x8NoTik0TZVkfby9hoty/nzklTyOoy1LduNUu//fqTWkQEHyxgmskmdXB7qawOQdhksAx/4FpYfwFC/7yicBKnjKECe7JAWCgqBF/GjIqrQUjLkAluTE5GGklqlA6fsS8jTBU5rZjXIcM0B8sTqoODPcI9cNYjsIJvmEy8XUpflr0ze6APVL90YDW159HKWGTJNziSeTad1MCCArrH1iAactk3osXJRNhfQpGGCqz9gBY3TF6slX42rBUUwo3WxwzIMcA2IKwjR350n6Lxn8ikAeoymQKBgQDlbRfvMhdfwXPnzy9648PxVCYeVveQSWn9FsELFysvA+0pW9rPNPiocbaEX2/stS5juL8a7L3R29TVDbpfi/tq+S1Px9V406qyAQQIRtlJ28TNZY2wAi3mA8ub9AEB8u4izjZfdjY0SE/pUcCluoamAyb+kjYXrWbIwLhen7qYrQKBgQC0Y7TJYw7M+/Ka5kGwnGWhjzh36vv1yZeaHEjSE6UA3S1uHj8kNdbiXMlDOSS61oYT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服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问(可以使用natapp内容穿透完成外网设置)
*/
@Value("${zfb.notify_url}")
public String notify_url;
/**
* 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
*/
@Value("${zfb.return_url}")
public String return_url;
/**
* 签名方式 固定
*/
public String sign_type = "RSA2";
/**
* 字符编码格式 固定
*/
public String charset = "utf-8";
/**
* 支付宝网关 开发环境 正式 https://openapi.alipay.com/gateway.do 沙箱 https://openapi.alipaydev.com/gateway.do
*/
public String gatewayUrl = "https://openapi.alipay.com/gateway.do";
}
网页支付宝支付
package com.tm.forum.system.service.payment;
import com.alipay.api.AlipayApiException;
import com.tm.forum.system.domain.order.Order;
import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.rmi.ServerException;
import java.util.Map;
/**
* @program: translation-api
* @description 支付宝支付
* @author: fei
* @create: 2022-10-22 23:07
**/
public interface AliPayService {
/**
* 获得支付页面
*
* @param order @return
* @param request
* @return
*/
String aliPayLine(Order order, HttpServletRequest request) throws Exception;
/**
* 获取异步返回的参数
*
* @param requestParams
* @return
*/
Map<String, String> getAliParams(Map requestParams);
// /**
// * 异步通知
// * @param request
// * @param response
// * @return
// */
// Object notify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException;
/**
* 查看订单
*
* @return
*/
String query(String orderNo) throws AlipayApiException, ServerException, FileNotFoundException;
/**
* 获得支付页面-手机端
*
* @param order @return
* @param request
* @return
*/
String mAliPayLine(Order order, HttpServletRequest request) throws Exception;
}
package com.tm.forum.system.service.payment;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradePagePayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.tm.forum.common.config.alipay.AlipayConfig;
import com.tm.forum.common.core.redis.RedisCache;
import com.tm.forum.common.utils.QRCodeUtil;
import com.tm.forum.common.utils.StringUtils;
import com.tm.forum.common.utils.ip.IpUtils;
import com.tm.forum.system.domain.AlipayBean;
import com.tm.forum.system.domain.order.Order;
import com.tm.forum.system.mapper.order.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;
import org.springframework.util.ResourceUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.math.BigDecimal;
import java.rmi.ServerException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @program: translation-api
* @description 网页支付宝支付
* @author: ddz
* @create: 2021-05-12 23:07
**/
@Slf4j
@Service
public class AliPayServiceImpl implements AliPayService {
@Resource
private OrderMapper payOrderMapper;
@Resource
private RedisCache redisUtil;
@Resource
private AlipayConfig alipayConfig;
/**
* 证书模式 获取文件路径
*
* @return
* @throws FileNotFoundException
* @throws ServerException
*/
public String queryPath() throws FileNotFoundException, ServerException {
String basePath = ResourceUtils.getURL("classpath:").getPath();
basePath = this.initCart(basePath);
return basePath;
}
/**
* 证书模式 初始化证书文件
*
* @param basePath
* @return
* @throws ServerException
*/
private String initCart(String basePath) throws ServerException {
if (basePath.contains("jar!")) {
if (basePath.startsWith("file:")) {
basePath = basePath.replace("file:", "");
}
String appCertPath = alipayConfig.APP_CERT_PATH;
this.checkAndcopyCart(basePath, appCertPath);
String alipayCertPath = alipayConfig.ALIPAY_CERT_PATH;
this.checkAndcopyCart(basePath, alipayCertPath);
String alipayRootCertPath = alipayConfig.ALIPAY_ROOT_CERT_PATH;
this.checkAndcopyCart(basePath, alipayRootCertPath);
}
return basePath;
}
/**
* 证书模式下需要
*
* @param basePath
* @param path
* @throws ServerException
* @description 查找在该文件路径下是否已经存在这个文件,如果不存在,则拷贝文件
*/
private void checkAndcopyCart(String basePath, String path) throws ServerException {
InputStream cartInputStream = null;
OutputStream cartOutputStream = null;
String cartPath = basePath + path;
File cartFile = new File(cartPath);
File parentFile = cartFile.getParentFile();
parentFile.mkdirs();
try {
if (!cartFile.exists()) {
cartInputStream = ClassUtils.getDefaultClassLoader().getResourceAsStream(path);
cartOutputStream = new FileOutputStream(cartFile);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = cartInputStream.read(buf)) != -1) {
cartOutputStream.write(buf, 0, bytesRead);
}
cartInputStream.close();
cartOutputStream.close();
}
} catch (IOException e) {
throw new ServerException(e.getMessage());
}
}
/**
* 构建client
*
* @return
* @throws AlipayApiException
* @throws ServerException
* @throws FileNotFoundException
*/
public AlipayClient initAlipayClient() throws AlipayApiException, ServerException, FileNotFoundException {
// String basePath = this.queryPath();
// 构造client
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
// 设置网关地址
certAlipayRequest.setServerUrl(alipayConfig.gatewayUrl);
// 设置应用Id
certAlipayRequest.setAppId(alipayConfig.app_id);
// 设置应用私钥
certAlipayRequest.setPrivateKey(alipayConfig.merchant_private_key);
// 设置请求格式,固定值json
certAlipayRequest.setFormat("json");
// 设置字符集
certAlipayRequest.setCharset(alipayConfig.charset);
// 设置签名类型
certAlipayRequest.setSignType(alipayConfig.sign_type);
// 设置应用公钥证书路径
certAlipayRequest.setCertPath(alipayConfig.APP_CERT_PATH);
// 设置支付宝公钥证书路径
certAlipayRequest.setAlipayPublicCertPath(alipayConfig.ALIPAY_CERT_PATH);
// 设置支付宝根证书路径
certAlipayRequest.setRootCertPath(alipayConfig.ALIPAY_ROOT_CERT_PATH);
// 构造client
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
return alipayClient;
}
/**
* 获得支付页面
*
* @param order @return
* @param request
* @return
*/
@Override
public String aliPayLine(Order order, HttpServletRequest request) throws Exception {
AlipayClient alipayClient = this.initAlipayClient();
// 根据订单交易号查询订单
order = payOrderMapper.findOutTradeNoOrder(order.getOutTradeNo());
if (null == order) {
return "没有该订单";
}
String out_trade_no = order.getOutTradeNo();
String total_amount = String.valueOf(order.getRmbPrice());
String subject = "用户" + order.getUsername() + "支付订单";
String body = subject;
// 设置请求参数
AlipayTradePagePayRequest aliRequest = new AlipayTradePagePayRequest();
// 设置回调地址
//alipayConfig.return_url
aliRequest.setReturnUrl(alipayConfig.return_url);
// alipayConfig.notify_url
aliRequest.setNotifyUrl(alipayConfig.notify_url);
// 封装参数,以及自己需要的参数 如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝会在异步通知时将该参数原样返回
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
model.setOutTradeNo(out_trade_no);
// 获取本地Ip 判断是否是测试ip
String ip = IpUtils.getHostIp();
if (StringUtils.isNotBlank(ip)) {
// ip.contains("192.168.1")||ip.contains("192.168.3.") || ip.contains("127.0.0.1") || order.getUserId() == 223695
if (ip.contains("192.168.1")||ip.contains("192.168.3.") || ip.contains("127.0.0.1")) {
model.setTotalAmount("0.01");
} else {
model.setTotalAmount(total_amount);
}
} else {
model.setTotalAmount(total_amount);
}
model.setSubject(subject);
model.setBody(body);
model.setTimeoutExpress("5m");
model.setProductCode("FAST_INSTANT_TRADE_PAY");
String json = JSONObject.toJSONString(order);
// 附加参数
model.setPassbackParams(json);
aliRequest.setBizModel(model);
//请求,返回的数据由前端进行解析
String result = alipayClient.pageExecute(aliRequest).getBody();
return result;
}
/**
* 获取阿里支付回调的数据拼装 验签,该方法在同步回调,异步回调时,必须要用到的
*/
@Override
public Map<String, String> getAliParams(Map requestParams) {
Map<String, String> params = new HashMap<String, String>();
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] + ",";
}
params.put(name, valueStr);
}
return params;
}
/**
* 查看订单
*
* @param orderNo
* @return
*/
@Override
public String query(String orderNo) throws AlipayApiException, ServerException, FileNotFoundException {
//获得初始化的AlipayClient
AlipayClient alipayClient = this.initAlipayClient();
AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
/**请求接口*/
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
model.setOutTradeNo(orderNo);
alipayRequest.setBizModel(model);
/**转换格式*/
String result = alipayClient.certificateExecute(alipayRequest).getBody().replace('\"', '\'').replace('\n', ' ');
log.info(result);
JSONObject jsonObject = JSONObject.parseObject(result, JSONObject.class);
JSONObject resp = (JSONObject) jsonObject.get("alipay_trade_query_response");
String code = (String) resp.get("code");
String status = "1";
if ("40004".equals(code)) {
status = "3";
}
String trade_status = (String) resp.get("trade_status");
//支付成功||交易结束,不可退款
if ("TRADE_SUCCESS".equals(trade_status) || "TRADE_FINISHED".equals(trade_status)) {
status = "2";
//交易创建,等待买家付款
} else if ("WAIT_BUYER_PAY".equals(trade_status)) {
status = "1";
//未付款交易超时关闭,或支付完成后全额退款
} else if ("TRADE_CLOSED".equals(trade_status)) {
status = "3";
}
return status;
}
/**
* 手机端吊起支付
*
* @param order @return
* @param request1
* @return
* @throws Exception
*/
@Override
public String mAliPayLine(Order order, HttpServletRequest request1) throws Exception {
AlipayClient alipayClient = this.initAlipayClient();
// 根据订单交易号查询订单
order = payOrderMapper.findOutTradeNoOrder(order.getOutTradeNo());
if (null == order) {
return "没有该订单";
}
String out_trade_no = order.getOutTradeNo();
String total_amount = String.valueOf(order.getRmbPrice());
String subject = "用户" + order.getUsername() + "支付订单";
AlipayTradeWapPayRequest aliRequest = new AlipayTradeWapPayRequest();
// 设置回调地址
//alipayConfig.return_url
aliRequest.setReturnUrl(alipayConfig.return_url);
// alipayConfig.notify_url
aliRequest.setNotifyUrl(alipayConfig.notify_url);
JSONObject bizContent = new JSONObject();
bizContent.put("out_trade_no", out_trade_no);
bizContent.put("subject", order.getName());
// 获取本地Ip 判断是否是测试ip
String ip = IpUtils.getHostIp();
if (StringUtils.isNotBlank(ip)) {
// ip.contains("192.168.1")||ip.contains("192.168.3.") || ip.contains("127.0.0.1") || order.getUserId() == 223695
if (ip.contains("192.168.1")||ip.contains("192.168.3.") || ip.contains("127.0.0.1")) {
bizContent.put("total_amount", "0.01");
} else {
bizContent.put("total_amount", total_amount);
}
} else {
bizContent.put("total_amount", total_amount);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
bizContent.put("product_code", "QUICK_WAP_WAY");
Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, 5);
bizContent.put("time_expire", sdf.format(nowTime.getTime()));
商品明细信息,按需传入
//JSONArray goodsDetail = new JSONArray();
//JSONObject goods1 = new JSONObject();
//goods1.put("goods_id", "goodsNo1");
//goods1.put("goods_name", "子商品1");
//goods1.put("quantity", 1);
//goods1.put("price", 0.01);
//goodsDetail.add(goods1);
//bizContent.put("goods_detail", goodsDetail);
扩展信息,按需传入
//JSONObject extendParams = new JSONObject();
//extendParams.put("sys_service_provider_id", "2088511833207846");
//bizContent.put("extend_params", extendParams);
aliRequest.setBizContent(bizContent.toString());
AlipayTradeWapPayResponse response = alipayClient.pageExecute(aliRequest);
if (response.isSuccess()) {
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}
String result = response.getBody();
return result;
}
}
**回调:**
/**
* 异步通知支付结果
*
* @param request
* @return String
* @throws AlipayApiException
* @throws ParseException
*/
@Transactional
@PostMapping("/asynch")
public String alipayNotify(HttpServletRequest request) throws Exception {
logger.info("支付宝异步回调:" + request.getParameterMap().toString());
// 获取支付宝的请求信息
Map<String, String> map = new HashMap<>();
Map<String, String[]> requestParams = request.getParameterMap();
if (requestParams.isEmpty()) {
return "failure";
}
// 将 Map<String,String[]> 转为 Map<String,String>
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
String name = iter.next();
String[] values = requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
}
map.put(name, valueStr);
}
// 验签
boolean signVerified = AlipaySignature.rsaCheckV1(map, alipayConfig.ZFB_pubile_key, alipayConfig.charset,
alipayConfig.sign_type);
// 验签通过
if (signVerified) {
//支付成功后进行操作
String outTradeNo = map.get("out_trade_no");
if (StringUtils.isNotBlank(outTradeNo)) {
Order order = payOrderService.findOutTradeNoOrder(outTradeNo);
if (null != order && 1 == order.getStatus()) {
// 业务代码
}
}
}
}
return "failure";
}