|
|
@@ -28,6 +28,7 @@ import com.wechat.pay.java.core.http.DefaultHttpClientBuilder;
|
|
|
import com.wechat.pay.java.core.http.HttpHeaders;
|
|
|
import com.wechat.pay.java.core.http.JsonRequestBody;
|
|
|
import com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter;
|
|
|
+import com.wechat.pay.java.core.notification.Notification;
|
|
|
import com.wechat.pay.java.core.notification.NotificationConfig;
|
|
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
|
|
import com.wechat.pay.java.core.notification.RequestParam;
|
|
|
@@ -530,6 +531,34 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
//================================================================发票=====================================================================
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信电子发票配置开发选项,例如回调地址、全部账单展示开发票入口开关
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Object devConfig() {
|
|
|
+ var headers = new HttpHeaders();
|
|
|
+ headers.addHeader("Accept", "application/json");
|
|
|
+ headers.addHeader("Content-Type", "application/json");
|
|
|
+ var params = JSONObject.of("callback_url", fapiaoConfig.getNotifyUrl(), "show_fapiao_cell", false);
|
|
|
+ var requestBody = new JsonRequestBody.Builder().body(params.toJSONString()).build();
|
|
|
+ var res = wxHttpClient.patch(headers, fapiaoConfig.getDevConfig(), requestBody, JSONObject.class);
|
|
|
+ LOGGER.info("微信电子发票开发设置:{}", res.toString());
|
|
|
+ return res.getServiceResponse();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商户配置的开发选项
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Object getDevConfig() {
|
|
|
+ var headers = new HttpHeaders();
|
|
|
+ headers.addHeader("Accept", "application/json");
|
|
|
+ headers.addHeader("Content-Type", "application/json");
|
|
|
+ var res = wxHttpClient.get(headers, fapiaoConfig.getDevConfig(), JSONObject.class);
|
|
|
+ LOGGER.info("查询微信电子发票开发设置:{}", res.toString());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户抬头信息填写URL
|
|
|
*
|
|
|
@@ -554,6 +583,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
/**
|
|
|
* 处理发票抬头填写完成通知
|
|
|
+ * event_type为FAPIAO.USER_APPLIED
|
|
|
*
|
|
|
* @param request
|
|
|
*/
|
|
|
@@ -684,6 +714,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
/**
|
|
|
* 微信开票结果通知
|
|
|
+ * event_tyoe为FAPIAO.ISSUED
|
|
|
*
|
|
|
* @param request
|
|
|
* @return
|
|
|
@@ -708,27 +739,28 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 微信电子发票配置开发选项,例如回调地址、全部账单展示开发票入口开关
|
|
|
+ * 接收电子发票相关回调通知
|
|
|
+ * @param request
|
|
|
*/
|
|
|
- void devConfig() {
|
|
|
- var headers = new HttpHeaders();
|
|
|
- headers.addHeader("Accept", "application/json");
|
|
|
- headers.addHeader("Content-Type", "application/json");
|
|
|
-
|
|
|
- var params = """
|
|
|
- {
|
|
|
- "callback_url" : %s,
|
|
|
- "show_fapiao_cell" : false
|
|
|
- }
|
|
|
- """.stripIndent().formatted(fapiaoConfig.getNotifyUrl());
|
|
|
- var requestBody = new JsonRequestBody.Builder().body(params).build();
|
|
|
- var res = wxHttpClient.patch(headers, fapiaoConfig.getDevConfig(), requestBody, JSONObject.class);
|
|
|
- LOGGER.info("微信电子发票开发设置:{}", res.toString());
|
|
|
- // TODO: 2023-10-07 业务逻辑
|
|
|
+ @Override
|
|
|
+ public void invoiceNotify(HttpServletRequest request) {
|
|
|
+ var notifyRes = handleWxNotify(request);
|
|
|
+ var requestParam = (RequestParam) notifyRes[0];
|
|
|
+ Notification notification = JSONObject.parseObject(requestParam.getBody(), Notification.class);
|
|
|
+ switch (notification.getEventType()) {
|
|
|
+ // 发票抬头填写完成
|
|
|
+ case "FAPIAO.USER_APPLIED":
|
|
|
+ titleWriteNotice(request);
|
|
|
+ // 发票开具结果
|
|
|
+ case "FAPIAO.ISSUED":
|
|
|
+ wxInvoiceNotify(request);
|
|
|
+ default:
|
|
|
+ throw new IllegalStateException("Unexpected value: " + notification.getEventType());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// TODO: 2023-10-07 下载发票
|
|
|
void downloadInvoice(String invoiceId) {
|
|
|
var invoice = invoiceService.getById(invoiceId);
|