|
|
|
@ -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()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 测试文件上传 |
|
|
|
*/ |
|
|
|
private String uplodWecWindow(String mchId, MultipartFile certfile){ |
|
|
|
if (certfile.isEmpty()) { |
|
|
|
// TODO 抛出业务异常
|
|
|
|
return "文件上传失败!"; |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
* 证书文件内容读取 |
|
|
|
* @param certPath |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String readCert(String certPath) { |
|
|
|
byte[] bytes; |
|
|
|
private String readCertificate(String certPath) { |
|
|
|
InputStream is = OssBootUtil.getOssFile(certPath); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
try{ |
|
|
|
bytes = Files.readAllBytes(Paths.get(certPath)); |
|
|
|
}catch (IOException e) { |
|
|
|
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){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |