|
@@ -38,6 +38,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.GCMParameterSpec;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
@@ -187,24 +188,30 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseEntity<String> prepayNotice(PrepayNoticeVo prepayNoticeVo, String dskey, BigDecimal amount, String userNum) {
|
|
|
+ public ResponseEntity<String> prepayNotice(PrepayNoticeVo prepayNoticeVo, String dskey, BigDecimal amount,
|
|
|
+ String userNum, HttpServletRequest httpServletRequest) {
|
|
|
log.info("获取到的支付成功的回调:{},dskey:{},amount:{},userNum:{}", prepayNoticeVo, dskey, amount, userNum);
|
|
|
// 传来的数据为整数 所以需要除以100
|
|
|
amount = amount.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
|
|
- List<String> dsKeys;
|
|
|
- if (StringUtils.isBlank(dskey)) {
|
|
|
- List<TenantDo> tenantList = (List<TenantDo>) redisService.getRedisCatchObj("allTenants");
|
|
|
- // 获取 所有的主库信息
|
|
|
- dsKeys = tenantList.stream().map(TenantDo::getDskey).collect(Collectors.toList());
|
|
|
- } else {
|
|
|
- dsKeys = Collections.singletonList(dskey);
|
|
|
- }
|
|
|
+ // List<String> dsKeys;
|
|
|
+ // if (StringUtils.isBlank(dskey)) {
|
|
|
+ // List<TenantDo> tenantList = (List<TenantDo>) redisService.getRedisCatchObj("allTenants");
|
|
|
+ // // 获取 所有的主库信息
|
|
|
+ // dsKeys = tenantList.stream().map(TenantDo::getDskey).collect(Collectors.toList());
|
|
|
+ // } else {
|
|
|
+ // dsKeys = Collections.singletonList(dskey);
|
|
|
+ // }
|
|
|
R error = R.error("失败");
|
|
|
- dsKeys.remove("incontrol");
|
|
|
+ // dsKeys.remove("incontrol");
|
|
|
+ httpServletRequest.setAttribute("schema",dskey);
|
|
|
// 获取所有商户的密钥
|
|
|
- List<SwEnterpriseConfigInfoDo> secretKeyList = commonBusinessDao.getSecretKey(dsKeys);
|
|
|
+ List<SwEnterpriseConfigInfoDo> secretKeyList = commonBusinessDao.getSecretKey(Collections.singletonList(dskey));
|
|
|
String analysisStr = null;
|
|
|
- String deKey = null;
|
|
|
+ // String deKey = null;
|
|
|
+ if(secretKeyList.isEmpty()) {
|
|
|
+ log.error("无法根据:{}找到到对应的商户信息",dskey);
|
|
|
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error.toString());
|
|
|
+ }
|
|
|
for (SwEnterpriseConfigInfoDo swEnterpriseConfigInfoDo : secretKeyList) {
|
|
|
try {
|
|
|
byte[] apiV3Key = swEnterpriseConfigInfoDo.getMerchantsecretkey().getBytes("UTF8");
|
|
@@ -217,7 +224,7 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
cipher.init(Cipher.DECRYPT_MODE, key, spec);
|
|
|
cipher.updateAAD(associatedData);
|
|
|
analysisStr = new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), "utf-8");
|
|
|
- deKey = swEnterpriseConfigInfoDo.getTenantid();
|
|
|
+ // deKey = swEnterpriseConfigInfoDo.getTenantid();
|
|
|
log.debug("解析成功");
|
|
|
if (StringUtils.isNotBlank(analysisStr)) {
|
|
|
break;
|
|
@@ -240,22 +247,25 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
log.error("JSON转换异常");
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error.toString());
|
|
|
}
|
|
|
+ // 商户号
|
|
|
+ String outTradeNo = transaction.getOutTradeNo();
|
|
|
+ SwPaymentInitRecordDo paymentInitRecordDo = swPaymentInitRecordService.getOne(new LambdaQueryWrapper<SwPaymentInitRecordDo>()
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
+ .eq(SwPaymentInitRecordDo::getOrderno, outTradeNo), false);
|
|
|
try {
|
|
|
// 微信订单号
|
|
|
String transactionId = transaction.getTransactionId();
|
|
|
- // 商户号
|
|
|
- String outTradeNo = transaction.getOutTradeNo();
|
|
|
+
|
|
|
Date successTime = transaction.getSuccessTime();
|
|
|
log.debug("支付回调:{}", transaction);
|
|
|
/******************创建缴费记录***************************/
|
|
|
|
|
|
- ContextHolder.setValue("dskey", dskey);
|
|
|
+ // ContextHolder.setValue("dskey", dskey);
|
|
|
CreatePaymentRecordVo createPaymentRecordVo = new CreatePaymentRecordVo();
|
|
|
createPaymentRecordVo.setOrderNo(outTradeNo);
|
|
|
createPaymentRecordVo.setPaymentAmount(amount);
|
|
|
- SwPaymentInitRecordDo paymentInitRecordDo = swPaymentInitRecordService.getOne(new LambdaQueryWrapper<SwPaymentInitRecordDo>()
|
|
|
- .eq(BaseDo::getDeleted, "0")
|
|
|
- .eq(SwPaymentInitRecordDo::getOrderno, outTradeNo), false);
|
|
|
+
|
|
|
+ log.info("根据商户订单号:{}获取到的下单信息为:{}",outTradeNo,paymentInitRecordDo);
|
|
|
String zdIds = null;
|
|
|
if (paymentInitRecordDo != null) {
|
|
|
zdIds = StringUtils.isBlank(paymentInitRecordDo.getBillid()) ? null : paymentInitRecordDo.getBillid();
|
|
@@ -276,6 +286,14 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
log.error("开始创建缴费记录:{}", createPaymentRecordVo);
|
|
|
paymentRecordService.createRecord(createPaymentRecordVo);
|
|
|
} catch (Exception e) {
|
|
|
+ if (paymentInitRecordDo != null) {
|
|
|
+ swPaymentInitRecordService.update(new LambdaUpdateWrapper<SwPaymentInitRecordDo>()
|
|
|
+ .eq(SwPaymentInitRecordDo::getId, paymentInitRecordDo.getId())
|
|
|
+ .set(SwPaymentInitRecordDo::getState, FAIL)
|
|
|
+ .set(SwPaymentInitRecordDo::getCallbackcontent, transaction.toString())
|
|
|
+ .set(BaseDo::getModifydate, new Date())
|
|
|
+ );
|
|
|
+ }
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error.toString());
|
|
|
} finally {
|
|
|
ContextHolder.clear();
|