✨ add pigx-sentinel-dashboard

♻️  重构包名
This commit is contained in:
冷冷 committed 2019-10-12 15:49:27 +08:00
1 parent 04371e8aa0
commit 18d03b7ce3
644 files changed
+29857 -30

No files matched your search

@@ -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;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxFeignClients;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;
import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
/**
* @author lengleng
* @date 2019年05月27日17:25:38
* <p>
* 支付模块
*/
@EnablePigxSwagger2
@SpringCloudApplication
@EnablePigxFeignClients
@EnablePigxResourceServer
public class PigxPayApplication {
public static void main(String[] args) {
SpringApplication.run(PigxPayApplication.class, args);
}
}
@@ -0,0 +1,25 @@
package com.pig4cloud.pigx.pay.config;
import lombok.Data;
/**
* @author lengleng
* @date 2019-06-19
*/
@Data
public class AliPayConfig {
/**
* 订单过期时间
*/
private String expireTime;
/**
* 前端回调地址
*/
private String returnUrl;
/**
* 服务端回调地址
*/
private String notifyUrl;
}
@@ -0,0 +1,30 @@
package com.pig4cloud.pigx.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
/**
* @author lengleng
* @date 2019-06-18
*/
@Data
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "pigx.pay")
public class PayCommonProperties {
/**
* 支付宝支付参数
*/
private AliPayConfig aliPayConfig;
/**
* 微信支付参数
*/
private WxPayConfig wxPayConfig;
private String test;
}
@@ -0,0 +1,114 @@
package com.pig4cloud.pigx.pay.config;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jpay.alipay.AliPayApiConfig;
import com.jpay.alipay.AliPayApiConfigKit;
import com.jpay.weixin.api.WxPayApiConfig;
import com.jpay.weixin.api.WxPayApiConfigKit;
import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付参数初始化
*/
@Slf4j
@Configuration
@AllArgsConstructor
public class PayConfigParmaInitRunner {
public static Map<String, WxMpService> mpServiceMap = new HashMap<>();
private final PayChannelService channelService;
private final RemoteTenantService tenantService;
@Async
@Order
@SqlParser(filter = true)
@EventListener({WebServerInitializedEvent.class})
public void initPayConfig() {
List<PayChannel> channelList = new ArrayList<>();
tenantService.list(SecurityConstants.FROM_IN).getData()
.forEach(tenant -> {
TenantContextHolder.setTenantId(tenant.getId());
List<PayChannel> payChannelList = channelService
.list(Wrappers.<PayChannel>lambdaQuery()
.eq(PayChannel::getState, CommonConstants.STATUS_NORMAL));
channelList.addAll(payChannelList);
});
channelList.forEach(channel -> {
JSONObject params = JSONUtil.parseObj(channel.getParam());
//支付宝支付
if (PayChannelNameEnum.ALIPAY_WAP.getName().equals(channel.getChannelId())) {
AliPayApiConfig aliPayApiConfig = AliPayApiConfig.New()
.setAppId(channel.getAppId())
.setPrivateKey(params.getStr("privateKey"))
.setCharset(CharsetUtil.UTF_8)
.setAlipayPublicKey(params.getStr("publicKey"))
.setServiceUrl(params.getStr("serviceUrl"))
.setSignType("RSA2")
.build();
AliPayApiConfigKit.putApiConfig(aliPayApiConfig);
log.info("新增支付宝支付参数 {}", aliPayApiConfig);
}
// 微信支付
if (PayChannelNameEnum.WEIXIN_MP.getName().equals(channel.getChannelId())) {
WxPayApiConfig wx = WxPayApiConfig.New()
.setAppId(channel.getAppId())
.setMchId(channel.getChannelMchId())
.setPaternerKey(params.getStr("paternerKey"))
.setPayModel(WxPayApiConfig.PayModel.BUSINESSMODEL);
String subMchId = params.getStr("subMchId");
if (StrUtil.isNotBlank(subMchId)) {
wx.setPayModel(WxPayApiConfig.PayModel.SERVICEMODE);
wx.setSubMchId(subMchId);
}
WxPayApiConfigKit.putApiConfig(wx);
WxMpService wxMpService = new WxMpServiceImpl();
WxMpInMemoryConfigStorage storage = new WxMpInMemoryConfigStorage();
storage.setAppId(channel.getAppId());
storage.setSecret(params.getStr("secret"));
storage.setToken(params.getStr("token"));
wxMpService.setWxMpConfigStorage(storage);
mpServiceMap.put(channel.getAppId(), wxMpService);
log.info("新增微信支付参数 {} {}", wx, wxMpService);
}
});
}
}
@@ -0,0 +1,61 @@
package com.pig4cloud.pigx.pay.config;
import cn.hutool.core.date.DateUtil;
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 com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
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();
}
}
@@ -0,0 +1,20 @@
package com.pig4cloud.pigx.pay.config;
import lombok.Data;
/**
* @author lengleng
* @date 2019-06-19
*/
@Data
public class WxPayConfig {
/**
* 服务端回调地址
*/
private String notifyUrl;
/**
* 订单过期时间
*/
private String expireTime;
}
@@ -0,0 +1,116 @@
/*
* 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 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.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.config.PayConfigParmaInitRunner;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@RestController
@AllArgsConstructor
@RequestMapping("/paychannel")
@Api(value = "paychannel", tags = "paychannel管理")
public class PayChannelController {
private final PayConfigParmaInitRunner parmaInitRunner;
private final PayChannelService payChannelService;
/**
* 分页查询
*
* @param page 分页对象
* @param payChannel 渠道
* @return
*/
@GetMapping("/page")
public R getPayChannelPage(Page page, PayChannel payChannel) {
return R.ok(payChannelService.page(page, Wrappers.query(payChannel)));
}
/**
* 通过id查询渠道
*
* @param id id
* @return R
*/
@GetMapping("/{id}")
public R getById(@PathVariable("id") Integer id) {
return R.ok(payChannelService.getById(id));
}
/**
* 新增渠道
*
* @param payChannel 渠道
* @return R
*/
@SysLog("新增渠道")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_paychannel_add')")
public R save(@RequestBody PayChannel payChannel) {
payChannelService.saveChannel(payChannel);
parmaInitRunner.initPayConfig();
return R.ok();
}
/**
* 修改渠道
*
* @param payChannel 渠道
* @return R
*/
@SysLog("修改渠道")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_paychannel_edit')")
public R updateById(@RequestBody PayChannel payChannel) {
payChannelService.updateById(payChannel);
parmaInitRunner.initPayConfig();
return R.ok();
}
/**
* 通过id删除渠道
*
* @param id id
* @return R
*/
@SysLog("删除渠道")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_paychannel_del')")
public R removeById(@PathVariable Integer id) {
payChannelService.removeById(id);
parmaInitRunner.initPayConfig();
return R.ok();
}
}
@@ -0,0 +1,176 @@
/*
* 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 com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jpay.weixin.api.WxPayApiConfigKit;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.pay.config.PayConfigParmaInitRunner;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Controller
@AllArgsConstructor
@RequestMapping("/goods")
@Api(value = "goods", tags = "商品订单管理")
public class PayGoodsOrderController {
private final PayGoodsOrderService payGoodsOrderService;
/**
* 商品订单
*
* @param goods 商品
* @param modelAndView
* @return R
*/
@Inner(false)
@GetMapping("/buy")
@SysLog("购买商品")
public ModelAndView buy(PayGoodsOrder goods, HttpServletRequest request, ModelAndView modelAndView) {
String ua = request.getHeader(HttpHeaders.USER_AGENT);
if (ua.contains(PayConstants.MICRO_MESSENGER)) {
String appId = WxPayApiConfigKit.getWxPayApiConfig().getAppId();
modelAndView.setViewName("redirect:https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId +
"&redirect_uri=http%3a%2f%2fadmin.pig4cloud.com%2fpay%2fgoods%2fwx%3famount%3d" + goods.getAmount() +
"&response_type=code&scope=snsapi_base&state=" + appId);
return modelAndView;
}
modelAndView.setViewName("pay");
modelAndView.addAllObjects(payGoodsOrderService.buy(goods));
return modelAndView;
}
/**
* oauth
*
* @param goods 商品信息
* @param state appid
* @param code 回调code
* @param modelAndView
* @return
* @throws WxErrorException
*/
@Inner(false)
@SneakyThrows
@GetMapping("/wx")
public ModelAndView wx(PayGoodsOrder goods, String state, String code, ModelAndView modelAndView) {
WxMpService wxMpService = PayConfigParmaInitRunner.mpServiceMap.get(state);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
goods.setUserId(wxMpOAuth2AccessToken.getOpenId());
goods.setAmount(goods.getAmount());
modelAndView.setViewName("pay");
modelAndView.addAllObjects(payGoodsOrderService.buy(goods));
return modelAndView;
}
/**
* 分页查询
*
* @param page 分页对象
* @param payGoodsOrder 商品订单表
* @return
*/
@ResponseBody
@GetMapping("/page")
public R getPayGoodsOrderPage(Page page, PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.page(page, Wrappers.query(payGoodsOrder)));
}
/**
* 通过id查询商品订单表
*
* @param goodsOrderId id
* @return R
*/
@ResponseBody
@GetMapping("/{goodsOrderId}")
public R getById(@PathVariable("goodsOrderId") Integer goodsOrderId) {
return R.ok(payGoodsOrderService.getById(goodsOrderId));
}
/**
* 新增商品订单表
*
* @param payGoodsOrder 商品订单表
* @return R
*/
@SysLog("新增商品订单表")
@PostMapping
@ResponseBody
@PreAuthorize("@pms.hasPermission('generator_paygoodsorder_add')")
public R save(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.save(payGoodsOrder));
}
/**
* 修改商品订单表
*
* @param payGoodsOrder 商品订单表
* @return R
*/
@SysLog("修改商品订单表")
@PutMapping
@ResponseBody
@PreAuthorize("@pms.hasPermission('generator_paygoodsorder_edit')")
public R updateById(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.updateById(payGoodsOrder));
}
/**
* 通过id删除商品订单表
*
* @param goodsOrderId id
* @return R
*/
@SysLog("删除商品订单表")
@ResponseBody
@DeleteMapping("/{goodsOrderId}")
@PreAuthorize("@pms.hasPermission('generator_paygoodsorder_del')")
public R removeById(@PathVariable Integer goodsOrderId) {
return R.ok(payGoodsOrderService.removeById(goodsOrderId));
}
}
@@ -0,0 +1,154 @@
/*
* 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 com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jpay.alipay.AliPayApi;
import com.jpay.ext.kit.HttpKit;
import com.jpay.ext.kit.PaymentKit;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.handler.PayNotifyCallbakHandler;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
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.Map;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/notify")
@Api(value = "notify", tags = "notify管理")
public class PayNotifyRecordController {
private final PayNotifyRecordService payNotifyRecordService;
private final PayNotifyCallbakHandler alipayCallback;
private final PayNotifyCallbakHandler weChatCallback;
/**
* 分页查询
*
* @param page 分页对象
* @param payNotifyRecord 异步通知记录
* @return
*/
@GetMapping("/page")
public R getPayNotifyRecordPage(Page page, PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.page(page, Wrappers.query(payNotifyRecord)));
}
/**
* 通过id查询异步通知记录
*
* @param id id
* @return R
*/
@GetMapping("/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(payNotifyRecordService.getById(id));
}
/**
* 新增异步通知记录
*
* @param payNotifyRecord 异步通知记录
* @return R
*/
@SysLog("新增异步通知记录")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_paynotifyrecord_add')")
public R save(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.save(payNotifyRecord));
}
/**
* 修改异步通知记录
*
* @param payNotifyRecord 异步通知记录
* @return R
*/
@SysLog("修改异步通知记录")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_paynotifyrecord_edit')")
public R updateById(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.updateById(payNotifyRecord));
}
/**
* 通过id删除异步通知记录
*
* @param id id
* @return R
*/
@SysLog("删除异步通知记录")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_paynotifyrecord_del')")
public R removeById(@PathVariable Long id) {
return R.ok(payNotifyRecordService.removeById(id));
}
/**
* 支付宝渠道异步回调
*
* @param request 渠道请求
* @return
*/
@Inner(false)
@SneakyThrows
@PostMapping("/ali/callbak")
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
@ResponseBody
@PostMapping("/wx/callbak")
public String wxCallbak(HttpServletRequest request) {
String xmlMsg = HttpKit.readData(request);
log.info("微信订单回调信息:{}", xmlMsg);
Map<String, String> params = PaymentKit.xmlToMap(xmlMsg);
return weChatCallback.handle(params);
}
}
@@ -0,0 +1,109 @@
/*
* 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 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.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@RestController
@AllArgsConstructor
@RequestMapping("/payrefundorder")
@Api(value = "payrefundorder", tags = "payrefundorder管理")
public class PayRefundOrderController {
private final PayRefundOrderService payRefundOrderService;
/**
* 分页查询
*
* @param page 分页对象
* @param payRefundOrder 退款
* @return
*/
@GetMapping("/page")
public R getPayRefundOrderPage(Page page, PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.page(page, Wrappers.query(payRefundOrder)));
}
/**
* 通过id查询退款
*
* @param refundOrderId id
* @return R
*/
@GetMapping("/{refund]orderId}")
public R getById(@PathVariable("refund]orderId") String refundOrderId) {
return R.ok(payRefundOrderService.getById(refundOrderId));
}
/**
* 新增退款
*
* @param payRefundOrder 退款
* @return R
*/
@SysLog("新增退款")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_payrefundorder_add')")
public R save(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.save(payRefundOrder));
}
/**
* 修改退款
*
* @param payRefundOrder 退款
* @return R
*/
@SysLog("修改退款")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_payrefundorder_edit')")
public R updateById(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.updateById(payRefundOrder));
}
/**
* 通过id删除退款
*
* @param refundOrderId refundOrderId
* @return R
*/
@SysLog("删除退款")
@DeleteMapping("/{refundOrderId}")
@PreAuthorize("@pms.hasPermission('pay_payrefundorder_del')")
public R removeById(@PathVariable String refundOrderId) {
return R.ok(payRefundOrderService.removeById(refundOrderId));
}
}
@@ -0,0 +1,104 @@
/*
* 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 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.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@RestController
@AllArgsConstructor
@RequestMapping("/order" )
@Api(value = "order", tags = "订单")
public class PayTradeOrderController {
private final PayTradeOrderService payTradeOrderService;
/**
* 分页查询
* @param page 分页对象
* @param payTradeOrder 支付
* @return
*/
@GetMapping("/page" )
public R getPayTradeOrderPage(Page page, PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.page(page, Wrappers.query(payTradeOrder)));
}
/**
* 通过id查询支付
* @param orderId id
* @return R
*/
@GetMapping("/{orderId}" )
public R getById(@PathVariable("orderId" ) String orderId) {
return R.ok(payTradeOrderService.getById(orderId));
}
/**
* 新增支付
* @param payTradeOrder 支付
* @return R
*/
@SysLog("新增支付" )
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_paytradeorder_add')" )
public R save(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.save(payTradeOrder));
}
/**
* 修改支付
* @param payTradeOrder 支付
* @return R
*/
@SysLog("修改支付" )
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_paytradeorder_edit')" )
public R updateById(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.updateById(payTradeOrder));
}
/**
* 通过id删除支付
* @param orderId id
* @return R
*/
@SysLog("删除支付" )
@DeleteMapping("/{orderId}" )
@PreAuthorize("@pms.hasPermission('pay_paytradeorder_del')" )
public R removeById(@PathVariable String orderId) {
return R.ok(payTradeOrderService.removeById(orderId));
}
}
@@ -0,0 +1,94 @@
/*
* 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.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
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)
@ApiModel(description = "渠道")
public class PayChannel extends Model<PayChannel> {
private static final long serialVersionUID = 1L;
/**
* 渠道主键ID
*/
@TableId
private Integer id;
/**
* 应用ID
*/
private String appId;
/**
* 渠道ID
*/
private String channelId;
/**
* 渠道名称,如:alipay,wechat
*/
private String channelName;
/**
* 渠道商户ID
*/
private String channelMchId;
/**
* 渠道状态
*/
private String state;
/**
* 配置参数,json字符串
*/
private String param;
/**
* 备注
*/
private String remark;
/**
* 删除标记
*/
@TableLogic
private String delFlag;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 租户ID
*/
private Integer tenantId;
}
@@ -0,0 +1,90 @@
/*
* 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.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
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)
@ApiModel(description = "商品")
public class PayGoodsOrder extends Model<PayGoodsOrder> {
private static final long serialVersionUID = 1L;
/**
* 商品订单ID
*/
@TableId
private String goodsOrderId;
/**
* 商品ID
*/
private String goodsId;
/**
* 商品名称
*/
private String goodsName;
/**
* 金额,单位分
*/
private String amount;
/**
* 用户ID
*/
private String userId;
/**
* 订单状态,订单生成(0),支付成功(1),处理完成(2),处理失败(-1)
*/
private String status;
/**
* 支付订单号
*/
private String payOrderId;
/**
* 0-正常,1-删除
*/
@TableLogic
private String delFlag;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 租户ID
*/
private Integer tenantId;
}
@@ -0,0 +1,86 @@
/*
* 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.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
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)
@ApiModel(description = "异步通知记录")
public class PayNotifyRecord extends Model<PayNotifyRecord> {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long id;
/**
* 响应ID
*/
private String notifyId;
/**
* 请求报文
*/
private String request;
/**
* 响应报文
*/
private String response;
/**
* 系统订单号
*/
private String orderNo;
/**
* http状态
*/
private String httpStatus;
/**
* 删除标记
*/
@TableLogic
private String delFlag;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 租户ID
*/
private Integer tenantId;
}
@@ -0,0 +1,166 @@
/*
* 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.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
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)
@ApiModel(description = "退款")
public class PayRefundOrder extends Model<PayRefundOrder> {
private static final long serialVersionUID = 1L;
/**
* 退款订单号
*/
@TableId
private String refundOrderId;
/**
* 支付订单号
*/
private String payOrderId;
/**
* 渠道支付单号
*/
private String channelPayOrderNo;
/**
* 商户ID
*/
private String mchId;
/**
* 商户退款单号
*/
private String mchRefundNo;
/**
* 渠道ID
*/
private String channelId;
/**
* 支付金额,单位元
*/
private String payAmount;
/**
* 退款金额,单位分
*/
private Long refundAmount;
/**
* 三位货币代码,人民币:cny
*/
private String currency;
/**
* 退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-业务处理完成
*/
private String status;
/**
* 退款结果:0-不确认结果,1-等待手动处理,2-确认成功,3-确认失败
*/
private String result;
/**
* 客户端IP
*/
private String clientIp;
/**
* 设备
*/
private String device;
/**
* 备注
*/
private String remark;
/**
* 渠道用户标识,如微信openId,支付宝账号
*/
private String channelUser;
/**
* 用户姓名
*/
private String username;
/**
* 渠道商户ID
*/
private String channelMchId;
/**
* 渠道订单号
*/
private String channelOrderNo;
/**
* 渠道错误码
*/
private String channelErrCode;
/**
* 渠道错误描述
*/
private String channelErrMsg;
/**
* 特定渠道发起时额外参数
*/
private String extra;
/**
* 通知地址
*/
private String notifyurl;
/**
* 扩展参数1
*/
private String param1;
/**
* 扩展参数2
*/
private String param2;
/**
* 订单失效时间
*/
private LocalDateTime expireTime;
/**
* 订单退款成功时间
*/
private LocalDateTime refundSuccTime;
/**
* 删除标记
*/
@TableLogic
private String delFlag;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 租户ID
*/
private Integer tenantId;
}
@@ -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.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
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)
@ApiModel(description = "支付")
public class PayTradeOrder extends Model<PayTradeOrder> {
private static final long serialVersionUID = 1L;
/**
* 支付订单号
*/
@TableId(type = IdType.INPUT)
private String orderId;
/**
* 渠道ID
*/
private String channelId;
/**
* 支付金额,单位元
*/
private String amount;
/**
* 三位货币代码,人民币:cny
*/
private String currency;
/**
* 支付状态,0-订单生成,1-支付中(目前未使用),2-支付成功,3-业务处理完成
*/
private String status;
/**
* 客户端IP
*/
private String clientIp;
/**
* 设备
*/
private String device;
/**
* 商品标题
*/
private String subject;
/**
* 商品描述信息
*/
private String body;
/**
* 特定渠道发起时额外参数
*/
private String extra;
/**
* 渠道商户ID
*/
private String channelMchId;
/**
* 渠道订单号
*/
private String channelOrderNo;
/**
* 渠道支付错误码
*/
private String errCode;
/**
* 渠道支付错误描述
*/
private String errMsg;
/**
* 扩展参数1
*/
private String param1;
/**
* 扩展参数2
*/
private String param2;
/**
* 通知地址
*/
private String notifyUrl;
/**
* 通知次数
*/
private Integer notifyCount;
/**
* 最后一次通知时间
*/
private Long lastNotifyTime;
/**
* 订单失效时间
*/
private Long expireTime;
/**
* 订单支付成功时间
*/
private Long paySuccTime;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 删除标记
*/
@TableLogic
private String delFlag;
/**
* 租户ID
*/
private Integer tenantId;
}
@@ -0,0 +1,34 @@
/*
* 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);
}
@@ -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.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);
}
@@ -0,0 +1,54 @@
package com.pig4cloud.pigx.pay.handler;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付业务
*/
public interface PayOrderHandler {
/**
* 创建商品订单
*
* @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);
}
@@ -0,0 +1,81 @@
/*
* 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);
}
}
@@ -0,0 +1,65 @@
/*
* 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.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.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(paySequence.nextNo());
goodsOrder.setStatus(OrderStatusEnum.INIT.getStatus());
goodsOrderMapper.insert(goodsOrder);
}
/**
* 调用入口
*
* @return
*/
@Override
public Object handle(PayGoodsOrder payGoodsOrder) {
createGoodsOrder(payGoodsOrder);
PayTradeOrder tradeOrder = createTradeOrder(payGoodsOrder);
Object result = pay(payGoodsOrder, tradeOrder);
updateOrder(payGoodsOrder, tradeOrder);
return result;
}
}
@@ -0,0 +1,167 @@
/*
* 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.CharsetUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jpay.alipay.AliPayApiConfig;
import com.jpay.alipay.AliPayApiConfigKit;
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.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) {
Integer tenant = MapUtil.getInt(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) {
String callReq = MapUtil.join(params, StrUtil.DASHED, StrUtil.DASHED);
log.info("支付宝发起回调 报文: {}", callReq);
String appId = params.get("app_id");
if (StrUtil.isBlank(appId)) {
log.warn("支付宝回调报文 appid 为空 {}", callReq);
return false;
}
AliPayApiConfig apiConfig = AliPayApiConfigKit.getApiConfig(appId);
if (apiConfig == null) {
log.warn("支付宝回调报文 appid 不合法 {}", callReq);
return false;
}
try {
return AlipaySignature.rsaCheckV1(params, apiConfig.getAlipayPublicKey()
, CharsetUtil.UTF_8, "RSA2");
} catch (AlipayApiException e) {
log.error("支付宝验签失败", e);
return false;
}
}
/**
* 解析报文
*
* @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));
Long succTime = MapUtil.getLong(params, "time_end");
tradeOrder.setPaySuccTime(succTime);
tradeOrder.setChannelOrderNo(params.get("trade_no"));
tradeOrder.setStatus(TradeStatusEnum.TRADE_SUCCESS.getStatus());
tradeOrder.setChannelOrderNo(params.get("transaction_id"));
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);
}
}
@@ -0,0 +1,127 @@
/*
* 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.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.jpay.alipay.AliPayApi;
import com.jpay.alipay.AliPayApiConfigKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.config.PayCommonProperties;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
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 PayCommonProperties payCommonProperties;
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final HttpServletRequest request;
private final HttpServletResponse response;
/**
* 创建交易订单
*
* @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(Long.parseLong(payCommonProperties.getAliPayConfig().getExpireTime()));
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(tradeOrder.getOrderId());
model.setTimeoutExpress(payCommonProperties.getAliPayConfig().getExpireTime() + "m");
//分转成元 并且保留两位
model.setTotalAmount(NumberUtil.div(tradeOrder.getAmount(), "100", 2).toString());
model.setProductCode(goodsOrder.getGoodsId());
model.setPassbackParams(String.valueOf(TenantContextHolder.getTenantId()));
try {
AliPayApi.wapPay(response, model, payCommonProperties.getAliPayConfig().getReturnUrl()
, payCommonProperties.getAliPayConfig().getNotifyUrl());
} 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);
}
}
@@ -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));
}
}
@@ -0,0 +1,116 @@
/*
* 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 com.jpay.ext.kit.PaymentKit;
import com.jpay.weixin.api.WxPayApi;
import com.jpay.weixin.api.WxPayApiConfigKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.config.PayCommonProperties;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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")
public class WeChatMpPayOrderHandler extends AbstractPayOrderHandler {
@Autowired
private PayCommonProperties payCommonProperties;
@Autowired
private PayTradeOrderMapper tradeOrderMapper;
@Autowired
private PayGoodsOrderMapper goodsOrderMapper;
@Autowired
private HttpServletRequest request;
/**
* 创建交易订单
*
* @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);
Map<String, String> params = WxPayApiConfigKit.getWxPayApiConfig()
.setAttach(TenantContextHolder.getTenantId().toString())
.setBody(goodsOrder.getGoodsName())
.setSpbillCreateIp(ip)
.setTotalFee(goodsOrder.getAmount())
.setOpenId(goodsOrder.getUserId())
.setTradeType(WxPayApi.TradeType.JSAPI)
.setNotifyUrl(payCommonProperties.getWxPayConfig().getNotifyUrl())
.setOutTradeNo(tradeOrder.getOrderId())
.build();
String xmlResult = WxPayApi.pushOrder(false, params);
log.info(xmlResult);
Map<String, String> resultMap = PaymentKit.xmlToMap(xmlResult);
String prepayId = resultMap.get("prepay_id");
return PaymentKit.prepayIdCreateSign(prepayId);
}
/**
* 更新订单信息
*
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}
@@ -0,0 +1,145 @@
/*
* 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.jpay.ext.kit.PaymentKit;
import com.jpay.weixin.api.WxPayApiConfigKit;
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.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) {
Integer tenant = MapUtil.getInt(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) {
if (!PaymentKit.verifyNotify(params, WxPayApiConfigKit.getWxPayApiConfig().getPaternerKey())) {
log.warn("微信支付回调验签失败", params);
return null;
}
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));
Long succTime = MapUtil.getLong(params, "time_end");
tradeOrder.setPaySuccTime(succTime);
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 PaymentKit.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);
}
}
@@ -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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.pay.entity.PayChannel;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
public interface PayChannelMapper extends BaseMapper<PayChannel> {
}
@@ -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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
public interface PayGoodsOrderMapper extends BaseMapper<PayGoodsOrder> {
}
@@ -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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
public interface PayNotifyRecordMapper extends BaseMapper<PayNotifyRecord> {
}
@@ -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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
public interface PayRefundOrderMapper extends BaseMapper<PayRefundOrder> {
}
@@ -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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
public interface PayTradeOrderMapper extends BaseMapper<PayTradeOrder> {
}
@@ -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);
}
@@ -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
* @return
*/
Map<String, Object> buy(PayGoodsOrder goodsOrder);
}
@@ -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> {
}
@@ -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.PayRefundOrder;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
public interface PayRefundOrderService extends IService<PayRefundOrder> {
}
@@ -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> {
}
@@ -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);
}
}
@@ -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.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
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> buy(PayGoodsOrder goodsOrder) {
String ua = 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;
}
}
@@ -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.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 {
}
@@ -0,0 +1,34 @@
/*
* 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.PayRefundOrder;
import com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import org.springframework.stereotype.Service;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Service
public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderMapper, PayRefundOrder> implements PayRefundOrderService {
}
@@ -0,0 +1,34 @@
/*
* 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 {
}
@@ -0,0 +1,44 @@
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", "完成"),
/**
* 订单支付失败
*/
FAIL("-1", "失败");
/**
* 状态
*/
private String status;
/**
* 描述
*/
private String description;
}
@@ -0,0 +1,54 @@
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", "微信公众号支付");
/**
* 名称
*/
@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.WEIXIN_WAP;
}
}
}
@@ -0,0 +1,37 @@
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";
}
@@ -0,0 +1,52 @@
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;
}
@@ -0,0 +1,16 @@
server:
port: 5010
spring:
application:
name: @artifactId@
cloud:
nacos:
discovery:
server-addr: ${NACOS-HOST:pigx-register}:${NACOS-PORT:8848}
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yml
shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
profiles:
active: @profiles.active@
@@ -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="debug"/>
</root>
</configuration>
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ 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)
~
-->
<!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>
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ 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)
~
-->
<!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>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ 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)
~
-->
<!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>
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ 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)
~
-->
<!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>
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ 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)
~
-->
<!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>
@@ -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>