mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 03:55:17 +08:00
Merge branch 'dev' into HuiFu
# Conflicts: # jsowell-admin/src/main/java/com/jsowell/api/uniapp/PayController.java # jsowell-admin/src/test/java/SpringBootTestController.java
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.jsowell.api.uniapp;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.huifu.adapay.core.AdapayCore;
|
||||
@@ -9,12 +8,14 @@ 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;
|
||||
import com.jsowell.pile.dto.GetPayModeDTO;
|
||||
import com.jsowell.pile.dto.PayOrderDTO;
|
||||
import com.jsowell.pile.dto.PaymentScenarioDTO;
|
||||
import com.jsowell.pile.dto.WeixinPayDTO;
|
||||
import com.jsowell.pile.vo.uniapp.PayModeVO;
|
||||
import com.jsowell.service.MemberService;
|
||||
@@ -72,48 +73,15 @@ public class PayController extends BaseController {
|
||||
}
|
||||
dto.setOpenId(openId);
|
||||
// 充值余额 附加参数
|
||||
Map<String, Object> weixinMap = memberService.rechargeBalance(dto);
|
||||
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));
|
||||
} catch (Exception e) {
|
||||
logger.error("会员充值余额 error", e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_RECHARGE_BALANCE_ERROR);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员充值余额
|
||||
* http://localhost:8080/uniapp/pay/rechargeBalance
|
||||
*
|
||||
* @param request
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/rechargeBalance")
|
||||
public RestApiResponse<?> rechargeBalance(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
||||
logger.info("会员充值余额 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);
|
||||
String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||
if (StringUtils.isBlank(openId)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
}
|
||||
dto.setOpenId(openId);
|
||||
// 充值余额 附加参数
|
||||
Map<String, Object> weixinMap = memberService.rechargeBalanceWithAdapay(dto);
|
||||
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
|
||||
} catch (Exception e) {
|
||||
logger.error("会员充值余额 error", e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_RECHARGE_BALANCE_ERROR);
|
||||
response = new RestApiResponse<>();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -150,6 +118,7 @@ public class PayController extends BaseController {
|
||||
if (isLock) {
|
||||
map = orderService.payOrder(dto);
|
||||
}
|
||||
// Map<String, Object> map = orderService.payOrder(dto);
|
||||
response = new RestApiResponse<>(map);
|
||||
} catch (BusinessException e) {
|
||||
logger.warn("支付订单 warn param:{}", dto.toString(), e);
|
||||
@@ -167,55 +136,6 @@ public class PayController extends BaseController {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* adapay支付订单
|
||||
* http://localhost:8080/uniapp/pay/payOrderWithAdapay
|
||||
*
|
||||
* @param request
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/payOrderWithAdapay")
|
||||
public RestApiResponse<?> payOrderWithAdapay(HttpServletRequest request, @RequestBody PayOrderDTO dto) {
|
||||
logger.info("adapay支付订单 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.payOrderWithAdapay(dto);
|
||||
}
|
||||
response = new RestApiResponse<>(map);
|
||||
} catch (BusinessException e) {
|
||||
logger.warn("adapay支付订单 warn param:{}", dto.toString(), e);
|
||||
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("adapay支付订单 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("adapay支付订单 result:{}", JSONObject.toJSONString(response));
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 7003 获取支付方式
|
||||
* http://localhost:8080/uniapp/pay/getPayMode
|
||||
@@ -261,7 +181,6 @@ public class PayController extends BaseController {
|
||||
|
||||
/**
|
||||
* 微信退款回调接口
|
||||
*
|
||||
* @param request
|
||||
* @param body
|
||||
* @return
|
||||
@@ -314,10 +233,11 @@ public class PayController extends BaseController {
|
||||
|
||||
/**
|
||||
* 汇付支付回调
|
||||
* https://api.jsowellcloud.com/uniapp/pay/refund
|
||||
* https://api.jsowellcloud.com/uniapp/pay/adapayCallback
|
||||
*/
|
||||
@PostMapping("/adapayCallback")
|
||||
public void callback(HttpServletRequest request) {
|
||||
logger.info("汇付支付回调 request:{}", JSONObject.toJSONString(request));
|
||||
try {
|
||||
//验签请参data
|
||||
String data = request.getParameter("data");
|
||||
@@ -327,18 +247,17 @@ public class PayController extends BaseController {
|
||||
boolean checkSign;
|
||||
//验签请参publicKey
|
||||
String publicKey = AdapayCore.PUBLIC_KEY;
|
||||
logger.info("汇付支付回调验签请参:data={}sign={}", data, sign);
|
||||
logger.info("汇付支付回调验签请参data={}, sign={}", data, sign);
|
||||
//验签
|
||||
checkSign = AdapaySign.verifySign(data, sign, publicKey);
|
||||
if (checkSign) {
|
||||
//验签成功逻辑
|
||||
System.out.println("汇付支付回调成功返回数据data:" + data);
|
||||
logger.info("汇付支付回调成功返回数据data:{}", data);
|
||||
} else {
|
||||
//验签失败逻辑
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("汇付支付回调失败 request:{}", JSON.toJSONString(request));
|
||||
logger.error("汇付支付回调失败 error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user