2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.api.uniapp;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
|
import com.jsowell.common.annotation.Anonymous;
|
|
|
|
|
|
import com.jsowell.common.core.controller.BaseController;
|
|
|
|
|
|
import com.jsowell.common.core.redis.RedisCache;
|
|
|
|
|
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
|
|
|
|
|
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
|
|
|
|
|
import com.jsowell.common.exception.BusinessException;
|
|
|
|
|
|
import com.jsowell.common.response.RestApiResponse;
|
|
|
|
|
|
import com.jsowell.common.util.StringUtils;
|
|
|
|
|
|
import com.jsowell.common.util.id.IdUtils;
|
2023-08-16 14:44:03 +08:00
|
|
|
|
import com.jsowell.pile.domain.MemberBasicInfo;
|
2023-03-29 15:09:51 +08:00
|
|
|
|
import com.jsowell.pile.dto.GetPayModeDTO;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.dto.PayOrderDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.PaymentScenarioDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.WeixinPayDTO;
|
2023-08-16 14:44:03 +08:00
|
|
|
|
import com.jsowell.pile.service.IMemberBasicInfoService;
|
2023-03-29 15:09:51 +08:00
|
|
|
|
import com.jsowell.pile.vo.uniapp.PayModeVO;
|
2023-08-16 14:44:03 +08:00
|
|
|
|
import com.jsowell.service.AgentDevService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.service.MemberService;
|
|
|
|
|
|
import com.jsowell.service.OrderService;
|
2023-07-27 16:44:18 +08:00
|
|
|
|
import com.jsowell.pile.dto.ApplyRefundDTO;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.wxpay.response.WechatPayNotifyParameter;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2023-03-29 15:09:51 +08:00
|
|
|
|
import java.util.List;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 支付相关controller
|
|
|
|
|
|
*/
|
2023-07-05 15:42:44 +08:00
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
@Anonymous
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/uniapp/pay")
|
|
|
|
|
|
public class PayController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private MemberService memberService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderService orderService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
2023-08-16 14:44:03 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private IMemberBasicInfoService memberBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
2023-08-11 17:44:01 +08:00
|
|
|
|
* 充值余额支付/微信余额充值
|
2023-03-04 16:29:55 +08:00
|
|
|
|
* 提供给小程序使用
|
|
|
|
|
|
* http://localhost:8080/uniapp/pay/weixinPay
|
2023-08-15 15:42:39 +08:00
|
|
|
|
* @deprecated 使用汇付支付,充值余额
|
2023-03-04 16:29:55 +08:00
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/weixinPay")
|
|
|
|
|
|
public RestApiResponse<?> weixinPay(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
|
|
|
|
|
logger.info("微信支付 param:{}", dto.toString());
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
2023-08-09 16:27:09 +08:00
|
|
|
|
if (dto != null) {
|
2023-08-09 16:37:37 +08:00
|
|
|
|
throw new BusinessException("00500005", "充值功能维护,已有余额可用,推荐使用在线支付");
|
2023-08-09 16:27:09 +08:00
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
|
2023-08-09 16:27:09 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 鉴权
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setMemberId(memberId);
|
|
|
|
|
|
String openId = memberService.getOpenIdByCode(dto.getCode());
|
|
|
|
|
|
if (StringUtils.isBlank(openId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setOpenId(openId);
|
|
|
|
|
|
// 充值余额 附加参数
|
|
|
|
|
|
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
|
|
|
|
|
|
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
|
|
|
|
|
|
paymentScenarioDTO.setMemberId(memberId);
|
|
|
|
|
|
dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
|
|
|
|
|
|
dto.setDescription("会员充值余额");
|
|
|
|
|
|
Map<String, Object> weixinMap = orderService.weixinPayV3(dto);
|
|
|
|
|
|
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
|
2023-08-09 16:27:09 +08:00
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("充值余额支付warn", e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
2023-03-04 16:29:55 +08:00
|
|
|
|
} catch (Exception e) {
|
2023-08-09 16:27:09 +08:00
|
|
|
|
logger.warn("充值余额支付error", e);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
response = new RestApiResponse<>();
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-29 15:09:51 +08:00
|
|
|
|
* 7002 支付订单
|
2023-03-04 16:29:55 +08:00
|
|
|
|
* http://localhost:8080/uniapp/pay/payOrder
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/payOrder")
|
|
|
|
|
|
public RestApiResponse<?> payOrder(HttpServletRequest request, @RequestBody PayOrderDTO dto) {
|
2023-05-26 10:19:35 +08:00
|
|
|
|
logger.info("wechatpay支付订单 param:{}", dto.toString());
|
2023-03-04 16:29:55 +08:00
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
|
|
|
|
|
|
// 支付订单加锁
|
|
|
|
|
|
String lockKey = "pay_order_" + dto.getOrderCode();
|
|
|
|
|
|
String lockValue = IdUtils.fastUUID();
|
|
|
|
|
|
try {
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
2023-03-07 15:05:03 +08:00
|
|
|
|
if (dto.getPayAmount() == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
dto.setMemberId(memberId);
|
|
|
|
|
|
dto.setLockValue(lockValue);
|
|
|
|
|
|
// redis锁
|
|
|
|
|
|
Boolean isLock = redisCache.lock(lockKey, lockValue, 60);
|
|
|
|
|
|
Map<String, Object> map = null;
|
|
|
|
|
|
if (isLock) {
|
|
|
|
|
|
map = orderService.payOrder(dto);
|
|
|
|
|
|
}
|
|
|
|
|
|
response = new RestApiResponse<>(map);
|
|
|
|
|
|
} catch (BusinessException e) {
|
2023-05-26 10:19:35 +08:00
|
|
|
|
logger.warn("wechatpay支付订单 warn param:{}", dto.toString(), e);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
2023-05-26 10:19:35 +08:00
|
|
|
|
logger.error("wechatpay支付订单 error param:{}", dto.toString(), e);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_ERROR);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
// 支付订单解锁
|
|
|
|
|
|
if (lockValue.equals(redisCache.getCacheObject(lockKey).toString())) {
|
|
|
|
|
|
redisCache.unLock(lockKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-26 10:19:35 +08:00
|
|
|
|
logger.info("wechatpay支付订单 result:{}", JSONObject.toJSONString(response));
|
2023-03-04 16:29:55 +08:00
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-29 15:09:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 7003 获取支付方式
|
|
|
|
|
|
* http://localhost:8080/uniapp/pay/getPayMode
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/getPayMode")
|
|
|
|
|
|
public RestApiResponse<?> getPayMode(HttpServletRequest request, @RequestBody GetPayModeDTO dto) {
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
2023-04-21 09:35:42 +08:00
|
|
|
|
dto.setMemberId(getMemberIdByAuthorization(request));
|
2023-03-29 15:09:51 +08:00
|
|
|
|
List<PayModeVO> list = orderService.getPayMode(dto);
|
|
|
|
|
|
response = new RestApiResponse<>(ImmutableMap.of("list", list));
|
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("获取支付方式 warn param:{}", dto.toString(), e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("获取支付方式 error param:{}", dto.toString(), e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PAY_MODE);
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 微信支付回调接口
|
|
|
|
|
|
* http://localhost:8080/uniapp/pay/callback
|
|
|
|
|
|
* https://api.jsowellcloud.com/uniapp/pay/wechatPayCallback
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/wechatPayCallback")
|
|
|
|
|
|
public RestApiResponse<?> wechatPayCallback(HttpServletRequest request, @RequestBody WechatPayNotifyParameter body) {
|
|
|
|
|
|
logger.info("1----------->微信支付回调开始 body:{}", JSONObject.toJSONString(body));
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
orderService.wechatPayCallback(request, body);
|
|
|
|
|
|
response = new RestApiResponse<>();
|
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("微信支付回调接口warn", e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("微信支付回调接口error", e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_CALLBACK_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 微信退款回调接口
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param body
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/wechatPayRefundCallback")
|
|
|
|
|
|
public RestApiResponse<?> wechatPayRefundCallback(HttpServletRequest request, @RequestBody WechatPayNotifyParameter body) {
|
|
|
|
|
|
logger.info("微信退款回调接口 body:{}", JSONObject.toJSONString(body));
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
orderService.wechatPayRefundCallback(request, body);
|
|
|
|
|
|
response = new RestApiResponse<>();
|
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("微信退款回调接口warn", e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("微信退款回调接口error", e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_CALLBACK_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-11 17:44:01 +08:00
|
|
|
|
* 微信退款接口/微信余额退款
|
2023-03-04 16:29:55 +08:00
|
|
|
|
* https://api.jsowellcloud.com/uniapp/pay/refund
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refund")
|
2023-07-27 16:44:18 +08:00
|
|
|
|
public RestApiResponse<?> weChatRefund(HttpServletRequest request, @RequestBody ApplyRefundDTO dto) {
|
2023-03-04 16:29:55 +08:00
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (dto.getRefundAmount() == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setMemberId(memberId);
|
|
|
|
|
|
dto.setRefundType("2");
|
|
|
|
|
|
orderService.weChatRefund(dto);
|
|
|
|
|
|
response = new RestApiResponse<>();
|
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("微信退款接口 warn", e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("微信退款接口 error", e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
2023-05-17 09:40:00 +08:00
|
|
|
|
|
2023-05-27 11:44:44 +08:00
|
|
|
|
/**
|
2023-08-11 17:44:01 +08:00
|
|
|
|
* 汇付充值余额/会员充值余额/汇付余额充值
|
|
|
|
|
|
* http://localhost:8080/uniapp/pay/rechargeBalance
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/rechargeBalance")
|
|
|
|
|
|
public RestApiResponse<?> rechargeBalance(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
|
|
|
|
|
logger.info("adapay会员充值余额 param:{}", dto.toString());
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
|
|
|
|
|
|
return new RestApiResponse<>(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 鉴权
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setMemberId(memberId);
|
2023-08-15 15:53:37 +08:00
|
|
|
|
// 设置appId
|
|
|
|
|
|
dto.setAppId(request.getHeader("appId"));
|
|
|
|
|
|
// 获取openId
|
2023-08-16 14:44:03 +08:00
|
|
|
|
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMemberId(memberId);
|
|
|
|
|
|
if (memberBasicInfo == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_HANDLE_USER_INFO_ERROR);
|
2023-08-11 17:44:01 +08:00
|
|
|
|
}
|
2023-08-16 14:44:03 +08:00
|
|
|
|
// if (StringUtils.isBlank(openId)) {
|
|
|
|
|
|
// throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
|
|
|
|
|
// }
|
|
|
|
|
|
dto.setOpenId(memberBasicInfo.getOpenId());
|
2023-08-11 17:44:01 +08:00
|
|
|
|
// 充值余额 附加参数
|
|
|
|
|
|
Map<String, Object> weixinMap = memberService.rechargeBalanceWithAdapay(dto);
|
|
|
|
|
|
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
|
2023-08-15 15:42:39 +08:00
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.error("汇付余额充值接口 error", e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
2023-08-11 17:44:01 +08:00
|
|
|
|
} catch (Exception e) {
|
2023-08-15 15:42:39 +08:00
|
|
|
|
logger.error("汇付余额充值接口 error", e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_RECHARGE_BALANCE_ERROR);
|
2023-08-11 17:44:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-17 10:07:28 +08:00
|
|
|
|
* 汇付支付退款/汇付支付余额退款/用户余额退款/汇付余额退款
|
2023-07-28 10:03:53 +08:00
|
|
|
|
* https://api.jsowellcloud.com/uniapp/pay/refundBalance
|
2023-05-27 11:44:44 +08:00
|
|
|
|
*/
|
2023-07-28 10:03:53 +08:00
|
|
|
|
@PostMapping("/refundBalance")
|
|
|
|
|
|
public RestApiResponse<?> refundBalance(HttpServletRequest request, @RequestBody ApplyRefundDTO dto) {
|
2023-05-27 14:59:23 +08:00
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (dto.getRefundAmount() == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setMemberId(memberId);
|
|
|
|
|
|
dto.setRefundType("2");
|
|
|
|
|
|
orderService.adapayRefund(dto);
|
|
|
|
|
|
response = new RestApiResponse<>();
|
|
|
|
|
|
} catch (BusinessException e) {
|
2023-05-27 16:30:35 +08:00
|
|
|
|
logger.warn("汇付支付退款接口 warn", e);
|
2023-05-27 14:59:23 +08:00
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
2023-05-27 16:30:35 +08:00
|
|
|
|
logger.error("汇付支付退款接口 error", e);
|
2023-05-27 14:59:23 +08:00
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
2023-05-27 11:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-17 09:40:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 汇付支付回调
|
2023-05-20 11:35:01 +08:00
|
|
|
|
* <a href="https://api.jsowellcloud.com/uniapp/pay/adapayCallback">...</a>
|
2023-05-17 09:40:00 +08:00
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/adapayCallback")
|
2023-05-20 10:53:49 +08:00
|
|
|
|
public void adapayCallback(HttpServletRequest request) {
|
2023-05-17 09:40:00 +08:00
|
|
|
|
try {
|
2023-07-06 16:12:34 +08:00
|
|
|
|
orderService.adapayCallback(request);
|
2023-07-10 16:53:16 +08:00
|
|
|
|
String type = request.getParameter("type");
|
2023-07-11 08:32:02 +08:00
|
|
|
|
logger.info("1汇付回调type:{}", type);
|
2023-05-17 09:40:00 +08:00
|
|
|
|
} catch (Exception e) {
|
2023-07-14 14:57:25 +08:00
|
|
|
|
logger.error("1汇付支付回调失败 error", e);
|
2023-05-17 09:40:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-27 14:59:23 +08:00
|
|
|
|
|
2023-08-15 09:34:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 支付占桩订单
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/payOccupyPileOrder")
|
|
|
|
|
|
public RestApiResponse<?> payOccupyPileOrder(HttpServletRequest request, @RequestBody PayOrderDTO dto) {
|
|
|
|
|
|
logger.info("wechatpay支付订单 param:{}", dto.toString());
|
|
|
|
|
|
RestApiResponse<?> response;
|
|
|
|
|
|
|
|
|
|
|
|
// 支付订单加锁
|
|
|
|
|
|
String lockKey = "pay_order_" + dto.getOrderCode();
|
|
|
|
|
|
String lockValue = IdUtils.fastUUID();
|
|
|
|
|
|
try {
|
|
|
|
|
|
String memberId = getMemberIdByAuthorization(request);
|
|
|
|
|
|
if (StringUtils.isBlank(memberId)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dto.getPayAmount() == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
dto.setMemberId(memberId);
|
|
|
|
|
|
dto.setLockValue(lockValue);
|
|
|
|
|
|
// redis锁
|
|
|
|
|
|
Boolean isLock = redisCache.lock(lockKey, lockValue, 60);
|
|
|
|
|
|
Map<String, Object> map = null;
|
|
|
|
|
|
if (isLock) {
|
|
|
|
|
|
map = orderService.payOrder(dto);
|
|
|
|
|
|
}
|
|
|
|
|
|
response = new RestApiResponse<>(map);
|
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
|
logger.warn("wechatpay支付订单 warn param:{}", dto.toString(), e);
|
|
|
|
|
|
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("wechatpay支付订单 error param:{}", dto.toString(), e);
|
|
|
|
|
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ORDER_PAY_ERROR);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
// 支付订单解锁
|
|
|
|
|
|
if (lockValue.equals(redisCache.getCacheObject(lockKey).toString())) {
|
|
|
|
|
|
redisCache.unLock(lockKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
logger.info("wechatpay支付订单 result:{}", JSONObject.toJSONString(response));
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|