feat: initial iShare project code

This commit is contained in:
purovps
2026-02-16 23:20:59 +08:00
parent 8c83a6fd46
commit 6f270a972e
1910 changed files with 218015 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
FROM pig4cloud/java:8-jre
MAINTAINER wangiegie@gmail.com
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom"
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /as-pay-platform
WORKDIR /as-pay-platform
EXPOSE 5010
ADD ./target/as-pay-platform.jar ./
CMD sleep 180;java $JAVA_OPTS -jar as-pay-platform.jar

View File

@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-visual</artifactId>
<version>5.2.0</version>
</parent>
<artifactId>as-pay-platform</artifactId>
<packaging>jar</packaging>
<description>支付系统</description>
<properties>
<yungouos.version>2.0.4</yungouos.version>
</properties>
<dependencies>
<!--注册中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
<!--PG-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!--DM8-->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>
<!-- druid 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!--common-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-data</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-sequence</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-extra</artifactId>
</dependency>
<!--灰度支持-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-gray</artifactId>
</dependency>
<!-- sentinel-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-sentinel</artifactId>
</dependency>
<!--feign 接口-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>as-upms-api</artifactId>
</dependency>
<!--swagger-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-swagger</artifactId>
</dependency>
<!--安全模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-xss</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-security</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-log</artifactId>
</dependency>
<!-- 支付依赖-->
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-WxPay</artifactId>
</dependency>
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-AliPay</artifactId>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
</dependency>
<dependency>
<groupId>com.yungouos.pay</groupId>
<artifactId>yungouos-pay-sdk</artifactId>
<version>${yungouos.version}</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay;
import com.pig4cloud.pigx.common.feign.annotation.EnablePigxFeignClients;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;
import com.pig4cloud.pigx.common.swagger.annotation.EnableOpenApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author lengleng
* @date 2019年05月27日17:25:38
* <p>
* 支付模块
*/
@EnableOpenApi("pay")
@EnablePigxFeignClients
@EnableDiscoveryClient
@EnablePigxResourceServer
@SpringBootApplication
public class AsPayPlatformApplication {
public static void main(String[] args) {
SpringApplication.run(AsPayPlatformApplication.class, args);
}
}

View File

@@ -0,0 +1,49 @@
package com.pig4cloud.pigx.pay.config;
import cn.hutool.core.date.DateUtil;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.common.sequence.builder.DbSeqBuilder;
import com.pig4cloud.pigx.common.sequence.properties.SequenceDbProperties;
import com.pig4cloud.pigx.common.sequence.sequence.Sequence;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* @author lengleng
* @date 2019-05-26
* <p>
* 设置发号器生成规则
*/
@Configuration
public class SequenceConfig {
/**
* 订单流水号发号器
* @param dataSource
* @param properties
* @return
*/
@Bean
public Sequence paySequence(DataSource dataSource, SequenceDbProperties properties) {
return DbSeqBuilder.create()
.bizName(() -> String.format("pay_%s_%s", TenantContextHolder.getTenantId(), DateUtil.today()))
.dataSource(dataSource).step(properties.getStep()).retryTimes(properties.getRetryTimes())
.tableName(properties.getTableName()).build();
}
/**
* 通道编号发号器
* @param dataSource
* @param properties
* @return
*/
@Bean
public Sequence channelSequence(DataSource dataSource, SequenceDbProperties properties) {
return DbSeqBuilder.create().bizName(() -> String.format("channel_%s", TenantContextHolder.getTenantId()))
.dataSource(dataSource).step(properties.getStep()).retryTimes(properties.getRetryTimes())
.tableName(properties.getTableName()).build();
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 支付渠道表
*
* @author PIG
* @date 2023-02-27 17:49:03
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/channel")
@Tag(description = "channel", name = "支付渠道表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayChannelController {
private final PayChannelService payChannelService;
/**
* 分页查询
* @param page 分页对象
* @param payChannel 支付渠道表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_channel_view')")
public R getpayChannelPage(Page page, PayChannel payChannel) {
LambdaQueryWrapper<PayChannel> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(payChannel.getChannelName()), PayChannel::getChannelName,
payChannel.getChannelName());
wrapper.eq(StrUtil.isNotBlank(payChannel.getState()), PayChannel::getState, payChannel.getState());
return R.ok(payChannelService.page(page, wrapper));
}
/**
* 通过id查询支付渠道表
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_channel_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(payChannelService.getById(id));
}
/**
* 新增支付渠道表
* @param payChannel 支付渠道表
* @return R
*/
@Operation(summary = "新增支付渠道表", description = "新增支付渠道表")
@SysLog("新增支付渠道表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_channel_add')")
public R save(@RequestBody PayChannel payChannel) {
return R.ok(payChannelService.save(payChannel));
}
/**
* 修改支付渠道表
* @param payChannel 支付渠道表
* @return R
*/
@Operation(summary = "修改支付渠道表", description = "修改支付渠道表")
@SysLog("修改支付渠道表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_channel_edit')")
public R updateById(@RequestBody PayChannel payChannel) {
return R.ok(payChannelService.updateById(payChannel));
}
/**
* 通过id删除支付渠道表
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除支付渠道表", description = "通过id删除支付渠道表")
@SysLog("通过id删除支付渠道表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_channel_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payChannelService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payChannel 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_channel_export')")
public List<PayChannel> export(PayChannel payChannel) {
return payChannelService.list(Wrappers.query(payChannel));
}
}

View File

@@ -0,0 +1,242 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/goods")
@Tag(description = "goods", name = "商品订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayGoodsOrderController {
private final PayGoodsOrderService payGoodsOrderService;
private final PayChannelService channelService;
private final ObjectMapper objectMapper;
/**
* 商品订单
* @param goods 商品
* @param response
*
* AliPayApiConfigKit.setAppId WxPayApiConfigKit.setAppId shezhi
*
*/
@SneakyThrows
@Inner(false)
@GetMapping("/buy")
@Operation(summary = "购买商品", description = "购买商品")
public void buy(PayGoodsOrder goods, HttpServletRequest request, HttpServletResponse response) {
String ua = request.getHeader(HttpHeaders.USER_AGENT);
log.info("当前扫码方式 UA:{}", ua);
if (ua.contains(PayConstants.MICRO_MESSENGER)) {
PayChannel channel = channelService.getOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP),
false);
if (channel == null) {
throw new IllegalArgumentException("公众号支付配置不存在");
}
String wxUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s"
+ "&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s";
String redirectUri = String.format("%s/admin/goods/wx?amount=%s&TENANT-ID=%s", channel.getNotifyUrl(),
goods.getAmount(), TenantContextHolder.getTenantId());
response.sendRedirect(
String.format(wxUrl, channel.getAppId(), URLUtil.encode(redirectUri), channel.getAppId()));
}
if (ua.contains(PayConstants.ALIPAY)) {
payGoodsOrderService.buy(goods, false);
}
}
@SneakyThrows
@Inner(false)
@GetMapping("/merge/buy")
@Operation(summary = "聚合支付购买商品", description = "聚合支付购买商品")
public void mergeBuy(PayGoodsOrder goods, HttpServletResponse response) {
Map<String, Object> result = payGoodsOrderService.buy(goods, true);
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(objectMapper.writeValueAsString(result));
}
/**
* oauth
* @param goods 商品信息
* @param code 回调code
* @param modelAndView
* @return
* @throws WxErrorException
*/
@Inner(false)
@SneakyThrows
@GetMapping("/wx")
@Operation(summary = "商品信息", description = "回调code")
public ModelAndView wx(PayGoodsOrder goods, String code, ModelAndView modelAndView) {
PayChannel channel = channelService.getOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP), false);
if (channel == null) {
throw new IllegalArgumentException("公众号支付配置不存在");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
WxMpService wxMpService = new WxMpServiceImpl();
WxMpDefaultConfigImpl storage = new WxMpDefaultConfigImpl();
storage.setAppId(channel.getAppId());
storage.setSecret(params.getStr("secret"));
wxMpService.setWxMpConfigStorage(storage);
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
goods.setUserId(accessToken.getOpenId());
goods.setAmount(goods.getAmount());
modelAndView.setViewName("pay");
modelAndView.addAllObjects(payGoodsOrderService.buy(goods, false));
return modelAndView;
}
/**
* 分页查询
* @param page 分页对象
* @param payGoodsOrder 商品订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
public R getpayGoodsOrderPage(Page page, PayGoodsOrder payGoodsOrder) {
LambdaQueryWrapper<PayGoodsOrder> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(payGoodsOrder.getStatus()), PayGoodsOrder::getStatus, payGoodsOrder.getStatus());
wrapper.like(Objects.nonNull(payGoodsOrder.getPayOrderId()), PayGoodsOrder::getPayOrderId,
payGoodsOrder.getPayOrderId());
return R.ok(payGoodsOrderService.page(page, wrapper));
}
/**
* 通过id查询商品订单表
* @param goodsOrderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{goodsOrderId}")
public R getById(@PathVariable("goodsOrderId") Long goodsOrderId) {
return R.ok(payGoodsOrderService.getById(goodsOrderId));
}
/**
* 新增商品订单表
* @param payGoodsOrder 商品订单表
* @return R
*/
@Operation(summary = "新增商品订单表", description = "新增商品订单表")
@SysLog("新增商品订单表")
@PostMapping
public R save(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.save(payGoodsOrder));
}
/**
* 修改商品订单表
* @param payGoodsOrder 商品订单表
* @return R
*/
@Operation(summary = "修改商品订单表", description = "修改商品订单表")
@SysLog("修改商品订单表")
@PutMapping
public R updateById(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.updateById(payGoodsOrder));
}
/**
* 通过id删除商品订单表
* @param ids goodsOrderId列表
* @return R
*/
@Operation(summary = "通过id删除商品订单表", description = "通过id删除商品订单表")
@SysLog("通过id删除商品订单表")
@DeleteMapping
public R removeById(@RequestBody Long[] ids) {
return R.ok(payGoodsOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payGoodsOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
public List<PayGoodsOrder> export(PayGoodsOrder payGoodsOrder) {
return payGoodsOrderService.list(Wrappers.query(payGoodsOrder));
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.core.kit.HttpKit;
import com.ijpay.core.kit.WxPayKit;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.common.xss.core.XssCleanIgnore;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.handler.PayNotifyCallbakHandler;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/notify")
@Tag(description = "notify", name = "通知记录日志表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayNotifyRecordController {
private final PayNotifyRecordService payNotifyRecordService;
private final PayNotifyCallbakHandler alipayCallback;
private final PayNotifyCallbakHandler weChatCallback;
private final PayNotifyCallbakHandler mergePayCallback;
/**
* 分页查询
* @param page 分页对象
* @param payNotifyRecord 通知记录日志表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_record_view')")
public R getpayNotifyRecordPage(Page page, PayNotifyRecord payNotifyRecord) {
LambdaQueryWrapper<PayNotifyRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(payNotifyRecord.getNotifyId()), PayNotifyRecord::getNotifyId,
payNotifyRecord.getNotifyId());
wrapper.eq(StrUtil.isNotBlank(payNotifyRecord.getOrderNo()), PayNotifyRecord::getOrderNo,
payNotifyRecord.getOrderNo());
return R.ok(payNotifyRecordService.page(page, wrapper));
}
/**
* 通过id查询通知记录日志表
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_record_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(payNotifyRecordService.getById(id));
}
/**
* 新增通知记录日志表
* @param payNotifyRecord 通知记录日志表
* @return R
*/
@Operation(summary = "新增通知记录日志表", description = "新增通知记录日志表")
@SysLog("新增通知记录日志表")
@PostMapping
public R save(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.save(payNotifyRecord));
}
/**
* 修改通知记录日志表
* @param payNotifyRecord 通知记录日志表
* @return R
*/
@Operation(summary = "修改通知记录日志表", description = "修改通知记录日志表")
@SysLog("修改通知记录日志表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_record_edit')")
public R updateById(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.updateById(payNotifyRecord));
}
/**
* 通过id删除通知记录日志表
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除通知记录日志表", description = "通过id删除通知记录日志表")
@SysLog("通过id删除通知记录日志表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_record_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payNotifyRecordService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 支付宝渠道异步回调
* @param request 渠道请求
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@SysLog("支付宝渠道异步回调")
@PostMapping("/ali/callbak")
@Operation(summary = "支付宝渠道异步回调", description = "支付宝渠道异步回调")
public void aliCallbak(HttpServletRequest request, HttpServletResponse response) {
// 解析回调信息
Map<String, String> params = AliPayApi.toMap(request);
response.getWriter().print(alipayCallback.handle(params));
}
/**
* 微信渠道支付回调
* @param request
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@PostMapping("/wx/callbak")
@Operation(summary = "微信渠道支付回调", description = "微信渠道支付回调")
@SysLog("微信渠道支付回调")
public String wxCallbak(HttpServletRequest request) {
String xmlMsg = HttpKit.readData(request);
log.info("微信订单回调信息:{}", xmlMsg);
Map<String, String> params = WxPayKit.xmlToMap(xmlMsg);
return weChatCallback.handle(params);
}
/**
* 聚合渠道异步回调
* @param request 渠道请求
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@PostMapping("/merge/callbak")
@Operation(summary = "聚合渠道异步回调", description = "聚合渠道异步回调")
@SysLog("聚合渠道异步回调")
public void mergeCallbak(HttpServletRequest request, HttpServletResponse response) {
// 解析回调信息
Map<String, String> params = AliPayApi.toMap(request);
response.getWriter().print(mergePayCallback.handle(params));
}
/**
* 导出excel 表格
* @param payNotifyRecord 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_record_export')")
public List<PayNotifyRecord> export(PayNotifyRecord payNotifyRecord) {
return payNotifyRecordService.list(Wrappers.query(payNotifyRecord));
}
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@RestController
@AllArgsConstructor
@RequestMapping("/refund")
@Tag(description = "refund", name = "退款订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayRefundOrderController {
private final PayRefundOrderService payRefundOrderService;
/**
* 分页查询
* @param page 分页对象
* @param payRefundOrder 退款订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_refund_view')")
public R getpayRefundOrderPage(Page page, PayRefundOrder payRefundOrder) {
LambdaQueryWrapper<PayRefundOrder> wrapper = Wrappers.lambdaQuery();
wrapper.eq(payRefundOrder.getRefundOrderId() != null, PayRefundOrder::getRefundOrderId,
payRefundOrder.getRefundOrderId());
wrapper.eq(payRefundOrder.getPayOrderId() != null, PayRefundOrder::getPayOrderId,
payRefundOrder.getPayOrderId());
wrapper.eq(StrUtil.isNotBlank(payRefundOrder.getMchId()), PayRefundOrder::getMchId, payRefundOrder.getMchId());
return R.ok(payRefundOrderService.page(page, wrapper));
}
/**
* 通过id查询退款订单表
* @param refundOrderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{refundOrderId}")
@PreAuthorize("@pms.hasPermission('pay_refund_view')")
public R getById(@PathVariable("refundOrderId") Long refundOrderId) {
return R.ok(payRefundOrderService.getById(refundOrderId));
}
/**
* 新增退款订单表
* @param payRefundOrder 退款订单表
* @return R
*/
@Operation(summary = "新增退款订单表", description = "新增退款订单表")
@SysLog("新增退款订单表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_refund_add')")
public R save(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.refund(payRefundOrder));
}
/**
* 修改退款订单表
* @param payRefundOrder 退款订单表
* @return R
*/
@Operation(summary = "修改退款订单表", description = "修改退款订单表")
@SysLog("修改退款订单表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_refund_edit')")
public R updateById(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.updateById(payRefundOrder));
}
/**
* 通过id删除退款订单表
* @param ids refundOrderId列表
* @return R
*/
@Operation(summary = "通过id删除退款订单表", description = "通过id删除退款订单表")
@SysLog("通过id删除退款订单表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_refund_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payRefundOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payRefundOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_refund_export')")
public List<PayRefundOrder> export(PayRefundOrder payRefundOrder) {
return payRefundOrderService.list(Wrappers.query(payRefundOrder));
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 支付订单表
*
* @author PIG
* @date 2023-02-28 14:18:17
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/trade")
@Tag(description = "trade", name = "支付订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayTradeOrderController {
private final PayTradeOrderService payTradeOrderService;
/**
* 分页查询
* @param page 分页对象
* @param payTradeOrder 支付订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_trade_view')")
public R getpayTradeOrderPage(Page page, PayTradeOrder payTradeOrder) {
LambdaQueryWrapper<PayTradeOrder> wrapper = Wrappers.lambdaQuery();
wrapper.like(payTradeOrder.getOrderId() != null, PayTradeOrder::getOrderId, payTradeOrder.getOrderId());
wrapper.eq(StrUtil.isNotBlank(payTradeOrder.getStatus()), PayTradeOrder::getStatus, payTradeOrder.getStatus());
return R.ok(payTradeOrderService.page(page, wrapper));
}
/**
* 通过id查询支付订单表
* @param orderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{orderId}")
@PreAuthorize("@pms.hasPermission('pay_trade_view')")
public R getById(@PathVariable("orderId") Long orderId) {
return R.ok(payTradeOrderService.getById(orderId));
}
/**
* 新增支付订单表
* @param payTradeOrder 支付订单表
* @return R
*/
@Operation(summary = "新增支付订单表", description = "新增支付订单表")
@SysLog("新增支付订单表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_trade_add')")
public R save(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.save(payTradeOrder));
}
/**
* 修改支付订单表
* @param payTradeOrder 支付订单表
* @return R
*/
@Operation(summary = "修改支付订单表", description = "修改支付订单表")
@SysLog("修改支付订单表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_trade_edit')")
public R updateById(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.updateById(payTradeOrder));
}
/**
* 通过id删除支付订单表
* @param ids orderId列表
* @return R
*/
@Operation(summary = "通过id删除支付订单表", description = "通过id删除支付订单表")
@SysLog("通过id删除支付订单表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_trade_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payTradeOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payTradeOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_trade_export')")
public List<PayTradeOrder> export(PayTradeOrder payTradeOrder) {
return payTradeOrderService.list(Wrappers.query(payTradeOrder));
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Data
@TableName("pay_channel")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "渠道")
public class PayChannel extends Model<PayChannel> {
private static final long serialVersionUID = 1L;
/**
* 渠道主键ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "渠道主键ID")
private Long id;
/**
* mchId
*/
@Schema(description = "mchId")
private String mchId;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 渠道名称,如:alipay,wechat
*/
@Schema(description = "渠道名称,如:alipay,wechat")
private String channelName;
/**
* 渠道商户ID | 12****123
*/
@Schema(description = "渠道商户ID | 12****123")
private String channelMchId;
/**
* 前端回调地址
*/
@Schema(description = "前端回调地址")
private String returnUrl;
/**
* 后端回调地址
*/
@Schema(description = "后端回调地址")
private String notifyUrl;
/**
* 渠道状态
*/
@Schema(description = "渠道状态")
private String state;
/**
* 配置参数,json字符串
*/
@Schema(description = "配置参数,json字符串")
private String param;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新时间")
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
/**
* 应用ID
*/
@Schema(description = "应用ID")
private String appId;
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Data
@TableName("pay_goods_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "商品订单表")
public class PayGoodsOrder extends Model<PayGoodsOrder> {
private static final long serialVersionUID = 1L;
/**
* 商品订单ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "商品订单ID")
private Long goodsOrderId;
/**
* 商品ID
*/
@Schema(description = "商品ID")
private String goodsId;
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String goodsName;
/**
* 金额,单位分
*/
@Schema(description = "金额,单位分")
private String amount;
/**
* 用户ID
*/
@Schema(description = "用户ID")
private String userId;
/**
* 订单状态,订单生成(0),支付成功(1),处理完成(2),处理失败(-1)
*/
@Schema(description = "订单状态,订单生成(0),支付成功(1),处理完成(2),处理失败(-1)")
private String status;
/**
* 支付订单号
*/
@Schema(description = "支付订单号")
private Long payOrderId;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Data
@TableName("pay_notify_record")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "异步通知记录")
public class PayNotifyRecord extends Model<PayNotifyRecord> {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "ID")
private Long id;
/**
* 响应ID
*/
@Schema(description = "响应ID")
private String notifyId;
/**
* 请求报文
*/
@Schema(description = "请求报文")
private String request;
/**
* 响应报文
*/
@Schema(description = "响应报文")
private String response;
/**
* 系统订单号
*/
@Schema(description = "系统订单号")
private String orderNo;
/**
* http状态
*/
@Schema(description = "http状态")
private String httpStatus;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,226 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Data
@TableName("pay_refund_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "退款订单表")
public class PayRefundOrder extends Model<PayRefundOrder> {
private static final long serialVersionUID = 1L;
/**
* 退款订单号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "退款订单号")
private Long refundOrderId;
/**
* 支付订单号
*/
@Schema(description = "支付订单号")
private Long payOrderId;
/**
* 渠道支付单号
*/
@Schema(description = "渠道支付单号")
private String channelPayOrderNo;
/**
* 商户ID
*/
@Schema(description = "商户ID")
private String mchId;
/**
* 商户退款单号
*/
@Schema(description = "商户退款单号")
private String mchRefundNo;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 支付金额
*/
@Schema(description = "支付金额")
private String payAmount;
/**
* 退款金额,单位分
*/
@Schema(description = "退款金额,单位分")
private Long refundAmount;
/**
* 三位货币代码
*/
@Schema(description = "三位货币代码")
private String currency;
/**
* 退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-业务处理完成
*/
@Schema(description = "退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-业务处理完成")
private Integer status;
/**
* 退款结果:0-不确认结果,1-等待手动处理,2-确认成功,3-确认失败
*/
@Schema(description = "退款结果:0-不确认结果,1-等待手动处理,2-确认成功,3-确认失败")
private Integer result;
/**
* 客户端IP
*/
@Schema(description = "客户端IP")
private String clientIp;
/**
* 设备
*/
@Schema(description = "设备")
private String device;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 渠道用户标识
*/
@Schema(description = "渠道用户标识")
private String channelUser;
/**
* 用户姓名
*/
@Schema(description = "用户姓名")
private String username;
/**
* 渠道商户ID
*/
@Schema(description = "渠道商户ID")
private String channelMchId;
/**
* 渠道订单号
*/
@Schema(description = "渠道订单号")
private String channelOrderNo;
/**
* 渠道错误码
*/
@Schema(description = "渠道错误码")
private String channelErrCode;
/**
* 渠道错误描述
*/
@Schema(description = "渠道错误描述")
private String channelErrMsg;
/**
* 特定渠道发起时额外参数
*/
@Schema(description = "特定渠道发起时额外参数")
private String extra;
/**
* 通知地址
*/
@Schema(description = "通知地址")
private String notifyUrl;
/**
* 扩展参数1
*/
@Schema(description = "扩展参数1")
private String param1;
/**
* 扩展参数2
*/
@Schema(description = "扩展参数2")
private String param2;
/**
* 订单失效时间
*/
@Schema(description = "订单失效时间")
private LocalDateTime expireTime;
/**
* 订单退款成功时间
*/
@Schema(description = "订单退款成功时间")
private LocalDateTime refundSuccTime;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,196 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Data
@TableName("pay_trade_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "支付订单表")
public class PayTradeOrder extends Model<PayTradeOrder> {
private static final long serialVersionUID = 1L;
/**
* 支付订单号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "支付订单号")
private Long orderId;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 支付金额
*/
@Schema(description = "支付金额")
private String amount;
/**
* 三位货币代码
*/
@Schema(description = "三位货币代码")
private String currency;
/**
* 支付状态,0-订单生成,1-支付中(目前未使用),2-支付成功,3-业务处理完成
*/
@Schema(description = "支付状态,0-订单生成,1-支付中(目前未使用),2-支付成功,3-业务处理完成")
private String status;
/**
* 客户端IP
*/
@Schema(description = "客户端IP")
private String clientIp;
/**
* 设备
*/
@Schema(description = "设备")
private String device;
/**
* 商品标题
*/
@Schema(description = "商品标题")
private String subject;
/**
* 商品描述信息
*/
@Schema(description = "商品描述信息")
private String body;
/**
* 特定渠道发起时额外参数
*/
@Schema(description = "特定渠道发起时额外参数")
private String extra;
/**
* 渠道商户ID
*/
@Schema(description = "渠道商户ID")
private String channelMchId;
/**
* 渠道订单号
*/
@Schema(description = "渠道订单号")
private String channelOrderNo;
/**
* 渠道支付错误码
*/
@Schema(description = "渠道支付错误码")
private String errCode;
/**
* 渠道支付错误描述
*/
@Schema(description = "渠道支付错误描述")
private String errMsg;
/**
* 扩展参数1
*/
@Schema(description = "扩展参数1")
private String param1;
/**
* 扩展参数2
*/
@Schema(description = "扩展参数2")
private String param2;
/**
* 通知地址
*/
@Schema(description = "通知地址")
private String notifyUrl;
/**
* 通知次数
*/
@Schema(description = "通知次数")
private Integer notifyCount;
/**
* 最后一次通知时间
*/
@Schema(description = "最后一次通知时间")
private Long lastNotifyTime;
/**
* 订单失效时间
*/
@Schema(description = "订单失效时间")
private Long expireTime;
/**
* 订单支付成功时间
*/
@Schema(description = "订单支付成功时间")
private LocalDateTime paySuccTime;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 消息去重
*/
public interface MessageDuplicateCheckerHandler {
/**
* 判断回调消息是否重复.
* @param messageId messageId需要根据上面讲的方式构造
* @return 如果是重复消息返回false否则返回true
*/
boolean isDuplicate(String messageId);
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 支付回调处理器
*/
public interface PayNotifyCallbakHandler {
/**
* 初始化执行
* @param params
*/
void before(Map<String, String> params);
/**
* 去重处理
* @param params 回调报文
* @return
*/
Boolean duplicateChecker(Map<String, String> params);
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
Boolean verifyNotify(Map<String, String> params);
/**
* 解析报文
* @param params
* @return
*/
String parse(Map<String, String> params);
/**
* 调用入口
* @param params
* @return
*/
String handle(Map<String, String> params);
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
void saveNotifyRecord(Map<String, String> params, String result);
}

View File

@@ -0,0 +1,58 @@
package com.pig4cloud.pigx.pay.handler;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付业务
*/
public interface PayOrderHandler {
/**
* 准备支付参数
*/
default PayChannel preparePayParams() {
return null;
}
/**
* 创建商品订单
* @param goodsOrder 金额
* @return
*/
void createGoodsOrder(PayGoodsOrder goodsOrder);
/**
* 创建交易订单
* @param goodsOrder 商品订单
* @return
*/
PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder);
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
* @return obj
*/
Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder);
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder);
/**
* 调用入口
* @param goodsOrde 商品订单
* @return
*/
Object handle(PayGoodsOrder goodsOrde);
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.handler;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* @author lengleng
* @date 2023-03-01
* <p>
* 退款业务
*/
public interface PayOrderRefundHandler {
/**
* 准备支付参数
*/
default PayChannel preparePayParams() {
return null;
}
/**
* 创建商品退款订单
* @param tradeOrder 交易订单
* @return
*/
PayRefundOrder createPayRefundOrder(PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 调起渠道退款
* @param refundOrder 商品退款订单
* @param tradeOrder 交易订单
* @return obj
*/
Object refund(PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
void updateOrder(Object obj, PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 调用入口
* @param goodsOrde 商品订单
* @return
*/
Object handle(PayRefundOrder refundOrder);
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.handler.PayNotifyCallbakHandler;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
*/
@Slf4j
public abstract class AbstractPayNotifyCallbakHandler implements PayNotifyCallbakHandler {
/**
* 调用入口
* @param params
* @return
*/
@Override
public String handle(Map<String, String> params) {
// 初始化租户
before(params);
// 去重处理
if (duplicateChecker(params)) {
return null;
}
// 验签处理
if (!verifyNotify(params)) {
return null;
}
String result = parse(params);
// 保存处理结果
saveNotifyRecord(params, result);
return result;
}
/**
* 保存记录
* @param params
* @param result
* @param record
* @param notifyId
* @param recordService
*/
void saveRecord(Map<String, String> params, String result, PayNotifyRecord record, String notifyId,
PayNotifyRecordService recordService) {
record.setNotifyId(notifyId);
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
record.setOrderNo(orderNo);
record.setRequest(MapUtil.join(params, StrUtil.DASHED, StrUtil.DASHED));
record.setResponse(result);
recordService.save(record);
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import com.pig4cloud.pigx.common.sequence.sequence.Sequence;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderHandler;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author lengleng
* @date 2019-05-31
*/
public abstract class AbstractPayOrderHandler implements PayOrderHandler {
@Autowired
private PayGoodsOrderMapper goodsOrderMapper;
@Autowired
private Sequence paySequence;
/**
* 创建商品订单
* @param goodsOrder 商品订单
* @return
*/
@Override
public void createGoodsOrder(PayGoodsOrder goodsOrder) {
goodsOrder.setPayOrderId(Long.parseLong(paySequence.nextNo()));
goodsOrder.setStatus(OrderStatusEnum.INIT.getStatus());
goodsOrderMapper.insert(goodsOrder);
}
/**
* 调用入口
* @return
*/
@Override
public Object handle(PayGoodsOrder payGoodsOrder) {
PayChannel payChannel = preparePayParams();
ChannelPayApiConfigKit.put(payChannel);
createGoodsOrder(payGoodsOrder);
PayTradeOrder tradeOrder = createTradeOrder(payGoodsOrder);
Object result = pay(payGoodsOrder, tradeOrder);
updateOrder(payGoodsOrder, tradeOrder);
// 情况ttl
ChannelPayApiConfigKit.remove();
return result;
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 支付宝回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("alipayCallback")
public class AlipayPayNotifyCallbackHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
private final PayNotifyRecordService recordService;
/**
* 维护租户信息
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "passback_params");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断是否是为支付中
if (StrUtil.equals(TradeStatusEnum.WAIT_BUYER_PAY.getDescription(), params.get(PayConstants.TRADE_STATUS))) {
log.info("支付宝订单待支付 {} 不做处理", params);
return true;
}
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.OUT_TRADE_NO))) {
log.info("支付宝订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return true;
}
/**
* 解析报文
* @param params 回调报文
* @return
*/
@Override
public String parse(Map<String, String> params) {
String tradeStatus = EnumUtil.fromString(TradeStatusEnum.class, params.get(PayConstants.TRADE_STATUS))
.getStatus();
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
goodsOrder.setStatus(tradeStatus);
goodsOrderService.updateById(goodsOrder);
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setChannelOrderNo(params.get("trade_no"));
tradeOrder.setStatus(TradeStatusEnum.TRADE_SUCCESS.getStatus());
tradeOrderService.updateById(tradeOrder);
return "success";
}
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = params.get("notify_id");
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,142 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.domain.AlipayTradeRefundModel;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderRefundHandler;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
/**
* yungous 退款时限
*
* @author lengleng
* @date 2023/3/1
*/
@Service("ALIPAY_REFUND")
@RequiredArgsConstructor
public class AlipayPayOrderRefundHandler implements PayOrderRefundHandler {
private final PayRefundOrderMapper refundOrderMapper;
private final PayChannelMapper channelMapper;
private final PayTradeOrderMapper tradeOrderMapper;
private final HttpServletRequest request;
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.ALIPAY_WAP.name()));
if (channel == null) {
throw new IllegalArgumentException("支付宝网页支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder().setAppId(channel.getAppId())
.setPrivateKey(params.getStr("privateKey")).setCharset(CharsetUtil.UTF_8)
.setAliPayPublicKey(params.getStr("publicKey")).setServiceUrl(params.getStr("serviceUrl"))
.setSignType("RSA2").build();
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
return channel;
}
/**
* 创建商品退款订单
* @param refundOrder 退款订单
* @param tradeOrder 交易订单
* @return
*/
@Override
public PayRefundOrder createPayRefundOrder(PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
refundOrder.setPayOrderId(tradeOrder.getOrderId());
refundOrder.setChannelOrderNo(tradeOrder.getChannelOrderNo());
refundOrder.setChannelId(PayChannelNameEnum.ALIPAY_WAP.getName());
refundOrder.setChannelMchId(AliPayApiConfigKit.getAliPayApiConfig().getAppId());
refundOrder.setClientIp(ServletUtil.getClientIP(request));
refundOrder.setPayAmount(tradeOrder.getAmount());
refundOrderMapper.insert(refundOrder);
return refundOrder;
}
/**
* 调起渠道退款
* @param refundOrder 商品退款订单
* @param tradeOrder 交易订单
* @return obj
*/
@Override
@SneakyThrows
public Object refund(PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
AlipayTradeRefundModel refundModel = new AlipayTradeRefundModel();
refundModel.setOutTradeNo(tradeOrder.getOrderId().toString());
refundModel.setTradeNo(tradeOrder.getChannelOrderNo());
refundModel.setRefundAmount(NumberUtil.div(refundOrder.getRefundAmount().toString(), "100", 2).toString());
refundModel.setRefundReason(refundOrder.getRemark());
return AliPayApi.tradeRefundToResponse(refundModel);
}
/**
* 更新订单信息
* @param refundOrder 退款订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(Object obj, PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
AlipayTradeRefundResponse refundResponse = (AlipayTradeRefundResponse) obj;
refundOrder.setMchRefundNo(refundResponse.getTradeNo());
// 更新退款单状态成功
refundOrder.setStatus(Integer.parseInt(TradeStatusEnum.TRADE_SUCCESS.getStatus()));
refundOrder.setRefundSuccTime(LocalDateTime.now());
refundOrderMapper.updateById(refundOrder);
// 更新原订单为退款成功状态
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setStatus(OrderStatusEnum.REFUND_SUCCESS.getStatus());
tradeOrderMapper.updateById(tradeOrder);
}
/**
* 调用入口
* @param refundOrder 退款订单
* @return
*/
@Override
public Object handle(PayRefundOrder refundOrder) {
// 准备支付宝相关参数
preparePayParams();
// 根据订单ID查询交易订单
PayTradeOrder payTradeOrder = tradeOrderMapper.selectOne(
Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, refundOrder.getPayOrderId()));
// 创建退款单
createPayRefundOrder(refundOrder, payTradeOrder);
// 拉起支付宝退款
Object refund = refund(refundOrder, payTradeOrder);
// 更新库表状态
updateOrder(refund, refundOrder, payTradeOrder);
return null;
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付宝手机支付
*/
@Slf4j
@Service("ALIPAY_WAP")
@AllArgsConstructor
public class AlipayWapPayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
private final HttpServletResponse response;
/**
* 准备支付参数
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.ALIPAY_WAP.name()));
if (channel == null) {
throw new IllegalArgumentException("支付宝网页支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder().setAppId(channel.getAppId())
.setPrivateKey(params.getStr("privateKey")).setCharset(CharsetUtil.UTF_8)
.setAliPayPublicKey(params.getStr("publicKey")).setServiceUrl(params.getStr("serviceUrl"))
.setSignType("RSA2").build();
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
return channel;
}
/**
* 创建交易订单
* @param goodsOrder
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.ALIPAY_WAP.getName());
tradeOrder.setChannelMchId(AliPayApiConfigKit.getAliPayApiConfig().getAppId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("cny");
tradeOrder.setExpireTime(30L);
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public PayTradeOrder pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.setBody(tradeOrder.getBody());
model.setSubject(tradeOrder.getBody());
model.setOutTradeNo(String.valueOf(tradeOrder.getOrderId()));
model.setTimeoutExpress("30m");
// 分转成元 并且保留两位
model.setTotalAmount(NumberUtil.div(tradeOrder.getAmount(), "100", 2).toString());
model.setProductCode(goodsOrder.getGoodsId());
model.setPassbackParams(String.valueOf(TenantContextHolder.getTenantId()));
try {
log.info("拉起支付宝wap 支付参数 {}", model);
AliPayApi.wapPay(response, model, ChannelPayApiConfigKit.get().getReturnUrl(),
ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/ali/callbak");
}
catch (AlipayApiException e) {
log.error("支付宝手机支付失败", e);
tradeOrder.setErrMsg(e.getErrMsg());
tradeOrder.setErrCode(e.getErrCode());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
catch (IOException e) {
log.error("支付宝手机支付失败", e);
tradeOrder.setErrMsg(e.getMessage());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
return tradeOrder;
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Duration;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 消息去重
*/
@Service
@AllArgsConstructor
public class MessageRedisDuplicateCheckerHandler implements MessageDuplicateCheckerHandler {
private final RedisTemplate redisTemplate;
/**
* 判断回调消息是否重复.
* @param messageId messageId需要根据上面讲的方式构造
* @return 如果是重复消息true否则返回false
*/
@Override
public boolean isDuplicate(String messageId) {
return !redisTemplate.opsForValue().setIfAbsent(messageId, messageId, Duration.ofSeconds(10L));
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.core.enums.SignType;
import com.ijpay.core.enums.TradeType;
import com.ijpay.core.kit.WxPayKit;
import com.ijpay.wxpay.WxPayApi;
import com.ijpay.wxpay.WxPayApiConfig;
import com.ijpay.wxpay.WxPayApiConfigKit;
import com.ijpay.wxpay.model.UnifiedOrderModel;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 微信公众号支付
*/
@Slf4j
@Service("WEIXIN_MP")
@RequiredArgsConstructor
public class WeChatMpPayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
/**
* 准备支付参数
* @return PayChannel
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP.name()));
if (channel == null) {
throw new IllegalArgumentException("微信公众号支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
WxPayApiConfig wx = WxPayApiConfig.builder().appId(channel.getAppId()).mchId(channel.getChannelMchId())
.partnerKey(params.getStr("partnerKey")).build();
WxPayApiConfigKit.setThreadLocalWxPayApiConfig(wx);
return channel;
}
/**
* 创建交易订单
* @param goodsOrder
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.WEIXIN_MP.getName());
tradeOrder.setChannelMchId(WxPayApiConfigKit.getWxPayApiConfig().getMchId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("CNY");
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
String ip = ServletUtil.getClientIP(request);
WxPayApiConfig wxPayApiConfig = WxPayApiConfigKit.getWxPayApiConfig();
// 预订单参数
Map<String, String> params = UnifiedOrderModel.builder().appid(wxPayApiConfig.getAppId())
.mch_id(wxPayApiConfig.getMchId()).nonce_str(WxPayKit.generateStr()).body(goodsOrder.getGoodsName())
.attach(TenantContextHolder.getTenantId().toString())
.out_trade_no(String.valueOf(tradeOrder.getOrderId())).total_fee(goodsOrder.getAmount())
.spbill_create_ip(ip)
.notify_url(ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/wx/callbak")
.trade_type(TradeType.JSAPI.getTradeType()).openid(goodsOrder.getUserId()).build()
.createSign(wxPayApiConfig.getPartnerKey(), SignType.HMACSHA256);
String xmlResult = WxPayApi.pushOrder(false, params);
log.info("微信统一下单返回 {}", xmlResult);
Map<String, String> resultMap = WxPayKit.xmlToMap(xmlResult);
String prepayId = resultMap.get("prepay_id");
return WxPayKit.prepayIdCreateSign(prepayId, wxPayApiConfig.getAppId(), wxPayApiConfig.getPartnerKey(),
SignType.HMACSHA256);
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.EnumUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.core.kit.WxPayKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 微信回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("weChatCallback")
public class WeChatPayNotifyCallbackHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
private final PayNotifyRecordService recordService;
/**
* 维护租户信息
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "attach");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.OUT_TRADE_NO))) {
log.info("微信订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return true;
}
/**
* 解析报文
* @param params
* @return
*/
@Override
public String parse(Map<String, String> params) {
String tradeStatus = EnumUtil.fromString(TradeStatusEnum.class, params.get(PayConstants.RESULT_CODE))
.getStatus();
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
goodsOrder.setStatus(tradeStatus);
goodsOrderService.updateById(goodsOrder);
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setStatus(tradeStatus);
tradeOrder.setChannelOrderNo(params.get("transaction_id"));
tradeOrder.setErrMsg(params.get("err_code_des"));
tradeOrder.setErrCode(params.get("err_code"));
tradeOrderService.updateById(tradeOrder);
Map<String, String> xml = new HashMap<>(4);
xml.put("return_code", "SUCCESS");
xml.put("return_msg", "OK");
return WxPayKit.toXml(xml);
}
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = params.get("transaction_id");
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,126 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @author lengleng
* @date 2021/1/4
* <p>
* 聚合支付回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("mergePayCallback")
public class YungouosMergePayNotifyCallbakHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayNotifyRecordService recordService;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
/**
* 初始化执行
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "attach");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.MERGE_OUT_TRADE_NO))) {
log.info("聚合支付订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return Boolean.TRUE;
}
/**
* 解析报文
* @param params
* @return
*/
@Override
public String parse(Map<String, String> params) {
String mergeCode = params.get(PayConstants.MERGE_CODE);
String orderNo = params.get(PayConstants.MERGE_OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
if (OrderStatusEnum.SUCCESS.getStatus().equals(mergeCode)) {
goodsOrder.setStatus(OrderStatusEnum.SUCCESS.getStatus());
tradeOrder.setStatus(OrderStatusEnum.SUCCESS.getStatus());
}
else {
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
goodsOrderService.updateById(goodsOrder);
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setChannelOrderNo(params.get("orderNo"));
// 修改实际的支付渠道
String payChannel = params.get(PayConstants.MERGE_OUT_TRADE_NO);
tradeOrder.setChannelId(payChannel);
tradeOrderService.updateById(tradeOrder);
return "SUCCESS";
}
/**
* 保存回调记录
* @param params 回调报文
* @param result 处理结果
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = RandomUtil.randomNumbers(12);
MapUtil.renameKey(params, PayConstants.MERGE_OUT_TRADE_NO, PayConstants.OUT_TRADE_NO);
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,107 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.yungouos.pay.merge.MergePay;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
/**
* @author lengleng
* @date 2021/1/4
* <p>
* https://open.pay.yungouos.com/#/api/api/pay/merge/nativePay 服务商聚合支付模式
*/
@Slf4j
@Service("MERGE_PAY")
@RequiredArgsConstructor
public class YungouosMergePayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
/**
* 准备支付参数
* @return
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.MERGE_PAY.name()));
if (channel == null) {
throw new IllegalArgumentException("聚合支付渠道配置为空");
}
return channel;
}
/**
* 创建交易订单
* @param goodsOrder 商品订单
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.MERGE_PAY.getName());
tradeOrder.setChannelMchId(ChannelPayApiConfigKit.get().getChannelMchId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("CNY");
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
* @return obj
*/
@Override
public Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
PayChannel channel = ChannelPayApiConfigKit.get();
String money = NumberUtil.div(tradeOrder.getAmount(), "100", 2).toString();
return MergePay.nativePay(String.valueOf(tradeOrder.getOrderId()), money, channel.getChannelMchId(),
tradeOrder.getBody(), "1", TenantContextHolder.getTenantId().toString(),
ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/merge/callbak",
ChannelPayApiConfigKit.get().getReturnUrl(), "", "", "", channel.getParam());
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import org.apache.ibatis.annotations.Mapper;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Mapper
public interface PayChannelMapper extends PigxBaseMapper<PayChannel> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Mapper
public interface PayGoodsOrderMapper extends PigxBaseMapper<PayGoodsOrder> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import org.apache.ibatis.annotations.Mapper;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Mapper
public interface PayNotifyRecordMapper extends PigxBaseMapper<PayNotifyRecord> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Mapper
public interface PayRefundOrderMapper extends PigxBaseMapper<PayRefundOrder> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Mapper
public interface PayTradeOrderMapper extends PigxBaseMapper<PayTradeOrder> {
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayChannel;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
public interface PayChannelService extends IService<PayChannel> {
/**
* 新增支付渠道
* @param payChannel 支付渠道
* @return
*/
Boolean saveChannel(PayChannel payChannel);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import java.util.Map;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
public interface PayGoodsOrderService extends IService<PayGoodsOrder> {
/**
* 购买商品
* @param goodsOrder goods
* @param isMerge 是否是服务商
* @return
*/
Map<String, Object> buy(PayGoodsOrder goodsOrder, boolean isMerge);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
public interface PayNotifyRecordService extends IService<PayNotifyRecord> {
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
public interface PayRefundOrderService extends IService<PayRefundOrder> {
/**
* 退款操作
* @param refundOrder refundOrder
* @return true/false
*/
Boolean refund(PayRefundOrder refundOrder);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
public interface PayTradeOrderService extends IService<PayTradeOrder> {
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Service
@AllArgsConstructor
public class PayChannelServiceImpl extends ServiceImpl<PayChannelMapper, PayChannel> implements PayChannelService {
/**
* 新增支付渠道
* @param payChannel 支付渠道
* @return
*/
@Override
public Boolean saveChannel(PayChannel payChannel) {
return save(payChannel);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderHandler;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Slf4j
@Service
@AllArgsConstructor
public class PayGoodsOrderServiceImpl extends ServiceImpl<PayGoodsOrderMapper, PayGoodsOrder>
implements PayGoodsOrderService {
private final Map<String, PayOrderHandler> orderHandlerMap;
private final HttpServletRequest request;
/**
* 下单购买
* @param goodsOrder
* @param isMerge
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> buy(PayGoodsOrder goodsOrder, boolean isMerge) {
// 是否聚合支付
String ua = isMerge ? "MERGE_PAY" : request.getHeader(HttpHeaders.USER_AGENT);
Enum channel = PayChannelNameEnum.getChannel(ua);
PayOrderHandler orderHandler = orderHandlerMap.get(channel.name());
goodsOrder.setGoodsName("测试产品");
goodsOrder.setGoodsId("10001");
Object params = orderHandler.handle(goodsOrder);
Map<String, Object> result = new HashMap<>(4);
result.put("channel", channel.name());
result.put("goods", goodsOrder);
result.put("params", params);
return result;
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.mapper.PayNotifyRecordMapper;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Slf4j
@Service
@AllArgsConstructor
public class PayNotifyRecordServiceImpl extends ServiceImpl<PayNotifyRecordMapper, PayNotifyRecord>
implements PayNotifyRecordService {
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderRefundHandler;
import com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import com.pig4cloud.pigx.pay.utils.RefundNameEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Service
@RequiredArgsConstructor
public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderMapper, PayRefundOrder>
implements PayRefundOrderService {
private final Map<String, PayOrderRefundHandler> refundHandlerMap;
/**
* 退款操作
* @param refundOrder refundOrder
* @return true/false
*/
@Override
public Boolean refund(PayRefundOrder refundOrder) {
String channelId = refundOrder.getChannelId();
// 判断用哪个通道
if (StrUtil.containsAnyIgnoreCase(channelId, "ali")) {
refundHandlerMap.get(RefundNameEnum.ALIPAY.getName()).handle(refundOrder);
}
else {
throw new UnsupportedOperationException();
}
return null;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import org.springframework.stereotype.Service;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Service
public class PayTradeOrderServiceImpl extends ServiceImpl<PayTradeOrderMapper, PayTradeOrder>
implements PayTradeOrderService {
}

View File

@@ -0,0 +1,29 @@
package com.pig4cloud.pigx.pay.utils;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import lombok.experimental.UtilityClass;
/**
* @author lengleng
* @date 2021/2/2
*
* 聚合支付配置管理
*/
@UtilityClass
public class ChannelPayApiConfigKit {
private static final ThreadLocal<PayChannel> TL = new ThreadLocal();
public PayChannel get() {
return TL.get();
}
public void put(PayChannel channel) {
TL.set(channel);
}
public void remove() {
TL.remove();
}
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 订单状态
*/
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {
/**
* 订单初始 下单
*/
INIT("0", "下单"),
/**
* 订单支付成功
*/
SUCCESS("1", "成功"),
/**
* 订单支付完成
*/
COMPLETE("2", "完成"),
/**
* 退款成功
*/
REFUND_SUCCESS("5", "退款成功"),
/**
* 订单支付失败
*/
FAIL("-1", "失败");
/**
* 状态
*/
private String status;
/**
* 描述
*/
private String description;
}

View File

@@ -0,0 +1,63 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 支付渠道名称
*/
@AllArgsConstructor
public enum PayChannelNameEnum {
/**
* 支付宝wap支付
*/
ALIPAY_WAP("ALIPAY_WAP", "支付宝手机支付"),
/**
* 微信H5支付
*/
WEIXIN_WAP("WEIXIN_WAP", "微信H5支付"),
/**
* 微信公众号支付
*/
WEIXIN_MP("WEIXIN_MP", "微信公众号支付"),
/**
* 聚合支付
*/
MERGE_PAY("MERGE_PAY", "yungouos 一码付");
/**
* 名称
*/
@Getter
private String name;
/**
* 描述
*/
private String description;
/**
* 通过ua 判断所属渠道
* @param ua 浏览器类型
* @return
*/
public static Enum getChannel(String ua) {
if (ua.contains(PayConstants.ALIPAY)) {
return PayChannelNameEnum.ALIPAY_WAP;
}
else if (ua.contains(PayConstants.MICRO_MESSENGER)) {
return PayChannelNameEnum.WEIXIN_MP;
}
else {
return PayChannelNameEnum.MERGE_PAY;
}
}
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.utils;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 支付相关的常量
*/
public interface PayConstants {
/**
* 支付宝商户交易编号
*/
String OUT_TRADE_NO = "out_trade_no";
/**
* 支付宝浏览器标志
*/
String ALIPAY = "Alipay";
/**
* 微信浏览器标志
*/
String MICRO_MESSENGER = "MicroMessenger";
/**
* 返回码
*/
String RESULT_CODE = "result_code";
/**
* 支付状态(支付宝)
*/
String TRADE_STATUS = "trade_status";
/**
* 聚合支付返回 Code
*/
String MERGE_CODE = "code";
/**
* 聚合支付订单号
*/
String MERGE_OUT_TRADE_NO = "outTradeNo";
/**
* 支付渠道
*/
String PAY_CHANNEL = "payChannel";
}

View File

@@ -0,0 +1,13 @@
package com.pig4cloud.pigx.pay.utils;
/**
* @author lengleng
* @date 2023/3/1
*
* 支付异常错误
*/
public interface PayErrorCodes {
String UNSUPPORTED_OPERATION = "unsupported_operation";
}

View File

@@ -0,0 +1,36 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 支付渠道名称
*/
@AllArgsConstructor
public enum RefundNameEnum {
/**
* 支付宝wap支付
*/
ALIPAY("ALIPAY_REFUND", "支付宝退款"),
/**
* 微信H5支付
*/
WEIXIN("WEIXIN_REFUND", "微信退款");
/**
* 名称
*/
@Getter
private String name;
/**
* 描述
*/
private String description;
}

View File

@@ -0,0 +1,54 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-06-14
*/
@Getter
@AllArgsConstructor
public enum TradeStatusEnum {
/**
* 交易完成
*/
WAIT_BUYER_PAY("WAIT_BUYER_PAY", OrderStatusEnum.INIT.getStatus()),
/**
* TRADE_CLOSED
*/
TRADE_CLOSED("TRADE_CLOSED", OrderStatusEnum.FAIL.getStatus()),
/**
* TRADE_SUCCESS
*/
TRADE_SUCCESS("TRADE_SUCCESS", OrderStatusEnum.SUCCESS.getStatus()),
/**
* 交易关闭
*/
TRADE_FINISHED("TRADE_FINISHED", OrderStatusEnum.COMPLETE.getStatus()),
/**
* 微信支付成功
*/
SUCCESS("SUCCESS", OrderStatusEnum.SUCCESS.getStatus()),
/**
* 微信支付失败
*/
FAIL("FAIL", OrderStatusEnum.FAIL.getStatus());
/**
* 描述
*/
private String description;
/**
* 描述
*/
private String status;
}

View File

@@ -0,0 +1,18 @@
server:
port: 5010
spring:
application:
name: @artifactId@
cloud:
nacos:
username: @nacos.username@
password: @nacos.password@
discovery:
server-addr: ${NACOS_HOST:pigx-register}:${NACOS_PORT:8848}
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
config:
import:
- optional:nacos:application-@profiles.active@.yml
- optional:nacos:${spring.application.name}-@profiles.active@.yml

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
小技巧: 在根pom里面设置统一存放路径统一管理方便维护
<properties>
<log-path>/Users/lengleng</log-path>
</properties>
1. 其他模块加日志输出直接copy本文件放在resources 目录即可
2. 注意修改 <property name="${log-path}/log.path" value=""/> 的value模块
-->
<configuration debug="false" scan="false">
<property name="log.path" value="logs/${project.artifactId}"/>
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- Log file debug output -->
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
</appender>
<!-- Log file error output -->
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<logger name="org.activiti.engine.impl.db" level="DEBUG">
<appender-ref ref="debug"/>
</logger>
<!--nacos 心跳 INFO 屏蔽-->
<logger name="com.alibaba.nacos" level="OFF">
<appender-ref ref="error"/>
</logger>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="error"/>
</root>
</configuration>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayChannelMapper">
<resultMap id="payChannelMap" type="com.pig4cloud.pigx.pay.entity.PayChannel">
<id property="id" column="id"/>
<result property="appId" column="app_id"/>
<result property="channelName" column="channel_name"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelId" column="channel_id"/>
<result property="state" column="state"/>
<result property="param" column="param"/>
<result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper">
<resultMap id="payGoodsOrderMap" type="com.pig4cloud.pigx.pay.entity.PayGoodsOrder">
<id property="goodsOrderId" column="goods_order_id"/>
<result property="goodsId" column="goods_id"/>
<result property="goodsName" column="goods_name"/>
<result property="amount" column="amount"/>
<result property="userId" column="user_id"/>
<result property="status" column="status"/>
<result property="payOrderId" column="pay_order_id"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayNotifyRecordMapper">
<resultMap id="payNotifyRecordMap" type="com.pig4cloud.pigx.pay.entity.PayNotifyRecord">
<id property="id" column="id"/>
<result property="notifyId" column="notify_id"/>
<result property="request" column="request"/>
<result property="response" column="response"/>
<result property="orderNo" column="order_no"/>
<result property="httpStatus" column="http_status"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper">
<resultMap id="payRefundOrderMap" type="com.pig4cloud.pigx.pay.entity.PayRefundOrder">
<id property="refundOrderId" column="refund_]order_id"/>
<result property="payOrderId" column="pay_order_id"/>
<result property="channelPayOrderNo" column="channel_pay_order_no"/>
<result property="mchId" column="mch_id"/>
<result property="mchRefundNo" column="mch_refund_no"/>
<result property="channelId" column="channel_id"/>
<result property="payAmount" column="pay_amount"/>
<result property="refundAmount" column="refund_amount"/>
<result property="currency" column="currency"/>
<result property="status" column="status"/>
<result property="result" column="result"/>
<result property="clientIp" column="client_ip"/>
<result property="device" column="device"/>
<result property="remark" column="remark"/>
<result property="channelUser" column="channel_user"/>
<result property="username" column="username"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelOrderNo" column="channel_order_no"/>
<result property="channelErrCode" column="channel_err_code"/>
<result property="channelErrMsg" column="channel_err_msg"/>
<result property="extra" column="extra"/>
<result property="notifyurl" column="notifyUrl"/>
<result property="param1" column="param1"/>
<result property="param2" column="param2"/>
<result property="expireTime" column="expire_time"/>
<result property="refundSuccTime" column="refund_succ_time"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper">
<resultMap id="payTradeOrderMap" type="com.pig4cloud.pigx.pay.entity.PayTradeOrder">
<id property="orderId" column="order_id"/>
<result property="channelId" column="channel_id"/>
<result property="amount" column="amount"/>
<result property="currency" column="currency"/>
<result property="status" column="status"/>
<result property="clientIp" column="client_ip"/>
<result property="device" column="device"/>
<result property="subject" column="subject"/>
<result property="body" column="body"/>
<result property="extra" column="extra"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelOrderNo" column="channel_order_no"/>
<result property="errCode" column="err_code"/>
<result property="errMsg" column="err_msg"/>
<result property="param1" column="param1"/>
<result property="param2" column="param2"/>
<result property="notifyUrl" column="notify_url"/>
<result property="notifyCount" column="notify_count"/>
<result property="lastNotifyTime" column="last_notify_time"/>
<result property="expireTime" column="expire_time"/>
<result property="paySuccTime" column="pay_succ_time"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Pigx Pro 支付模块</title>
</head>
<script src="//cdn.jsdelivr.net/jquery/1.12.1/jquery.min.js"></script>
<body>
<#if channel == 'WEIXIN_WAP'>
<a href="javascript:void(0)" onclick="pay()">确认购买</a>
</#if>
</body>
</html>
<#if channel == 'WEIXIN_MP'>
<script>
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": "${params.appId}", //公众号名称,由商户传入
"timeStamp": "${params.timeStamp}", //时间戳自1970年以来的秒数
"nonceStr": "${params.nonceStr}", //随机串
"package": "${params.package}",
"signType": "${params.signType}", //微信签名方式:
"paySign": "${params.paySign}" //微信签名,paySign 采用统一的微信支付 Sign 签名生成方法,注意这里 appId 也要参与签名appId 与 config 中传入的 appId 一致即最后参与签名的参数有appId, timeStamp, nonceStr, package, signType。
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") { // 使用以上方式判断前端返回,微信团队郑重提示res.err_msg将在用户支付成功后返回 ok但并不保证它绝对可靠。
alert('支付成功!');
} else {
alert('支付失败:' + res.err_msg);
}
WeixinJSBridge.call('closeWindow');
}
);
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
</script>
</#if>
<#if channel == 'WEIXIN_WAP'>
<script>
function pay() {
window.location.href = "${params}"
}
</script>
</#if>