-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…增加商户电子发票功能
- Loading branch information
Showing
25 changed files
with
1,078 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
weixin-java-common/src/test/java/me/chanjar/weixin/common/redis/CommonWxRedisOpsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.chanjar.weixin.common.redis; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class CommonWxRedisOpsTest { | ||
|
||
protected WxRedisOps wxRedisOps; | ||
private String key = "access_token"; | ||
private String value = String.valueOf(System.currentTimeMillis()); | ||
|
||
@Test | ||
public void testGetValue() { | ||
wxRedisOps.setValue(key, value, 3, TimeUnit.SECONDS); | ||
Assert.assertEquals(wxRedisOps.getValue(key), value); | ||
} | ||
|
||
@Test | ||
public void testSetValue() { | ||
String key = "access_token", value = String.valueOf(System.currentTimeMillis()); | ||
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS); | ||
wxRedisOps.setValue(key, value, 0, TimeUnit.SECONDS); | ||
wxRedisOps.setValue(key, value, 1, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testGetExpire() { | ||
String key = "access_token", value = String.valueOf(System.currentTimeMillis()); | ||
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS); | ||
Assert.assertTrue(wxRedisOps.getExpire(key) < 0); | ||
wxRedisOps.setValue(key, value, 4, TimeUnit.SECONDS); | ||
Long expireSeconds = wxRedisOps.getExpire(key); | ||
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0); | ||
} | ||
|
||
@Test | ||
public void testExpire() { | ||
String key = "access_token", value = String.valueOf(System.currentTimeMillis()); | ||
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS); | ||
wxRedisOps.expire(key, 4, TimeUnit.SECONDS); | ||
Long expireSeconds = wxRedisOps.getExpire(key); | ||
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0); | ||
} | ||
|
||
@Test | ||
public void testGetLock() { | ||
Assert.assertNotNull(wxRedisOps.getLock("access_token_lock")); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
weixin-java-common/src/test/java/me/chanjar/weixin/common/redis/JedisWxRedisOpsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.chanjar.weixin.common.redis; | ||
|
||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
import redis.clients.jedis.JedisPool; | ||
|
||
public class JedisWxRedisOpsTest extends CommonWxRedisOpsTest { | ||
|
||
JedisPool jedisPool; | ||
|
||
@BeforeTest | ||
public void init() { | ||
this.jedisPool = new JedisPool("127.0.0.1", 6379); | ||
this.wxRedisOps = new JedisWxRedisOps(jedisPool); | ||
} | ||
|
||
@AfterTest | ||
public void destroy() { | ||
this.jedisPool.close(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...java-common/src/test/java/me/chanjar/weixin/common/redis/RedisTemplateWxRedisOpsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.chanjar.weixin.common.redis; | ||
|
||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
|
||
public class RedisTemplateWxRedisOpsTest extends CommonWxRedisOpsTest { | ||
|
||
StringRedisTemplate redisTemplate; | ||
|
||
@BeforeTest | ||
public void init() { | ||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(); | ||
connectionFactory.setHostName("127.0.0.1"); | ||
connectionFactory.setPort(6379); | ||
connectionFactory.afterPropertiesSet(); | ||
StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory); | ||
this.redisTemplate = redisTemplate; | ||
this.wxRedisOps = new RedisTemplateWxRedisOps(this.redisTemplate); | ||
} | ||
|
||
@AfterTest | ||
public void destroy() { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
weixin-java-common/src/test/java/me/chanjar/weixin/common/redis/RedissonWxRedisOpsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.chanjar.weixin.common.redis; | ||
|
||
import org.redisson.Redisson; | ||
import org.redisson.api.RedissonClient; | ||
import org.redisson.config.Config; | ||
import org.redisson.config.TransportMode; | ||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
|
||
public class RedissonWxRedisOpsTest extends CommonWxRedisOpsTest { | ||
|
||
RedissonClient redissonClient; | ||
|
||
@BeforeTest | ||
public void init() { | ||
Config config = new Config(); | ||
config.useSingleServer().setAddress("redis://127.0.0.1:6379"); | ||
config.setTransportMode(TransportMode.NIO); | ||
this.redissonClient = Redisson.create(config); | ||
this.wxRedisOps = new RedissonWxRedisOps(this.redissonClient); | ||
} | ||
|
||
@AfterTest | ||
public void destroy() { | ||
this.redissonClient.shutdown(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMerchantInvoiceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package me.chanjar.weixin.mp.api; | ||
|
||
|
||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.mp.bean.invoice.merchant.*; | ||
|
||
/** | ||
* 商户电子发票相关的接口 | ||
* <p> | ||
* 重要!!!, 根据不同开票平台, 以下错误码可能开票成功(开票,冲红), 内部暂时未处理: | ||
* 73105: 开票平台开票中,请使用相同的发票请求流水号重试开票 | ||
* 73107: 发票请求流水正在被处理,请通过查询接口获取结果 | ||
* 73100: 开票平台错误 | ||
* <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_API_List.html | ||
*/ | ||
public interface WxMpMerchantInvoiceService { | ||
|
||
/** | ||
* 获取开票授权页链接 | ||
*/ | ||
InvoiceAuthPageResult getAuthPageUrl(InvoiceAuthPageRequest params) throws WxErrorException; | ||
|
||
/** | ||
* 获得用户授权数据 | ||
*/ | ||
InvoiceAuthDataResult getAuthData(InvoiceAuthDataRequest params) throws WxErrorException; | ||
|
||
/** | ||
* 拒绝开票 | ||
* <p> | ||
* 场景: 用户授权填写数据无效 | ||
* 结果: 用户会收到一条开票失败提示 | ||
*/ | ||
void rejectInvoice(InvoiceRejectRequest params) throws WxErrorException; | ||
|
||
/** | ||
* 开具电子发票 | ||
*/ | ||
void makeOutInvoice(MakeOutInvoiceRequest params) throws WxErrorException; | ||
|
||
/** | ||
* 发票冲红 | ||
*/ | ||
void clearOutInvoice(ClearOutInvoiceRequest params) throws WxErrorException; | ||
|
||
/** | ||
* 查询发票信息 | ||
* | ||
* @param fpqqlsh 发票请求流水号 | ||
* @param nsrsbh 纳税人识别号 | ||
*/ | ||
InvoiceResult queryInvoiceInfo(String fpqqlsh, String nsrsbh) throws WxErrorException; | ||
|
||
/** | ||
* 设置商户联系方式, 获取授权链接前需要设置商户联系信息 | ||
*/ | ||
void setMerchantContactInfo(MerchantContactInfo contact) throws WxErrorException; | ||
|
||
/** | ||
* 获取商户联系方式 | ||
*/ | ||
MerchantContactInfo getMerchantContactInfo() throws WxErrorException; | ||
|
||
/** | ||
* 配置授权页面字段 | ||
*/ | ||
void setAuthPageSetting(InvoiceAuthPageSetting authPageSetting) throws WxErrorException; | ||
|
||
/** | ||
* 获取授权页面配置 | ||
*/ | ||
InvoiceAuthPageSetting getAuthPageSetting() throws WxErrorException; | ||
|
||
/** | ||
* 设置商户开票平台信息 | ||
*/ | ||
void setMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException; | ||
|
||
/** | ||
* 获取商户开票平台信息 | ||
*/ | ||
MerchantInvoicePlatformInfo getMerchantInvoicePlatform(MerchantInvoicePlatformInfo merchantInvoicePlatformInfo) throws WxErrorException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.