Skip to content

微信电子发票报销方接口 #2052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.chanjar.weixin.mp.api;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.bean.invoice.reimburse.*;

import java.util.List;

/**
* 电子发票报销方相关接口
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
public interface WxMpReimburseInvoiceService {

/**
* 查询报销发票信息
* @param request {@link InvoiceInfoRequest} 查询报销发票信息参数
* @return {@link InvoiceInfoResponse} 查询结果
* @throws WxErrorException 查询失败时
*/
InvoiceInfoResponse getInvoiceInfo(InvoiceInfoRequest request) throws WxErrorException;


/**
* 批量查询报销发票信息
* @param request {@link InvoiceBatchRequest} 批量查询报销发票信息参数对象
* @return {@link InvoiceInfoResponse} 查询结果列表
* @throws WxErrorException 查询失败时
*/
List<InvoiceInfoResponse> getInvoiceBatch(InvoiceBatchRequest request) throws WxErrorException;


/**
* 更新发票状态
* @param request {@link UpdateInvoiceStatusRequest} 更新发票状态参数
* @throws WxErrorException 更新失败时
*/
void updateInvoiceStatus(UpdateInvoiceStatusRequest request) throws WxErrorException;


/**
* 批量更新发票状态
* @param request {@link UpdateStatusBatchRequest} 批量更新发票状态参数
* @throws WxErrorException 更新失败时
*/
void updateStatusBatch(UpdateStatusBatchRequest request) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ public interface WxMpService extends WxService {
*/
WxImgProcService getImgProcService();

/**
* 返回电子发票报销方相关接口
* @return WxMpReimburseInvoiceService
*/
WxMpReimburseInvoiceService getReimburseInvoiceService();

/**
* .
* @param reimburseInvoiceService .
*/
void setReimburseInvoiceService(WxMpReimburseInvoiceService reimburseInvoiceService);

/**
* .
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
@Setter
private WxOAuth2Service oAuth2Service = new WxMpOAuth2ServiceImpl(this);

@Getter
@Setter
private WxMpReimburseInvoiceService reimburseInvoiceService = new WxMpReimburseInvoiceServiceImpl(this);

private Map<String, WxMpConfigStorage> configStorageMap;

private int retrySleepMillis = 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.chanjar.weixin.mp.api.impl;

import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpReimburseInvoiceService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.invoice.reimburse.*;

import java.util.List;

import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Invoice.*;

/**
* 电子发票报销方相关接口实现
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
@AllArgsConstructor
public class WxMpReimburseInvoiceServiceImpl implements WxMpReimburseInvoiceService {

private final WxMpService wxMpService;

@Override
public InvoiceInfoResponse getInvoiceInfo(InvoiceInfoRequest request) throws WxErrorException {
return InvoiceInfoResponse.fromJson(this.wxMpService.post(GET_INVOICE_INFO,request.toJson()));
}

@Override
public List<InvoiceInfoResponse> getInvoiceBatch(InvoiceBatchRequest request) throws WxErrorException {
return InvoiceInfoResponse.toList(this.wxMpService.post(GET_INVOICE_BATCH,request.toJson()));
}

@Override
public void updateInvoiceStatus(UpdateInvoiceStatusRequest request) throws WxErrorException {
this.wxMpService.post(UPDATE_INVOICE_STATUS,request.toJson());
}

@Override
public void updateStatusBatch(UpdateStatusBatchRequest request) throws WxErrorException {
this.wxMpService.post(UPDATE_STATUS_BATCH,request.toJson());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.chanjar.weixin.mp.bean.invoice.reimburse;

import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* <pre>
* 批量查询报销发票信息参数对象
* </pre>
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
@Data
@Builder
public class InvoiceBatchRequest implements Serializable {

private static final long serialVersionUID = -9121443117105107231L;

/**
* 发票卡券的card_id
* <pre>
* 是否必填: 是
* </pre>
*/
@SerializedName("item_list")
private List<InvoiceInfoRequest> itemList;

public String toJson() {
return WxMpGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.chanjar.weixin.mp.bean.invoice.reimburse;

import lombok.Data;

/**
* <pre>
* 发票商品信息
* </pre>
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
@Data
public class InvoiceCommodityInfo {

/**
* 项目(商品)名称
*/
private String name;

/**
* 项目数量
*/
private Integer num;

/**
* 项目单位
*/
private String unit;

/**
* 单价,以分为单位
*/
private Integer price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.chanjar.weixin.mp.bean.invoice.reimburse;


import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

import java.io.Serializable;

/**
* <pre>
* 查询报销发票信息参数对象
* </pre>
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
@Data
@Builder
public class InvoiceInfoRequest implements Serializable {

private static final long serialVersionUID = 7854633127026139444L;


/**
* 发票卡券的card_id
* <pre>
* 是否必填: 是
* </pre>
*/
@SerializedName("card_id")
private String cardId;


/**
* 发票卡券的加密code,和card_id共同构成一张发票卡券的唯一标识
* <pre>
* 是否必填: 是
* </pre>
*/
@SerializedName("encrypt_code")
private String encryptCode;


public String toJson() {
return WxMpGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package me.chanjar.weixin.mp.bean.invoice.reimburse;

import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

import java.util.List;

/**
* <pre>
* 查询报销发票信息响应对象
* </pre>
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-03-23
*/
@Data
public class InvoiceInfoResponse {

/**
* 发票ID
*/
@SerializedName("card_id")
private String cardId;


/**
* 发票的有效期起始时间
*/
@SerializedName("begin_time")
private Integer beginTime;

/**
* 发票的有效期截止时间
*/
@SerializedName("end_time")
private Integer endTime;

/**
* 用户标识
*/
private String openid;

/**
* 发票的类型
*/
private String type;

/**
* 发票的收款方
*/
private String payee;

/**
* 发票详情
*/
private String detail;

/**
* 用户可在发票票面看到的主要信息
*/
@SerializedName("user_info")
private InvoiceUserInfo userInfo;


public static InvoiceInfoResponse fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(json, InvoiceInfoResponse.class);
}


public static List<InvoiceInfoResponse> toList(String json) {
JsonObject jsonObject = GsonParser.parse(json);
return WxMpGsonBuilder.create().fromJson(jsonObject.get("item_list").toString(),
new TypeToken<List<InvoiceInfoResponse>>() {
}.getType());
}
}
Loading