|
|
@@ -103,13 +103,17 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
private final ActivityService activityService;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 微信支付专用,支持自动签名验签解密等
|
|
|
*/
|
|
|
private OkHttpClientAdapter wxHttpClient;
|
|
|
|
|
|
|
|
|
- public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService, RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService, EnPlusService enPlusService, ActivityService activityService) {
|
|
|
+ public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService,
|
|
|
+ PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService,
|
|
|
+ RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService,
|
|
|
+ EnPlusService enPlusService, ActivityService activityService) {
|
|
|
this.conf = conf;
|
|
|
this.fapiaoConfig = fapiaoConfig;
|
|
|
this.walletDetailService = walletDetailService;
|
|
|
@@ -753,20 +757,34 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* 开具电子发票
|
|
|
*/
|
|
|
@Override
|
|
|
+ @DS("db-miniapp")
|
|
|
public void fapiaoApplication(String invoiceId) {
|
|
|
var invoice = invoiceService.lambdaQuery().eq(Invoice::getId, invoiceId).one();
|
|
|
|
|
|
// 订单金额+ ,服务费优惠金额- 服务费优惠金额单独一个item,金额为负数
|
|
|
-
|
|
|
+ var itemList = new ArrayList<FaPiao.FaPiaoInfomation.IssueItem>();
|
|
|
// 电费 税务商品编码:1100101020000000000
|
|
|
var elecMoney = invoice.getOrderDetails().stream().mapToInt(InvoiceOrderDetail::getElecMoney).sum();
|
|
|
- var elecMoneyItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotalAmount(elecMoney).setTaxCode("1100101020000000000");
|
|
|
+ // 必须为正数
|
|
|
+ if (elecMoney > 0) {
|
|
|
+ var elecMoneyItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotal_amount(elecMoney).setTax_code("1100101020000000000");
|
|
|
+ itemList.add(elecMoneyItem);
|
|
|
+ }
|
|
|
// 服务费 税务商品编码:3040100000000000000
|
|
|
- var serviceMoney = invoice.getOrderDetails().stream().mapToInt(InvoiceOrderDetail::getElecMoney).sum();
|
|
|
- var serviceMoneyItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotalAmount(serviceMoney).setTaxCode("3040100000000000000");
|
|
|
+ var serviceMoney = invoice.getOrderDetails().stream().mapToInt(InvoiceOrderDetail::getServiceMoney).sum();
|
|
|
+ // 必须为正数
|
|
|
+ if (serviceMoney > 0) {
|
|
|
+ var serviceMoneyItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotal_amount(serviceMoney).setTax_code("3040100000000000000");
|
|
|
+ itemList.add(serviceMoneyItem);
|
|
|
+ }
|
|
|
+
|
|
|
// 服务费优惠 税务商品编码:3040100000000000000
|
|
|
var serviceMoneyDiscount = -invoice.getOrderDetails().stream().mapToInt(InvoiceOrderDetail::getServiceMoneyDiscount).sum();
|
|
|
- var serviceMoneyDiscountItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotalAmount(serviceMoneyDiscount).setTaxCode("3040100000000000000");
|
|
|
+ // 必须为正数
|
|
|
+ if (serviceMoneyDiscount > 0) {
|
|
|
+ var serviceMoneyDiscountItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotal_amount(serviceMoneyDiscount).setTax_code("3040100000000000000");
|
|
|
+ itemList.add(serviceMoneyDiscountItem);
|
|
|
+ }
|
|
|
|
|
|
var headers = new HttpHeaders();
|
|
|
headers.addHeader("Accept", "application/json");
|
|
|
@@ -788,7 +806,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// fapiao_id为invoice.id
|
|
|
fapiaoInformation.setFapiao_id(String.valueOf(invoice.getId()))
|
|
|
.setTotal_amount(invoice.getInvoiceAmount())
|
|
|
- .setItems(List.of(elecMoneyItem, serviceMoneyItem, serviceMoneyDiscountItem));
|
|
|
+ .setItems(itemList);
|
|
|
|
|
|
// 请求参数
|
|
|
var fapiao = new FaPiao()
|
|
|
@@ -803,7 +821,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
/**
|
|
|
* 微信开票结果通知
|
|
|
- * event_tyoe为FAPIAO.ISSUED
|
|
|
+ * event_type为FAPIAO.ISSUED
|
|
|
*
|
|
|
* @param notifyRes
|
|
|
* @return
|
|
|
@@ -844,21 +862,31 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// 发票开具结果
|
|
|
case "FAPIAO.ISSUED":
|
|
|
wxInvoiceNotify(notifyRes);
|
|
|
- default:
|
|
|
- throw new IllegalStateException("Unexpected value: " + notification.getEventType());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- // TODO: 2023-10-07 下载发票
|
|
|
- void downloadInvoice(String invoiceId) {
|
|
|
+ /**
|
|
|
+ * 下载发票,下载链接30s有效
|
|
|
+ *
|
|
|
+ * @param invoiceId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, String> downloadInvoice(String invoiceId) {
|
|
|
var invoice = invoiceService.getById(invoiceId);
|
|
|
- // TODO: 2023-10-07 查询发票下载信息,下载链接30s有效
|
|
|
var download = getFapiaoDownloadInfo(invoice.getApplyId());
|
|
|
var downloadInfo = download.getFapiao_download_info_list().get(0);
|
|
|
- var params = "?token=%s&mchid=%s&openid=%s&invoice_code=%s&invoice_no=%s&fapiao_id=%s";
|
|
|
- var inputStream = wxHttpClient.download(downloadInfo.getDownload_url().concat(params.formatted("", conf.getMchid(), "", "", "", invoice.getId())));
|
|
|
-
|
|
|
+ // 查询电子发票
|
|
|
+ var fapiaoApplications = queryFapiao(invoice.getApplyId());
|
|
|
+
|
|
|
+ var params = "&mchid=%s&openid=%s&invoice_code=%s&invoice_no=%s&fapiao_id=%s";
|
|
|
+ // openid 通过查询电子发票接口获取的card_openid
|
|
|
+ var fapiao = fapiaoApplications.getFapiao_information().get(0);
|
|
|
+ var downloadUrl = downloadInfo.getDownload_url().concat(params.formatted(conf.getMchid(),
|
|
|
+ fapiao.getCard_information().getCard_openid(), fapiao.getBlue_fapiao().getFapiao_code(),
|
|
|
+ fapiao.getBlue_fapiao().getFapiao_number(), invoice.getId()));
|
|
|
+ return Map.of("downloadUrl", downloadUrl);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -867,7 +895,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* @param applyId
|
|
|
* @return
|
|
|
*/
|
|
|
- private FapiaoDownload getFapiaoDownloadInfo(String applyId) {
|
|
|
+ @Override
|
|
|
+ public FapiaoDownload getFapiaoDownloadInfo(String applyId) {
|
|
|
var downloadUrl = fapiaoConfig.getFapiaoFiles().formatted(applyId);
|
|
|
var headers = new HttpHeaders();
|
|
|
headers.addHeader("Accept", "application/json");
|
|
|
@@ -880,7 +909,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
*
|
|
|
* @param applyId
|
|
|
*/
|
|
|
- private FapiaoApplications queryFapiao(String applyId) {
|
|
|
+ @Override
|
|
|
+ public FapiaoApplications queryFapiao(String applyId) {
|
|
|
var headers = new HttpHeaders();
|
|
|
headers.addHeader("Accept", "application/json");
|
|
|
headers.addHeader("Content-Type", "application/json");
|