|
@@ -5,11 +5,16 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huifu.adapay.core.AdapayCore;
|
|
|
import com.huifu.adapay.core.util.AdapaySign;
|
|
|
+import com.yeepay.g3.sdk.yop.encrypt.DigitalEnvelopeDTO;
|
|
|
+import com.yeepay.g3.sdk.yop.utils.DigitalEnvelopeUtils;
|
|
|
+import com.yeepay.g3.sdk.yop.utils.RSAKeyUtils;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
|
|
|
+import com.ym.mec.web.WebFeignService;
|
|
|
import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
|
|
|
import com.yonge.cooleshow.mbg.model.UserOrderPayment;
|
|
|
import com.yonge.cooleshow.portal.dto.OrderPayRes;
|
|
@@ -23,14 +28,13 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
-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 org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.security.PrivateKey;
|
|
|
+import java.security.PublicKey;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -57,6 +61,9 @@ public class PaymentController extends BaseController {
|
|
|
@Autowired
|
|
|
private UserOrderPaymentService userOrderPaymentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WebFeignService webFeignService;
|
|
|
+
|
|
|
|
|
|
/***
|
|
|
* 支付回调
|
|
@@ -133,7 +140,7 @@ public class PaymentController extends BaseController {
|
|
|
e.printStackTrace();
|
|
|
return failed("请求超时");
|
|
|
}
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
return "验签失败";
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -143,4 +150,51 @@ public class PaymentController extends BaseController {
|
|
|
return "succeeded";
|
|
|
}
|
|
|
|
|
|
+ /***
|
|
|
+ * 易宝支付回调
|
|
|
+ * @author liweifan
|
|
|
+ * @param: request
|
|
|
+ * @updateTime 2022/3/11 18:35
|
|
|
+ */
|
|
|
+ @RequestMapping("/callback_yee/{tenantId}")
|
|
|
+ public Object callback_yee(@PathVariable("tenantId") Integer tenantId, HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ String content = request.getParameter("response");
|
|
|
+ JSONObject dataObj = JSON.parseObject(content);
|
|
|
+ String orderNo = dataObj.getString("orderId");
|
|
|
+ UserOrderPayment userOrderPayment = userOrderPaymentService.getByAdapayNo(orderNo);
|
|
|
+ if (userOrderPayment == null) {
|
|
|
+ throw new BizException("订单不存在");
|
|
|
+ }
|
|
|
+ HfMerchantConfig hfMerchantConfig = webFeignService.queryByTenantId("YEEPAY",tenantId).getData();
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("机构[{}][{}]商户信息找不到", tenantId, "YEEPAY");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造结果通知请求对象
|
|
|
+ DigitalEnvelopeDTO dto = new DigitalEnvelopeDTO();
|
|
|
+ dto.setCipherText(content);
|
|
|
+ PrivateKey privateKey = RSAKeyUtils.string2PrivateKey(hfMerchantConfig.getRsaPrivateKey());
|
|
|
+ PublicKey publicKey = RSAKeyUtils.string2PublicKey(hfMerchantConfig.getRsaPublicKey());
|
|
|
+
|
|
|
+ dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);
|
|
|
+
|
|
|
+ log.info("易宝支付回调信息:response:{} plaintText:{}", content, dto.getPlainText());
|
|
|
+ if("SUCCESS".equals(dataObj.getString("status"))) {
|
|
|
+ orderService.paymentSucceededHandle(orderNo,
|
|
|
+ dataObj.getBigDecimal("orderAmount"),dataObj.getString("channel"));
|
|
|
+ }else {
|
|
|
+ Map<String,Object> notifyMap = new HashMap<>();
|
|
|
+ notifyMap.put("channelType", dataObj.getString("channel"));
|
|
|
+ notifyMap.put("tradeState", "0");
|
|
|
+ notifyMap.put("totalMoney", dataObj.getString("orderAmount"));
|
|
|
+ notifyMap.put("merOrderNo", orderNo);
|
|
|
+ orderService.paymentFailedHandle(orderNo,notifyMap);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return e.getMessage();
|
|
|
+ }
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+
|
|
|
}
|