mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-28 04:29:07 +08:00
🎨 🐛 #1898 【公众号】微信商户电子发票代码规范化及优化,并修复设置商户联系方式参数问题
This commit is contained in:
@ -14,16 +14,26 @@ import me.chanjar.weixin.mp.bean.invoice.merchant.*;
|
|||||||
* <p>
|
* <p>
|
||||||
* 流程文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_and_Invoicing_Platform_Mode_Instruction.html
|
* 流程文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_and_Invoicing_Platform_Mode_Instruction.html
|
||||||
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html
|
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html
|
||||||
|
*
|
||||||
|
* @author Mario Luo
|
||||||
*/
|
*/
|
||||||
public interface WxMpMerchantInvoiceService {
|
public interface WxMpMerchantInvoiceService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取开票授权页链接
|
* 获取开票授权页链接
|
||||||
|
*
|
||||||
|
* @param params the params
|
||||||
|
* @return the auth page url
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
InvoiceAuthPageResult getAuthPageUrl(InvoiceAuthPageRequest params) throws WxErrorException;
|
InvoiceAuthPageResult getAuthPageUrl(InvoiceAuthPageRequest params) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得用户授权数据
|
* 获得用户授权数据
|
||||||
|
*
|
||||||
|
* @param params the params
|
||||||
|
* @return the auth data
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
InvoiceAuthDataResult getAuthData(InvoiceAuthDataRequest params) throws WxErrorException;
|
InvoiceAuthDataResult getAuthData(InvoiceAuthDataRequest params) throws WxErrorException;
|
||||||
|
|
||||||
@ -32,16 +42,25 @@ public interface WxMpMerchantInvoiceService {
|
|||||||
* <p>
|
* <p>
|
||||||
* 场景: 用户授权填写数据无效
|
* 场景: 用户授权填写数据无效
|
||||||
* 结果: 用户会收到一条开票失败提示
|
* 结果: 用户会收到一条开票失败提示
|
||||||
|
*
|
||||||
|
* @param params the params
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void rejectInvoice(InvoiceRejectRequest params) throws WxErrorException;
|
void rejectInvoice(InvoiceRejectRequest params) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开具电子发票
|
* 开具电子发票
|
||||||
|
*
|
||||||
|
* @param params the params
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void makeOutInvoice(MakeOutInvoiceRequest params) throws WxErrorException;
|
void makeOutInvoice(MakeOutInvoiceRequest params) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发票冲红
|
* 发票冲红
|
||||||
|
*
|
||||||
|
* @param params the params
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void clearOutInvoice(ClearOutInvoiceRequest params) throws WxErrorException;
|
void clearOutInvoice(ClearOutInvoiceRequest params) throws WxErrorException;
|
||||||
|
|
||||||
@ -50,36 +69,57 @@ public interface WxMpMerchantInvoiceService {
|
|||||||
*
|
*
|
||||||
* @param fpqqlsh 发票请求流水号
|
* @param fpqqlsh 发票请求流水号
|
||||||
* @param nsrsbh 纳税人识别号
|
* @param nsrsbh 纳税人识别号
|
||||||
|
* @return the invoice result
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
InvoiceResult queryInvoiceInfo(String fpqqlsh, String nsrsbh) throws WxErrorException;
|
InvoiceResult queryInvoiceInfo(String fpqqlsh, String nsrsbh) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置商户联系方式, 获取授权链接前需要设置商户联系信息
|
* 设置商户联系方式, 获取授权链接前需要设置商户联系信息
|
||||||
|
*
|
||||||
|
* @param contact the contact
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void setMerchantContactInfo(MerchantContactInfo contact) throws WxErrorException;
|
void setMerchantContactInfo(MerchantContactInfo contact) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取商户联系方式
|
* 获取商户联系方式
|
||||||
|
*
|
||||||
|
* @return the merchant contact info
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
MerchantContactInfo getMerchantContactInfo() throws WxErrorException;
|
MerchantContactInfo getMerchantContactInfo() throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置授权页面字段
|
* 配置授权页面字段
|
||||||
|
*
|
||||||
|
* @param authPageSetting the auth page setting
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void setAuthPageSetting(InvoiceAuthPageSetting authPageSetting) throws WxErrorException;
|
void setAuthPageSetting(InvoiceAuthPageSetting authPageSetting) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取授权页面配置
|
* 获取授权页面配置
|
||||||
|
*
|
||||||
|
* @return the auth page setting
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
InvoiceAuthPageSetting getAuthPageSetting() throws WxErrorException;
|
InvoiceAuthPageSetting getAuthPageSetting() throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置商户开票平台信息
|
* 设置商户开票平台信息
|
||||||
|
*
|
||||||
|
* @param merchantInvoicePlatformInfo the merchant invoice platform info
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
void setMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException;
|
void setMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取商户开票平台信息
|
* 获取商户开票平台信息
|
||||||
|
*
|
||||||
|
* @param merchantInvoicePlatformInfo the merchant invoice platform info
|
||||||
|
* @return the merchant invoice platform
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
MerchantInvoicePlatformInfo getMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException;
|
MerchantInvoicePlatformInfo getMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
import com.google.gson.FieldNamingPolicy;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
@ -11,96 +10,85 @@ import me.chanjar.weixin.mp.api.WxMpMerchantInvoiceService;
|
|||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.bean.invoice.merchant.*;
|
import me.chanjar.weixin.mp.bean.invoice.merchant.*;
|
||||||
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
||||||
|
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Invoice.*;
|
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Invoice.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mario Luo
|
||||||
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class WxMpMerchantInvoiceServiceImpl implements WxMpMerchantInvoiceService {
|
public class WxMpMerchantInvoiceServiceImpl implements WxMpMerchantInvoiceService {
|
||||||
|
private final WxMpService wxMpService;
|
||||||
private WxMpService wxMpService;
|
private final WxMpCardService wxMpCardService;
|
||||||
private WxMpCardService wxMpCardService;
|
|
||||||
|
|
||||||
private final static Gson gson;
|
|
||||||
|
|
||||||
static {
|
|
||||||
gson = new GsonBuilder()
|
|
||||||
.disableHtmlEscaping()
|
|
||||||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InvoiceAuthPageResult getAuthPageUrl(InvoiceAuthPageRequest params) throws WxErrorException {
|
public InvoiceAuthPageResult getAuthPageUrl(InvoiceAuthPageRequest params) throws WxErrorException {
|
||||||
String ticket = wxMpCardService.getCardApiTicket();
|
String ticket = wxMpCardService.getCardApiTicket();
|
||||||
params.setTicket(ticket);
|
params.setTicket(ticket);
|
||||||
return doCommonInvoiceHttpPost(GET_AUTH_URL, params, InvoiceAuthPageResult.class);
|
return this.doCommonInvoiceHttpPost(GET_AUTH_URL, params, InvoiceAuthPageResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InvoiceAuthDataResult getAuthData(InvoiceAuthDataRequest params) throws WxErrorException {
|
public InvoiceAuthDataResult getAuthData(InvoiceAuthDataRequest params) throws WxErrorException {
|
||||||
return doCommonInvoiceHttpPost(GET_AUTH_DATA, params, InvoiceAuthDataResult.class);
|
return this.doCommonInvoiceHttpPost(GET_AUTH_DATA, params, InvoiceAuthDataResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rejectInvoice(InvoiceRejectRequest params) throws WxErrorException {
|
public void rejectInvoice(InvoiceRejectRequest params) throws WxErrorException {
|
||||||
doCommonInvoiceHttpPost(REJECT_INSERT, params, null);
|
this.doCommonInvoiceHttpPost(REJECT_INSERT, params, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeOutInvoice(MakeOutInvoiceRequest params) throws WxErrorException {
|
public void makeOutInvoice(MakeOutInvoiceRequest params) throws WxErrorException {
|
||||||
doCommonInvoiceHttpPost(MAKE_OUT_INVOICE, params, null);
|
this.doCommonInvoiceHttpPost(MAKE_OUT_INVOICE, params, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearOutInvoice(ClearOutInvoiceRequest params) throws WxErrorException {
|
public void clearOutInvoice(ClearOutInvoiceRequest params) throws WxErrorException {
|
||||||
doCommonInvoiceHttpPost(CLEAR_OUT_INVOICE, params, null);
|
this.doCommonInvoiceHttpPost(CLEAR_OUT_INVOICE, params, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InvoiceResult queryInvoiceInfo(String fpqqlsh, String nsrsbh) throws WxErrorException {
|
public InvoiceResult queryInvoiceInfo(String fpqqlsh, String nsrsbh) throws WxErrorException {
|
||||||
Map data = new HashMap();
|
Map<String, String> data = ImmutableMap.of("fpqqlsh", fpqqlsh, "nsrsbh", nsrsbh);
|
||||||
data.put("fpqqlsh", fpqqlsh);
|
return this.doCommonInvoiceHttpPost(QUERY_INVOICE_INFO, data, InvoiceResult.class);
|
||||||
data.put("nsrsbh", nsrsbh);
|
|
||||||
return doCommonInvoiceHttpPost(QUERY_INVOICE_INFO, data, InvoiceResult.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMerchantContactInfo(MerchantContactInfo contact) throws WxErrorException {
|
public void setMerchantContactInfo(MerchantContactInfo contact) throws WxErrorException {
|
||||||
MerchantContactInfoWrapper data = new MerchantContactInfoWrapper();
|
this.doCommonInvoiceHttpPost(SET_CONTACT_SET_BIZ_ATTR, new MerchantContactInfoWrapper(contact), null);
|
||||||
data.setContact(contact);
|
|
||||||
doCommonInvoiceHttpPost(SET_CONTACT_SET_BIZ_ATTR, data, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MerchantContactInfo getMerchantContactInfo() throws WxErrorException {
|
public MerchantContactInfo getMerchantContactInfo() throws WxErrorException {
|
||||||
MerchantContactInfoWrapper merchantContactInfoWrapper = doCommonInvoiceHttpPost(GET_CONTACT_SET_BIZ_ATTR, null, MerchantContactInfoWrapper.class);
|
MerchantContactInfoWrapper merchantContactInfoWrapper = this.doCommonInvoiceHttpPost(GET_CONTACT_SET_BIZ_ATTR, null, MerchantContactInfoWrapper.class);
|
||||||
return merchantContactInfoWrapper == null ? null : merchantContactInfoWrapper.getContact();
|
return merchantContactInfoWrapper == null ? null : merchantContactInfoWrapper.getContact();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthPageSetting(InvoiceAuthPageSetting authPageSetting) throws WxErrorException {
|
public void setAuthPageSetting(InvoiceAuthPageSetting authPageSetting) throws WxErrorException {
|
||||||
doCommonInvoiceHttpPost(SET_AUTH_FIELD_SET_BIZ_ATTR, authPageSetting, null);
|
this.doCommonInvoiceHttpPost(SET_AUTH_FIELD_SET_BIZ_ATTR, authPageSetting, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InvoiceAuthPageSetting getAuthPageSetting() throws WxErrorException {
|
public InvoiceAuthPageSetting getAuthPageSetting() throws WxErrorException {
|
||||||
return doCommonInvoiceHttpPost(GET_AUTH_FIELD_SET_BIZ_ATTR, new JsonObject(), InvoiceAuthPageSetting.class);
|
return this.doCommonInvoiceHttpPost(GET_AUTH_FIELD_SET_BIZ_ATTR, new JsonObject(), InvoiceAuthPageSetting.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMerchantInvoicePlatform(MerchantInvoicePlatformInfo paymchInfo) throws WxErrorException {
|
public void setMerchantInvoicePlatform(MerchantInvoicePlatformInfo paymchInfo) throws WxErrorException {
|
||||||
MerchantInvoicePlatformInfoWrapper data = new MerchantInvoicePlatformInfoWrapper();
|
MerchantInvoicePlatformInfoWrapper data = new MerchantInvoicePlatformInfoWrapper();
|
||||||
data.setPaymchInfo(paymchInfo);
|
data.setPaymchInfo(paymchInfo);
|
||||||
doCommonInvoiceHttpPost(SET_PAY_MCH_SET_BIZ_ATTR, data, null);
|
this.doCommonInvoiceHttpPost(SET_PAY_MCH_SET_BIZ_ATTR, data, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MerchantInvoicePlatformInfo getMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException {
|
public MerchantInvoicePlatformInfo getMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException {
|
||||||
MerchantInvoicePlatformInfoWrapper result = doCommonInvoiceHttpPost(GET_PAY_MCH_SET_BIZ_ATTR, new JsonObject(), MerchantInvoicePlatformInfoWrapper.class);
|
MerchantInvoicePlatformInfoWrapper result = this.doCommonInvoiceHttpPost(GET_PAY_MCH_SET_BIZ_ATTR, new JsonObject(), MerchantInvoicePlatformInfoWrapper.class);
|
||||||
return result == null ? null : result.getPaymchInfo();
|
return result == null ? null : result.getPaymchInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,11 +97,15 @@ public class WxMpMerchantInvoiceServiceImpl implements WxMpMerchantInvoiceServic
|
|||||||
*/
|
*/
|
||||||
private <T> T doCommonInvoiceHttpPost(WxMpApiUrl url, Object data, Class<T> resultClass) throws WxErrorException {
|
private <T> T doCommonInvoiceHttpPost(WxMpApiUrl url, Object data, Class<T> resultClass) throws WxErrorException {
|
||||||
String json = "";
|
String json = "";
|
||||||
|
final Gson gson = WxMpGsonBuilder.create();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
json = gson.toJson(data);
|
json = gson.toJson(data);
|
||||||
}
|
}
|
||||||
String responseText = wxMpService.post(url, json);
|
String responseText = wxMpService.post(url, json);
|
||||||
if (resultClass == null) return null;
|
if (resultClass == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return gson.fromJson(responseText, resultClass);
|
return gson.fromJson(responseText, resultClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
package me.chanjar.weixin.mp.bean.invoice.merchant;
|
package me.chanjar.weixin.mp.bean.invoice.merchant;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户联系信息
|
* 商户联系信息
|
||||||
|
*
|
||||||
|
* @author Mario Luo
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class MerchantContactInfo implements Serializable {
|
public class MerchantContactInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = -2008465944249686100L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系电话
|
* 联系电话
|
||||||
*/
|
*/
|
||||||
@ -17,6 +22,7 @@ public class MerchantContactInfo implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 开票超时时间
|
* 开票超时时间
|
||||||
*/
|
*/
|
||||||
|
@SerializedName("time_out")
|
||||||
private Integer timeout;
|
private Integer timeout;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package me.chanjar.weixin.mp.bean.invoice.merchant;
|
package me.chanjar.weixin.mp.bean.invoice.merchant;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置商户联系信息和发票过时时间参数
|
* 设置商户联系信息和发票过时时间参数
|
||||||
|
*
|
||||||
|
* @author Mario Luo
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
public class MerchantContactInfoWrapper implements Serializable {
|
public class MerchantContactInfoWrapper implements Serializable {
|
||||||
|
private static final long serialVersionUID = -5377979396495452212L;
|
||||||
|
|
||||||
private MerchantContactInfo contact;
|
private MerchantContactInfo contact;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user