注销支付宝

master
Diyu0904 2025-03-15 09:35:03 +08:00
parent 4ebcb60f17
commit 14576812ae
8 changed files with 1175 additions and 1197 deletions

View File

@ -1,303 +1,303 @@
package com.mcwl.web.controller.pay.AliPay;
import cn.hutool.core.lang.UUID;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.alipay.api.domain.AlipayAccount;
import com.alipay.easysdk.factory.Factory;
import com.mcwl.common.annotation.Anonymous;
import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.common.core.redis.RedisCache;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.ShareCodeUtils;
import com.mcwl.pay.config.AliConfig;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.domain.OrderTradeDto;
import com.mcwl.pay.domain.vo.PayVo;
import com.mcwl.pay.service.AliPayService;
import com.mcwl.pay.service.OrderTradeService;
import com.mcwl.system.domain.SysUserPayAccount;
import com.mcwl.system.service.ISysUserPayAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.FileNotFoundException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.pay
* @FilenameOrderTradeController
* @Description
* @Date2025/1/3 14:46
*/
@Controller
@RequestMapping("/ali/pay")
@Validated
@Api(tags = "支付模块")
public class AliPayController extends BaseController {
@Autowired
private OrderTradeService orderTradeService;
@Autowired
private ISysUserPayAccountService sysUserPayAccountService;
@Autowired
private AliPayService aliPayService;
@Autowired
private AliConfig aliConfig;
@Autowired
private RedisCache redisCache;
@Value("${mall.mgt.aliPayConfig.bindUrl}")
private String bindUrl;
/**
*
*
* @param response
* @throws Exception
*/
@ApiOperation(value = "支付宝绑定")
@GetMapping("/generateQrCode")
@ResponseBody
public R<String> generateQrCode(HttpServletResponse response) throws Exception {
String scope = "auth_user"; // 需要获取用户信息
String appId = aliConfig.getAppId();
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
// 线上
//package com.mcwl.web.controller.pay.AliPay;
//
//import cn.hutool.core.lang.UUID;
//import cn.hutool.extra.qrcode.QrCodeUtil;
//import com.alipay.api.domain.AlipayAccount;
//import com.alipay.easysdk.factory.Factory;
//import com.mcwl.common.annotation.Anonymous;
//import com.mcwl.common.constant.HttpStatus;
//import com.mcwl.common.core.controller.BaseController;
//import com.mcwl.common.core.domain.AjaxResult;
//import com.mcwl.common.core.domain.R;
//import com.mcwl.common.core.redis.RedisCache;
//import com.mcwl.common.utils.SecurityUtils;
//import com.mcwl.common.utils.ShareCodeUtils;
//import com.mcwl.pay.config.AliConfig;
//import com.mcwl.pay.domain.OrderTrade;
//import com.mcwl.pay.domain.OrderTradeDto;
//import com.mcwl.pay.domain.vo.PayVo;
//import com.mcwl.pay.service.AliPayService;
//import com.mcwl.pay.service.OrderTradeService;
//import com.mcwl.system.domain.SysUserPayAccount;
//import com.mcwl.system.service.ISysUserPayAccountService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.apache.ibatis.annotations.Param;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Controller;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.validation.Valid;
//import javax.validation.constraints.Min;
//import javax.validation.constraints.NotBlank;
//import javax.validation.constraints.NotNull;
//import javax.validation.constraints.Pattern;
//import java.io.FileNotFoundException;
//import java.net.URLEncoder;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Objects;
//import java.util.Optional;
//
///**
// * @AuthorChenYan
// * @ProjectMcWl
// * @Packagecom.mcwl.web.controller.pay
// * @FilenameOrderTradeController
// * @Description 支付模块
// * @Date2025/1/3 14:46
// */
//
//@Controller
//@RequestMapping("/ali/pay")
//@Validated
//@Api(tags = "支付模块")
//public class AliPayController extends BaseController {
//
// @Autowired
// private OrderTradeService orderTradeService;
//
// @Autowired
// private ISysUserPayAccountService sysUserPayAccountService;
//
// @Autowired
// private AliPayService aliPayService;
//
// @Autowired
// private AliConfig aliConfig;
//
//
// @Autowired
// private RedisCache redisCache;
//
// @Value("${mall.mgt.aliPayConfig.bindUrl}")
// private String bindUrl;
//
//
// /**
// * 授权二维码
// *
// * @param response 响应
// * @throws Exception 抛出异常
// */
// @ApiOperation(value = "支付宝绑定")
// @GetMapping("/generateQrCode")
// @ResponseBody
// public R<String> generateQrCode(HttpServletResponse response) throws Exception {
// String scope = "auth_user"; // 需要获取用户信息
// String appId = aliConfig.getAppId();
// String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
//
// String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
// // 线上
//// String authUrl = String.format(
//// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
//// appId, scope, encodedRedirectUri, state
//// );
// // 沙箱
// String authUrl = String.format(
// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
// "https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
// appId, scope, encodedRedirectUri, state
// );
// 沙箱
String authUrl = String.format(
"https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
appId, scope, encodedRedirectUri, state
);
// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
return R.ok(authUrl, "成功");
}
/**
*
*/
@GetMapping("/queryBindStatus")
@ApiOperation(value = "支付宝绑定状态查询")
@ResponseBody
public R<Object> queryTradeStatus() throws Exception {
return aliPayService.queryBindStatus();
}
/**
*
*
* @param authCode
*/
@GetMapping("/callback")
public String callback(@RequestParam("auth_code") String authCode, String state) throws FileNotFoundException {
System.out.println("authCode = " + authCode);
String result = aliPayService.bindingCallback(authCode, state);
if ("success".equals(result)) {
return "binding-success";
} else {
return "binding-fail";
}
}
// /**
// * 账户余额查询
// */
// @GetMapping("/balance")
// @ResponseBody
// public AjaxResult balance() throws AlipayApiException {
// String balance = aliPayService.balance();
// return AjaxResult.success(balance);
//
//// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
// return R.ok(authUrl, "成功");
// }
/**
*
*
* @param orderTradeDto
* @param response
* @throws Exception
*/
@Anonymous
@PostMapping("/doPay")
@ApiOperation(value = "支付宝支付")
@ResponseBody
public R<PayVo> doPay(@Valid
@RequestBody
OrderTradeDto orderTradeDto,
HttpServletResponse response) throws Exception {
PayVo payVo = null;
String type = orderTradeDto.getType();
if ("member".equalsIgnoreCase(type)) {
if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"商品id不能为空");
}
payVo = aliPayService.memberPay(orderTradeDto);
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
} else if ("points".equalsIgnoreCase(type)) {
payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
} else if ("wallet".equalsIgnoreCase(type)) {
// 充值金额只能是整数
if (orderTradeDto.getAmount() % 1 != 0) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"充值金额只能是整数");
}
payVo = aliPayService.walletPay(orderTradeDto.getAmount());
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
} else {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"订单类型错误");
}
return R.ok(payVo);
}
/**
*
*/
@Anonymous
@GetMapping("/fetch")
@ResponseBody
@ApiOperation(value = "提现")
public R<String> fetch(@Valid
@NotNull(message = "提现金额不能为空")
@Pattern(regexp = "^(0|(?!0\\d)[1-9]\\d*)(\\.\\d{2})?$", message = "金额格式错误(必须保留两位小数)")
String amount) throws Exception {
SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
.eq(SysUserPayAccount::getUserId, SecurityUtils.getUserId())
.eq(SysUserPayAccount::getType, 0)
.one();
if (Objects.isNull(sysUserPayAccount)) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"请先绑定支付宝");
}
if (Double.parseDouble(amount) < 0.1) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"提现金额最小为0.1");
}
return aliPayService.fetch(amount.toString());
}
/**
*
*
* @param request
* @return
* @throws Exception
*/
@Anonymous
@PostMapping("/notify") // 注意这里必须是POST接口
@ResponseBody
public String payNotify(HttpServletRequest request) throws Exception {
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
System.out.println("=========支付宝异步回调========");
Map<String, String> params = new HashMap<>();
Map<String, String[]> requestParams = request.getParameterMap();
for (String name : requestParams.keySet()) {
params.put(name, request.getParameter(name));
// System.out.println(name + " = " + request.getParameter(name));
}
// 支付宝验签
if (Factory.Payment.Common().verifyNotify(params)) {
// System.out.println("交易名称: " + params.get("subject"));
// System.out.println("交易状态: " + params.get("trade_status"));
// System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
// System.out.println("商户订单号: " + params.get("out_trade_no"));
// System.out.println("交易金额: " + params.get("total_amount"));
// System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
// System.out.println("买家付款时间: " + params.get("gmt_payment"));
// System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
// 验签通过
String code = params.get("out_trade_no"); // 商户订单号
OrderTrade orderTrade = orderTradeService.lambdaQuery()
.eq(OrderTrade::getCode, code)
.one();
if (Objects.isNull(orderTrade)) {
return "failure";
}
// 获取订单后缀
String suffix = code.substring(code.lastIndexOf("_") + 1);
orderTradeService.orderHandler(orderTrade, suffix, params);
// 更新订单状态
// if (!StringUtils.isEmpty(orderTradeJson)) {
// OrderTrade orderTrade = JSONUtil.toBean(orderTradeJson, OrderTrade.class);
// // 支付宝交易凭证号
// orderTrade.setPaymentMethod(params.get("trade_no"));
// orderTrade.setTransactionId(1);
// orderTrade.setOrderTime(DateUtils.parseDate(params.get("gmt_payment")));
// orderTrade.setOrderStatus(3);
// orderTrade.setPayStatus(2);
// String totalAmountStr = params.get("total_amount");
// if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
// BigDecimal totalAmount = new BigDecimal(totalAmountStr);
// orderTrade.setTotalAmount(totalAmount.intValue());
// }
// String buyerPayAmountStr = params.get("buyer_pay_amount");
// if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
// BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
// orderTrade.setPaymentAmount(buyerPayAmount.intValue());
// }
// orderTradeService.save(orderTrade);
//
// /**
// * 支付宝绑定状态查询
// */
// @GetMapping("/queryBindStatus")
// @ApiOperation(value = "支付宝绑定状态查询")
// @ResponseBody
// public R<Object> queryTradeStatus() throws Exception {
//
// return aliPayService.queryBindStatus();
// }
//
// /**
// * 授权回调
// *
// * @param authCode 授权码
// */
// @GetMapping("/callback")
// public String callback(@RequestParam("auth_code") String authCode, String state) throws FileNotFoundException {
//
// System.out.println("authCode = " + authCode);
// String result = aliPayService.bindingCallback(authCode, state);
// if ("success".equals(result)) {
// return "binding-success";
// } else {
// return "binding-fail";
// }
// }
//
//// /**
//// * 账户余额查询
//// */
//// @GetMapping("/balance")
//// @ResponseBody
//// public AjaxResult balance() throws AlipayApiException {
//// String balance = aliPayService.balance();
//// return AjaxResult.success(balance);
//// }
//
//
// /**
// * 支付接口
// *
// * @param orderTradeDto 订单实体
// * @param response 响应
// * @throws Exception
// */
// @Anonymous
// @PostMapping("/doPay")
// @ApiOperation(value = "支付宝支付")
// @ResponseBody
// public R<PayVo> doPay(@Valid
// @RequestBody
// OrderTradeDto orderTradeDto,
// HttpServletResponse response) throws Exception {
// PayVo payVo = null;
//
// String type = orderTradeDto.getType();
//
// if ("member".equalsIgnoreCase(type)) {
// if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"商品id不能为空");
// }
// payVo = aliPayService.memberPay(orderTradeDto);
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
// } else if ("points".equalsIgnoreCase(type)) {
// payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
// } else if ("wallet".equalsIgnoreCase(type)) {
// // 充值金额只能是整数
// if (orderTradeDto.getAmount() % 1 != 0) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"充值金额只能是整数");
// }
// payVo = aliPayService.walletPay(orderTradeDto.getAmount());
//// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
// } else {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"订单类型错误");
// }
//
// return R.ok(payVo);
// }
//
// /**
// * 提现接口
// */
// @Anonymous
// @GetMapping("/fetch")
// @ResponseBody
// @ApiOperation(value = "提现")
// public R<String> fetch(@Valid
// @NotNull(message = "提现金额不能为空")
// @Pattern(regexp = "^(0|(?!0\\d)[1-9]\\d*)(\\.\\d{2})?$", message = "金额格式错误(必须保留两位小数)")
// String amount) throws Exception {
//
// SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
// .eq(SysUserPayAccount::getUserId, SecurityUtils.getUserId())
// .eq(SysUserPayAccount::getType, 0)
// .one();
//
// if (Objects.isNull(sysUserPayAccount)) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"请先绑定支付宝");
// }
//
//
// if (Double.parseDouble(amount) < 0.1) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"提现金额最小为0.1");
// }
//
// return aliPayService.fetch(amount.toString());
// }
//
//
// /**
// * 支付回调接口
// *
// * @param request
// * @return
// * @throws Exception
// */
// @Anonymous
// @PostMapping("/notify") // 注意这里必须是POST接口
// @ResponseBody
// public String payNotify(HttpServletRequest request) throws Exception {
//
//
// if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
// System.out.println("=========支付宝异步回调========");
//
// Map<String, String> params = new HashMap<>();
// Map<String, String[]> requestParams = request.getParameterMap();
// for (String name : requestParams.keySet()) {
// params.put(name, request.getParameter(name));
// // System.out.println(name + " = " + request.getParameter(name));
// }
//
// // 支付宝验签
// if (Factory.Payment.Common().verifyNotify(params)) {
//// System.out.println("交易名称: " + params.get("subject"));
//// System.out.println("交易状态: " + params.get("trade_status"));
//// System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
//// System.out.println("商户订单号: " + params.get("out_trade_no"));
//// System.out.println("交易金额: " + params.get("total_amount"));
//// System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
//// System.out.println("买家付款时间: " + params.get("gmt_payment"));
//// System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
// // 验签通过
//
// String code = params.get("out_trade_no"); // 商户订单号
// OrderTrade orderTrade = orderTradeService.lambdaQuery()
// .eq(OrderTrade::getCode, code)
// .one();
// if (Objects.isNull(orderTrade)) {
// return "failure";
// }
} else {
// 验签失败
System.out.println("验签失败");
}
} else {
// 验签失败
System.out.println("验签失败");
}
return "success";
}
}
// // 获取订单后缀
// String suffix = code.substring(code.lastIndexOf("_") + 1);
//
// orderTradeService.orderHandler(orderTrade, suffix, params);
//
// // 更新订单状态
//// if (!StringUtils.isEmpty(orderTradeJson)) {
//// OrderTrade orderTrade = JSONUtil.toBean(orderTradeJson, OrderTrade.class);
//// // 支付宝交易凭证号
//// orderTrade.setPaymentMethod(params.get("trade_no"));
//// orderTrade.setTransactionId(1);
//// orderTrade.setOrderTime(DateUtils.parseDate(params.get("gmt_payment")));
//// orderTrade.setOrderStatus(3);
//// orderTrade.setPayStatus(2);
//// String totalAmountStr = params.get("total_amount");
//// if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
//// BigDecimal totalAmount = new BigDecimal(totalAmountStr);
//// orderTrade.setTotalAmount(totalAmount.intValue());
//// }
//// String buyerPayAmountStr = params.get("buyer_pay_amount");
//// if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
//// BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
//// orderTrade.setPaymentAmount(buyerPayAmount.intValue());
//// }
//// orderTradeService.save(orderTrade);
//// }
// } else {
// // 验签失败
// System.out.println("验签失败");
// }
// } else {
// // 验签失败
// System.out.println("验签失败");
// }
//
// return "success";
// }
//
//
//}

View File

@ -1,163 +1,163 @@
package com.mcwl.web.controller.pay.AliPay;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
import com.alipay.easysdk.payment.common.models.AlipayTradeCloseResponse;
import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
import com.mcwl.common.JSONUtils;
import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.core.redis.RedisCache;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.service.AliPayService;
import com.mcwl.pay.service.OrderTradeService;
import com.mcwl.resource.domain.dto.ProductRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.pay
* @FilenameOrderTradeController
* @Description
* @Date2025/1/3 14:46
*/
@RestController
@RequestMapping("/order")
@Validated
@Api(tags = "订单模块")
public class OrderTradeController extends BaseController {
@Autowired
private Config config;
@Autowired
private OrderTradeService orderTradeService;
@Autowired
private AliPayService aliPayService;
@Autowired
private RedisCache redisCache;
/**
*
*/
@PostMapping("/buy")
@ApiOperation(value = "购买产品")
public R<Object> buy(@Valid @RequestBody ProductRes productRes) throws Exception {
orderTradeService.productHandler(productRes);
return R.ok();
}
/**
*
*/
@GetMapping("/list")
@ApiOperation(value = "查询订单列表")
public TableDataInfo list(OrderTrade orderTrade) {
startPage();
List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
return getDataTable(list);
}
/**
*
*/
@PostMapping("/add")
@ApiOperation(value = "新增订单")
public R<Object> add(@RequestBody OrderTrade orderTrade) {
// 获取当前用户
Long userId = SecurityUtils.getUserId();
if (userId == null) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
}
orderTrade.setUserId(userId);
return R.ok(orderTradeService.insertMallProduct(orderTrade));
}
/**
*
*/
@PostMapping("/update")
@ApiOperation(value = "修改订单")
public R<Object> update(@RequestBody OrderTrade orderTrade) {
// 获取当前用户
Long userId = SecurityUtils.getUserId();
if (userId == null) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
}
orderTrade.setUserId(userId);
orderTradeService.updateMallProduct(orderTrade);
return R.ok();
}
/**
*
*/
@PostMapping
@ApiOperation(value = "删除订单")
public R<Object> remove(@RequestBody IdsParam ids) {
orderTradeService.deleteMallProductByIds(ids);
return R.ok();
}
/**
*
*/
@GetMapping("/queryTradeStatus")
@ApiOperation(value = "查询交易状态")
public R<Object> queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") String outTradeNo) throws Exception {
return aliPayService.queryTradeStatus(outTradeNo);
}
/**
*
*/
// @GetMapping("/cancelTrade")
// public AjaxResult cancelTrade(String outTradeNo) throws Exception {
// // 关闭交易
// AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(outTradeNo);
// if (cancel.getCode().equals("10000")) {
// return AjaxResult.success("关闭成功");
// }
// return AjaxResult.error("关闭失败");
//package com.mcwl.web.controller.pay.AliPay;
//
//import com.alipay.easysdk.factory.Factory;
//import com.alipay.easysdk.kernel.Config;
//import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
//import com.alipay.easysdk.payment.common.models.AlipayTradeCloseResponse;
//import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
//import com.mcwl.common.JSONUtils;
//import com.mcwl.common.constant.HttpStatus;
//import com.mcwl.common.core.controller.BaseController;
//import com.mcwl.common.core.domain.AjaxResult;
//import com.mcwl.common.core.domain.R;
//import com.mcwl.common.core.page.TableDataInfo;
//import com.mcwl.common.core.redis.RedisCache;
//import com.mcwl.common.domain.IdsParam;
//import com.mcwl.common.utils.SecurityUtils;
//import com.mcwl.pay.domain.OrderTrade;
//import com.mcwl.pay.service.AliPayService;
//import com.mcwl.pay.service.OrderTradeService;
//import com.mcwl.resource.domain.dto.ProductRes;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import javax.validation.constraints.NotBlank;
//import java.util.List;
//import java.util.Map;
//
///**
// * @AuthorChenYan
// * @ProjectMcWl
// * @Packagecom.mcwl.web.controller.pay
// * @FilenameOrderTradeController
// * @Description 支付模块
// * @Date2025/1/3 14:46
// */
//
//@RestController
//@RequestMapping("/order")
//@Validated
//@Api(tags = "订单模块")
//public class OrderTradeController extends BaseController {
//
// @Autowired
// private Config config;
//
// @Autowired
// private OrderTradeService orderTradeService;
//
// @Autowired
// private AliPayService aliPayService;
//
// @Autowired
// private RedisCache redisCache;
//
//
// /**
// * 购买产品
// */
// @PostMapping("/buy")
// @ApiOperation(value = "购买产品")
// public R<Object> buy(@Valid @RequestBody ProductRes productRes) throws Exception {
// orderTradeService.productHandler(productRes);
// return R.ok();
// }
/**
*
*/
// @GetMapping("/closeTrade")
// public AjaxResult closeTrade(String outTradeNo) throws Exception {
// // 关闭交易
// AlipayTradeCloseResponse close = Factory.Payment.Common().close(outTradeNo);
// if (close.getCode().equals("10000")) {
// return AjaxResult.success("关闭成功");
// }
// return AjaxResult.error("关闭失败");
//
//
// /**
// * 查询列表
// */
// @GetMapping("/list")
// @ApiOperation(value = "查询订单列表")
// public TableDataInfo list(OrderTrade orderTrade) {
// startPage();
// List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
// return getDataTable(list);
// }
}
//
// /**
// * 新增
// */
// @PostMapping("/add")
// @ApiOperation(value = "新增订单")
// public R<Object> add(@RequestBody OrderTrade orderTrade) {
// // 获取当前用户
// Long userId = SecurityUtils.getUserId();
// if (userId == null) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
// }
// orderTrade.setUserId(userId);
// return R.ok(orderTradeService.insertMallProduct(orderTrade));
// }
//
// /**
// * 修改
// */
// @PostMapping("/update")
// @ApiOperation(value = "修改订单")
// public R<Object> update(@RequestBody OrderTrade orderTrade) {
// // 获取当前用户
// Long userId = SecurityUtils.getUserId();
// if (userId == null) {
// return R.fail(HttpStatus.SHOW_ERROR_MSG,"用户未登录");
// }
// orderTrade.setUserId(userId);
// orderTradeService.updateMallProduct(orderTrade);
// return R.ok();
// }
//
// /**
// * 删除
// */
// @PostMapping
// @ApiOperation(value = "删除订单")
// public R<Object> remove(@RequestBody IdsParam ids) {
// orderTradeService.deleteMallProductByIds(ids);
// return R.ok();
// }
//
//
// /**
// * 查询交易状态
// */
// @GetMapping("/queryTradeStatus")
// @ApiOperation(value = "查询交易状态")
// public R<Object> queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") String outTradeNo) throws Exception {
// return aliPayService.queryTradeStatus(outTradeNo);
//
//
// }
//
//
// /**
// * 撤销交易
// */
//// @GetMapping("/cancelTrade")
//// public AjaxResult cancelTrade(String outTradeNo) throws Exception {
//// // 关闭交易
//// AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(outTradeNo);
//// if (cancel.getCode().equals("10000")) {
//// return AjaxResult.success("关闭成功");
//// }
//// return AjaxResult.error("关闭失败");
//// }
//
// /**
// * 关闭交易
// */
//// @GetMapping("/closeTrade")
//// public AjaxResult closeTrade(String outTradeNo) throws Exception {
//// // 关闭交易
//// AlipayTradeCloseResponse close = Factory.Payment.Common().close(outTradeNo);
//// if (close.getCode().equals("10000")) {
//// return AjaxResult.success("关闭成功");
//// }
//// return AjaxResult.error("关闭失败");
//// }
//
//
//}

View File

@ -144,12 +144,12 @@ mall:
appId: 9021000135682614
# 沙箱应用私钥
privateKey: MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQxmQGcaiKjOhayWi+zNTvpp8B5YT8jFFkjLzrD+W+T2Dwf2GfFR4p95zsCJxYeoLWdghMPA6/GMFrLbuVFpaEjuTm4icqA9N8n5d3W0j7gh+wMjZoqyJclAIeb09ut7rY6mWzilA9kWmZnUG7MOWIU70RVRYrfJectCFw/odM9lG4XIVe13X2h+1ecTQyQzLWmnvKFCfo7dQjE7fIYiWfud1ZGUneNs3u73pNWMB6ThGTTCbs0atcgM3fYOg3q7fTxIu9VcaUCJiJ/kNbL9sVEyOrSyx2f2o6w06zdEaOiQFsuDeS8QPYGMg7pf42wAfqCO6hqxQiQT5vp1hvB0o1AgMBAAECggEAIhaEYLwMSispXo8D2cES9iaOU/z91hUX6Qv2Q4anuqqoEZh8nN91Db6etTjFz1NxURvTklelxTsH97t56n26DRY0MWTYgd0Kw9Iz8MeOpKGb4nnAM97vpUq4QQBGfLRIC2ENdzu+7vA5JBFR88hsky/cWaNmJ/EbJauIIDneE7GigMR2HF7kfzdZzOBN4ZEh/ef5NKeCnEieRJJhWRgrgNXVZ44Tqi67AM7ey9pyUtBe7fgzxXtrWXBN9yKaVxxSXm3KJXFQqA6mcilFVZaxMNlAySc4MPTW8lq0ozOCOCunoeIphNz/OVIxGu3/voXFXlBfOKqOkYMVZxMY6OrvtQKBgQD0nIlXK4VW72VaGpz9kxQkRNzJV/yqaqet1GOSlPM2l0RCRFOVVdnvbQdHGPe6+HxHL1dh5MP8T/aHoP+4UXkkQCc8moS2FZxJvFH2QTSZBcSSdGL7GMpROqs38J+XlJzrhNcB20lrW6D7yMeQa4YEcXwdbD8Er/YaIqODBWYYewKBgQCXg+16RLDArciwwhf0TBWZPor2iYFDdwU5UPu7CKOhU1MLfQhG85gGpXHjB6G8cMUi/ezxh/FEl+sWOZegpkPwL5/BQS9tNYWIaC4kipPF/a5Up4DMYUHVAuuPwNqqXpvgU+rGjCns0wtPRnjrkghLkc3oTSID7o7pzUwIk2whDwKBgAys3+EIfExY82OL5X6uVGjcuKQmTw11oWK8krxRw5iclgjpCXu/ix+BAtOIU634mlgF9/02oYE9k4TLrvSaJDDgsifNyfq1e/fGLmkYT+VuCxWbulVQn4s+AwlPCrYMGWWK6KlL9638fYcOjGjLaZJpXwkXRtyzUYlhKh/r87JpAoGBAIavRp2mi/xrPvgpQQPv0k9L8llfOCHRnjoqC+thrZsNp8eRmJcBmMVnskofEZ2iHQuS71pw/n58EQTLo0ayJbhPjVJL8K3CovXzrfjbmqqoa5xi3bJQTiXdF6rMw1QpD6Uk05E1LVuQ6v/IZFr7kBYlAQWb8z3NhQq+bPU+nyLvAoGAGpBbSM8gPzdWQqkHoos0icu3cj0GhN3MU7+1Eb/rsXyh/lk5wtZTEnHjwhdUOUtwVNjvrv7CzA7unhOoaM6YcE/Zpd4zt8pjqH1Mhds7UHf4Xg+A+J4G6meYnhSwfBpOub02ncsqfBlXE0qhFv6AvcMewWndyLb8EYaUUXTYkG0=
# 线上应用公钥证书
appCertPath: /opt/cert/pro/appCertPublicKey_2021005119630093.crt
# 线上支付宝公钥证书路径
alipayCertPath: /opt/cert/pro/alipayCertPublicKey_RSA2.crt
# 线上支付宝根证书路径
alipayRootCertPath: /opt/cert/pro/alipayRootCert.crt
# # 线上应用公钥证书
# appCertPath: /opt/cert/pro/appCertPublicKey_2021005119630093.crt
# # 线上支付宝公钥证书路径
# alipayCertPath: /opt/cert/pro/alipayCertPublicKey_RSA2.crt
# # 线上支付宝根证书路径
# alipayRootCertPath: /opt/cert/pro/alipayRootCert.crt
# # 沙箱应用公钥证书
# appCertPath: D:\workspace\mochuang\mcwl-ai\mcwl-admin\src\main\resources\cert\dev\alipayPublicCert.crt
# # 沙箱支付宝公钥证书路径

View File

@ -1,22 +0,0 @@
package com.mcwl;
import com.mcwl.resource.util.MqttTemplate;
import lombok.RequiredArgsConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = McWlApplication.class)
@RunWith(SpringRunner.class)
@RequiredArgsConstructor
public class TestMQTT {
private final MqttTemplate mqttTemplate;
@Test
public void publishTest() throws Exception {
mqttTemplate.publish("workFlow/1", "test");
}
}

View File

@ -1,34 +1,34 @@
package com.mcwl.pay.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Data
@Configuration
@Component
public class AliConfig {
@Value("${mall.mgt.aliPayConfig.protocol}")
private String protocol;
@Value("${mall.mgt.aliPayConfig.gatewayHost}")
private String gatewayHost;
@Value("${mall.mgt.aliPayConfig.signType}")
private String signType;
@Value("${mall.mgt.aliPayConfig.appId}")
private String appId;
@Value("${mall.mgt.aliPayConfig.privateKey}")
private String privateKey;
@Value("${mall.mgt.aliPayConfig.appCertPath}")
private String appCertPath;
@Value("${mall.mgt.aliPayConfig.alipayCertPath}")
private String alipayCertPath;
@Value("${mall.mgt.aliPayConfig.alipayRootCertPath}")
private String alipayRootCertPath;
@Value("${mall.mgt.aliPayConfig.gatewayUrl}")
private String gatewayUrl;
@Value("${mall.mgt.aliPayConfig.notifyUrl}")
private String notifyUrl;
}
//package com.mcwl.pay.config;
//
//
//import lombok.Data;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.stereotype.Component;
//
//@Data
//@Configuration
//@Component
//public class AliConfig {
// @Value("${mall.mgt.aliPayConfig.protocol}")
// private String protocol;
// @Value("${mall.mgt.aliPayConfig.gatewayHost}")
// private String gatewayHost;
// @Value("${mall.mgt.aliPayConfig.signType}")
// private String signType;
// @Value("${mall.mgt.aliPayConfig.appId}")
// private String appId;
// @Value("${mall.mgt.aliPayConfig.privateKey}")
// private String privateKey;
// @Value("${mall.mgt.aliPayConfig.appCertPath}")
// private String appCertPath;
// @Value("${mall.mgt.aliPayConfig.alipayCertPath}")
// private String alipayCertPath;
// @Value("${mall.mgt.aliPayConfig.alipayRootCertPath}")
// private String alipayRootCertPath;
// @Value("${mall.mgt.aliPayConfig.gatewayUrl}")
// private String gatewayUrl;
// @Value("${mall.mgt.aliPayConfig.notifyUrl}")
// private String notifyUrl;
//}

View File

@ -1,27 +1,27 @@
package com.mcwl.pay.service;
import com.alipay.api.AlipayApiException;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.pay.domain.OrderTradeDto;
import com.mcwl.pay.domain.vo.PayVo;
import javax.validation.constraints.NotNull;
import java.io.FileNotFoundException;
public interface AliPayService {
String bindingCallback(String authCode, String state) throws FileNotFoundException;
PayVo memberPay(OrderTradeDto orderTradeDto) throws Exception;
PayVo pointsPay(Double paymentAmount) throws Exception;
R<String> fetch(String amount) throws AlipayApiException, FileNotFoundException;
// 查询订单状态
R<Object> queryTradeStatus(String outTradeNo) throws Exception;
PayVo walletPay(Double amount) throws Exception;
R<Object> queryBindStatus();
}
//package com.mcwl.pay.service;
//
//import com.alipay.api.AlipayApiException;
//import com.mcwl.common.core.domain.AjaxResult;
//import com.mcwl.common.core.domain.R;
//import com.mcwl.pay.domain.OrderTradeDto;
//import com.mcwl.pay.domain.vo.PayVo;
//
//import javax.validation.constraints.NotNull;
//import java.io.FileNotFoundException;
//
//public interface AliPayService {
// String bindingCallback(String authCode, String state) throws FileNotFoundException;
//
// PayVo memberPay(OrderTradeDto orderTradeDto) throws Exception;
//
// PayVo pointsPay(Double paymentAmount) throws Exception;
//
// R<String> fetch(String amount) throws AlipayApiException, FileNotFoundException;
//
// // 查询订单状态
// R<Object> queryTradeStatus(String outTradeNo) throws Exception;
//
// PayVo walletPay(Double amount) throws Exception;
//
// R<Object> queryBindStatus();
//}

View File

@ -1,45 +1,45 @@
package com.mcwl.pay.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mcwl.common.constant.QueueConstants;
import com.mcwl.memberCenter.domain.Member;
import com.mcwl.pay.domain.OrderTrade;
import com.mcwl.pay.service.AliPayService;
import com.mcwl.pay.service.OrderTradeService;
import lombok.RequiredArgsConstructor;
import org.joda.time.LocalDateTime;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
@Component("payTask")
@RequiredArgsConstructor
public class PayTask {
private final OrderTradeService orderTradeService;
/**
* 1h 0 0 0/1 * * ?
*/
public void deleteInvalidOrderTask() {
Date date = LocalDateTime.now().plusMinutes(-15).toDate();
List<OrderTrade> orderTradeList = orderTradeService.lambdaQuery()
.le(OrderTrade::getCreateTime, date)
.and(wrapper -> wrapper
.eq(OrderTrade::getOrderStatus, 4)
.or()
.eq(OrderTrade::getPayStatus, 1)
)
.list();
orderTradeService.removeBatchByIds(orderTradeList);
}
}
//package com.mcwl.pay.task;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.mcwl.common.constant.QueueConstants;
//import com.mcwl.memberCenter.domain.Member;
//import com.mcwl.pay.domain.OrderTrade;
//import com.mcwl.pay.service.AliPayService;
//import com.mcwl.pay.service.OrderTradeService;
//import lombok.RequiredArgsConstructor;
//import org.joda.time.LocalDateTime;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.List;
//import java.util.function.Consumer;
//
//@Component("payTask")
//@RequiredArgsConstructor
//public class PayTask {
//
// private final OrderTradeService orderTradeService;
//
//
// /**
// * 删除失效订单 间隔1h检查 0 0 0/1 * * ?
// */
// public void deleteInvalidOrderTask() {
//
// Date date = LocalDateTime.now().plusMinutes(-15).toDate();
//
// List<OrderTrade> orderTradeList = orderTradeService.lambdaQuery()
// .le(OrderTrade::getCreateTime, date)
// .and(wrapper -> wrapper
// .eq(OrderTrade::getOrderStatus, 4)
// .or()
// .eq(OrderTrade::getPayStatus, 1)
// )
// .list();
//
// orderTradeService.removeBatchByIds(orderTradeList);
//
// }
//
//
//}