diff --git a/payment-base-app/src/main/java/com/base/springcloud/service/imp/MerchantServiceImp.java b/payment-base-app/src/main/java/com/base/springcloud/service/imp/MerchantServiceImp.java index 6e60a70..19a9c78 100644 --- a/payment-base-app/src/main/java/com/base/springcloud/service/imp/MerchantServiceImp.java +++ b/payment-base-app/src/main/java/com/base/springcloud/service/imp/MerchantServiceImp.java @@ -7,11 +7,14 @@ import com.base.springcloud.bo.OrderBO; import com.base.springcloud.constant.ErrorConstant; import com.base.springcloud.dao.MerchantConfigMapper; import com.base.springcloud.entity.MerchantConfig; +import com.base.springcloud.handle.RBSQueueHandler; import com.base.springcloud.service.DepartService; import com.base.springcloud.service.MerchantService; import com.base.springcloud.util.FtpUtil; import com.base.springcloud.util.OssBootUtil; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -31,18 +34,14 @@ import java.util.stream.Collectors; @Service public class MerchantServiceImp implements MerchantService { + Logger logger = LoggerFactory.getLogger(MerchantServiceImp.class); + @Autowired private MerchantConfigMapper merchantConfigMapper; @Autowired private DepartService departService; - @Autowired - private FtpUtil ftpUtil; - - @Value("${test_ftp.file_path}") - public String FTP_BASEPATH; - /** * 支付信息配置 * @param merchantConfigBO @@ -70,6 +69,11 @@ public class MerchantServiceImp implements MerchantService { departService.savePayDepart(departBO); } + /** + * 证书上传 + * @param certFile + * @return + */ private String uploadCertificate(MultipartFile certFile) { return OssBootUtil.upload(certFile, "merchant/paymentConfigure"); } @@ -97,10 +101,10 @@ public class MerchantServiceImp implements MerchantService { @Override public void updateMerchantConfig(MerchantConfigBO merchantConfigBO) { // 证书上传服务器 - String certPath = uplodWecWindow(merchantConfigBO.getMchId(),merchantConfigBO.getCertFile()); + //String certPath = uplodWecWindow(merchantConfigBO.getMchId(),merchantConfigBO.getCertFile()); // 商户支付信息保存 MerchantConfig merchantConfig = new MerchantConfig(); - merchantConfig.setCertPath(certPath); + //merchantConfig.setCertPath(certPath); BeanUtils.copyProperties(merchantConfigBO,merchantConfig); merchantConfig.setUpdateTime(new Date()); int count = merchantConfigMapper.updateMerchantConfig(merchantConfig); @@ -140,45 +144,38 @@ public class MerchantServiceImp implements MerchantService { } orderBO.setAppId(merchantConfig.getAppId()); orderBO.setMchPrivateKey(merchantConfig.getMchPrivateKey()); - //String certificate = readCert(merchantConfig.getCertPath()); - orderBO.setCertificate(merchantConfig.getCertPath()); + String certificate = readCertificate(merchantConfig.getCertPath()); + orderBO.setCertificate(certificate); orderBO.setSerialNo(merchantConfig.getSerialNo()); } /** - * 测试文件上传 + * 证书文件内容读取 + * @param certPath + * @return */ - private String uplodWecWindow(String mchId, MultipartFile certfile){ - if (certfile.isEmpty()) { - // TODO 抛出业务异常 - return "文件上传失败!"; - } + private String readCertificate(String certPath) { + InputStream is = OssBootUtil.getOssFile(certPath); + StringBuilder sb = new StringBuilder(); + try{ + byte[] buf = new byte[1024]; + int length; + //循环读取文件内容,输入流中将最多buf.length个字节的数据读入一个buf数组中,返回类型是读取到的字节数。 + while((length = is.read(buf)) != -1){ + sb.append(new String(buf,0,length)); + } + }catch (IOException e){ + logger.info("read_certificate_exception : {}",e.getMessage()); + throw new BusinessException(ErrorConstant.MERCHANT_PAY_CERT_READ_FAIL); + }finally { + try{ + is.close(); + }catch (IOException e){ - String fileName = certfile.getOriginalFilename(); - String suffixName = fileName.substring(fileName.lastIndexOf(".")); - File file = new File(FTP_BASEPATH + mchId + suffixName); - try { - certfile.transferTo(file); - return file.getPath(); - } catch (IOException e) { - // TODO 抛出业务异常 - } - return "文件上传失败!"; - } + } - /** - * 文件读取 - * @throws IOException - */ - public String readCert(String certPath) { - byte[] bytes; - try{ - bytes = Files.readAllBytes(Paths.get(certPath)); - }catch (IOException e) { - throw new BusinessException(ErrorConstant.MERCHANT_PAY_CERT_READ_FAIL); } - - return new String(bytes, StandardCharsets.UTF_8); + return sb.toString(); } /** @@ -197,29 +194,4 @@ public class MerchantServiceImp implements MerchantService { } return true; } - - /** - * 证书上传服务器 - * @param mchId - * @param certfile - * @return - */ - private String uplodWecPayCert(String mchId,File certfile){ - //获取文件名 - String fileName = certfile.getName(); - //获取文件的后缀名 - String suffixName = fileName.substring(fileName.lastIndexOf(".")); - fileName = mchId + suffixName; - //上传的文件名也需要加上后缀,不然虚拟机不知道文件格式 - try{ - InputStream inputStream = new FileInputStream(certfile); - Boolean flag = ftpUtil.uploadFile(fileName, inputStream); - if (flag == true) { - return ftpUtil.FTP_BASEPATH + fileName; - } - }catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } } \ No newline at end of file diff --git a/payment-base-app/src/main/java/com/base/springcloud/wxsdk/WxpayUtils.java b/payment-base-app/src/main/java/com/base/springcloud/wxsdk/WxpayUtils.java index b550095..60af180 100644 --- a/payment-base-app/src/main/java/com/base/springcloud/wxsdk/WxpayUtils.java +++ b/payment-base-app/src/main/java/com/base/springcloud/wxsdk/WxpayUtils.java @@ -216,8 +216,8 @@ public class WxpayUtils { * @throws UnsupportedEncodingException */ public static CloseableHttpClient getClient(String mchid, String serialNo, PrivateKey privateKey, String certificate) throws CertificateException, IOException { - //byte[] bytes = certificate.getBytes(StandardCharsets.UTF_8); - ByteArrayInputStream base = new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(certificate)); + byte[] bytes = certificate.getBytes(StandardCharsets.UTF_8); + ByteArrayInputStream base = new ByteArrayInputStream(bytes); List certs = new ArrayList<>(); CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = null; diff --git a/payment-base-app/src/main/resources/application-dev.yml b/payment-base-app/src/main/resources/application-dev.yml index 77f6728..724833b 100644 --- a/payment-base-app/src/main/resources/application-dev.yml +++ b/payment-base-app/src/main/resources/application-dev.yml @@ -32,26 +32,26 @@ spring: password: Redis@CS0731 port: 6200 #JimuReport[上传配置] - jeecg: - # local|minio|alioss - uploadType: alioss - # local - path: - #文件路径 - upload: /opt/upload - # alioss - oss: - staticDomain: http://rrimage.oss-cn-beijing.aliyuncs.com - endpoint: oss-cn-beijing.aliyuncs.com - accessKey: LTAIFKTe6ghqO5q2 - secretKey: 8rhlQcMggzfx5jIWpMK8idayrHungs - bucketName: rrimage - # minio - minio: - minio_url: http://minio.jeecg.com - minio_name: ?? - minio_pass: ?? - bucketName: ?? +jeecg: + # local|minio|alioss + uploadType: alioss + # local + path: + #文件路径 + upload: /opt/upload + # alioss + oss: + staticDomain: http://rrimage.oss-cn-beijing.aliyuncs.com + endpoint: oss-cn-beijing.aliyuncs.com + accessKey: LTAIFKTe6ghqO5q2 + secretKey: 8rhlQcMggzfx5jIWpMK8idayrHungs + bucketName: rrimage + # minio + minio: + minio_url: http://minio.jeecg.com + minio_name: ?? + minio_pass: ?? + bucketName: ?? cache: type: simple servlet: diff --git a/payment-base-app/src/main/resources/application.yml b/payment-base-app/src/main/resources/application.yml index 90385b2..caf4dfc 100644 --- a/payment-base-app/src/main/resources/application.yml +++ b/payment-base-app/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: prod \ No newline at end of file + active: dev \ No newline at end of file