|
|
@@ -0,0 +1,154 @@
|
|
|
+package com.xingxi.unifiedpay.service;
|
|
|
+
|
|
|
+import com.xingxi.common.aliyun.oss.AliyunOSSClient;
|
|
|
+
|
|
|
+import com.xingxi.unifiedpay.repository.XingxiUnifiedpayRepository;
|
|
|
+import com.aliyun.oss.model.OSSObject;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.StreamUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+class XingxiUnifiedpayRepositoryImpl implements XingxiUnifiedpayRepository {
|
|
|
+
|
|
|
+ private final AliyunOSSClient aliyunOSSClient;
|
|
|
+// private final IMerchantService merchantService;
|
|
|
+// private final IMercWxappService mercWxappService;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public MercUnifiedpayDTO selectMercUnifiedpayDTOByMercId(Long mercId) {
|
|
|
+// Merchant merchant = merchantService.selectMerchantByMercId(mercId);
|
|
|
+// if (ObjectUtils.isEmpty(merchant)) {
|
|
|
+// log.debug("商户[" + mercId + "]不存在");
|
|
|
+// throw new BusinessException("商户不存在");
|
|
|
+// }
|
|
|
+// if (!"IN_COOPERATION".equals(merchant.getStatus())) {
|
|
|
+// log.debug("商户[" + mercId + "]已停止合作");
|
|
|
+// throw new BusinessException("已停止合作");
|
|
|
+// }
|
|
|
+// MercWxapp mercWxapp = new MercWxapp();
|
|
|
+// mercWxapp.setMercId(mercId);
|
|
|
+// if (EPaymentChannel.WX_PAY.getVal().equals(merchant.getPaymentChannel())) {
|
|
|
+// mercWxapp.setAppOrgType(EAppOrgType.WXPAY.getVal());
|
|
|
+// } else {
|
|
|
+// mercWxapp.setCurFlag(EYesNo.YES.getVal());
|
|
|
+// }
|
|
|
+// mercWxapp.setDelFlag(EYesNo.NO.getVal());
|
|
|
+//
|
|
|
+// mercWxapp = mercWxappService.selectMercWxappByCond(mercWxapp);
|
|
|
+// if (ObjectUtils.isEmpty(mercWxapp)) {
|
|
|
+// log.debug("商户[" + mercId + "]支付配置信息不存在");
|
|
|
+// throw new BusinessException("商户支付配置信息不存在");
|
|
|
+// }
|
|
|
+// if (!EAppOrgType.XIAOWEI.getVal().equals(mercWxapp.getAppOrgType()) &&
|
|
|
+// !EAppOrgType.ENTERPRISE.getVal().equals(mercWxapp.getAppOrgType()) &&
|
|
|
+// !EAppOrgType.WXPAY.getVal().equals(mercWxapp.getAppOrgType())) {
|
|
|
+// log.debug("商户[" + mercId + "]支付配置信息不正确");
|
|
|
+// throw new BusinessException("支付配置信息不正确");
|
|
|
+// }
|
|
|
+// MercUnifiedpayDTO mercUnifiedpayDTO = new MercUnifiedpayDTO();
|
|
|
+// mercUnifiedpayDTO.setMercId(mercId);
|
|
|
+// mercUnifiedpayDTO.setPaymentChannel(merchant.getPaymentChannel());
|
|
|
+// mercUnifiedpayDTO.setPaymentMethod(merchant.getPaymentMethod());
|
|
|
+// if(EAppOrgType.WXPAY.getVal().equals(mercWxapp.getAppOrgType())){
|
|
|
+// mercUnifiedpayDTO.setSubMchid(mercWxapp.getWxMchId());
|
|
|
+// } else {
|
|
|
+// mercUnifiedpayDTO.setSubMchid(mercWxapp.getSubMchid());
|
|
|
+// }
|
|
|
+// return mercUnifiedpayDTO;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public MercUnifiedpayConfigDTO selectMercUnifiedpayConfigDTOByCallUnifiedpayMercId(Long mercId) {
|
|
|
+//
|
|
|
+// Merchant merchant = merchantService.selectMerchantByMercId(mercId);
|
|
|
+// if (ObjectUtils.isEmpty(merchant)) {
|
|
|
+// log.debug("商户[" + mercId + "]不存在");
|
|
|
+// throw new BusinessException("商户不存在");
|
|
|
+// }
|
|
|
+// if (!"IN_COOPERATION".equals(merchant.getStatus())) {
|
|
|
+// log.debug("商户[" + mercId + "]已停止合作");
|
|
|
+// throw new BusinessException("已停止合作");
|
|
|
+// }
|
|
|
+// MercWxapp mercWxapp = new MercWxapp();
|
|
|
+// mercWxapp.setMercId(mercId);
|
|
|
+//
|
|
|
+// if (EPaymentChannel.WX_PAY.getVal().equals(merchant.getPaymentChannel())) {
|
|
|
+// mercWxapp.setAppOrgType(EAppOrgType.WXPAY.getVal());
|
|
|
+// } else {
|
|
|
+// mercWxapp.setCurFlag(EYesNo.YES.getVal());
|
|
|
+// }
|
|
|
+// mercWxapp.setDelFlag(EYesNo.NO.getVal());
|
|
|
+//
|
|
|
+// mercWxapp = mercWxappService.selectMercWxappByCond(mercWxapp);
|
|
|
+// if (ObjectUtils.isEmpty(mercWxapp)) {
|
|
|
+// log.debug("商户[" + mercId + "]支付配置信息不存在");
|
|
|
+// throw new BusinessException("商户支付配置信息不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!EAppOrgType.XIAOWEI.getVal().equals(mercWxapp.getAppOrgType()) &&
|
|
|
+// !EAppOrgType.ENTERPRISE.getVal().equals(mercWxapp.getAppOrgType()) &&
|
|
|
+// !EAppOrgType.WXPAY.getVal().equals(mercWxapp.getAppOrgType())) {
|
|
|
+// log.debug("商户[" + mercId + "]支付配置信息不正确");
|
|
|
+// throw new BusinessException("支付配置信息不正确");
|
|
|
+// }
|
|
|
+//
|
|
|
+// MercUnifiedpayConfigDTO mercUnifiedpayConfigDTO = new MercUnifiedpayConfigDTO();
|
|
|
+// mercUnifiedpayConfigDTO.setApiV3Key(mercWxapp.getWxApiV3key());
|
|
|
+// mercUnifiedpayConfigDTO.setMchId(mercWxapp.getWxMchId());
|
|
|
+// mercUnifiedpayConfigDTO.setAppId(mercWxapp.getWxPayId());
|
|
|
+// mercUnifiedpayConfigDTO.setPrivateKeyContent(getCertBytesFromOSSByURL(mercWxapp.getWxKeyFile()));
|
|
|
+// mercUnifiedpayConfigDTO.setPrivateCertContent(getCertBytesFromOSSByURL(mercWxapp.getWxCertFile()));
|
|
|
+//
|
|
|
+// return mercUnifiedpayConfigDTO;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] getCertBytesFromOSSByURL(String URL) {
|
|
|
+
|
|
|
+ for (String s : DOMAIN_LIST) {
|
|
|
+ URL = URL.replaceAll(s, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ OSSObject ossObject = null;
|
|
|
+ byte[] bytes;
|
|
|
+ try {
|
|
|
+ ossObject = aliyunOSSClient.getObject(URL);
|
|
|
+ InputStream content = ossObject.getObjectContent();
|
|
|
+ bytes = StreamUtils.copyToByteArray(content);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.debug("商户证书[" + URL + "]取得失败", e);
|
|
|
+ throw new RuntimeException();
|
|
|
+ } finally {
|
|
|
+ if (ossObject != null) {
|
|
|
+ try {
|
|
|
+ ossObject.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private final static List<String> DOMAIN_LIST = new ArrayList<String>() {{
|
|
|
+ add("https://biandan-default.oss-cn-beijing.aliyuncs.com/");
|
|
|
+ add("https://res.njnet.vip/");
|
|
|
+ add("http://biandan-default.oss-cn-beijing.aliyuncs.com/");
|
|
|
+ add("http://res.njnet.vip/");
|
|
|
+ add("https://res.ysyd.cloud/");
|
|
|
+ }};
|
|
|
+
|
|
|
+
|
|
|
+}
|