mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-01 11:38:27 +08:00
1、增加卡券的api_ticket,区分jsapi_ticket,二者的获取逻辑不同;
2、增加小程序审核事件及审核事件推送消息SuccTime和Reason两个字段; 3、增加开放平台获取会员卡开卡插件参数接口。 4、增加开放平台手机端预授权接口实现;
This commit is contained in:
@ -15,7 +15,26 @@ public interface WxMaJsapiService {
|
||||
/**
|
||||
* 获得jsapi_ticket的url
|
||||
*/
|
||||
String GET_JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
|
||||
String GET_JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
|
||||
|
||||
/**
|
||||
* 获得卡券api_ticket,不强制刷新api_ticket
|
||||
*
|
||||
* @see #getJsapiTicket(boolean)
|
||||
*/
|
||||
String getCardApiTicket() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获得卡券api_ticket
|
||||
* 获得时会检查apiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
|
||||
*
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||
* </pre>
|
||||
*
|
||||
* @param forceRefresh 强制刷新
|
||||
*/
|
||||
String getCardApiTicket(boolean forceRefresh) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获得jsapi_ticket,不强制刷新jsapi_ticket
|
||||
|
||||
@ -28,6 +28,32 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
|
||||
this.wxMaService = wxMaService;
|
||||
}
|
||||
|
||||
public String getCardApiTicket() throws WxErrorException {
|
||||
return getCardApiTicket(false);
|
||||
}
|
||||
|
||||
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
|
||||
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock();
|
||||
try {
|
||||
lock.lock();
|
||||
if (forceRefresh) {
|
||||
this.wxMaService.getWxMaConfig().expireCardApiTicket();
|
||||
}
|
||||
|
||||
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
|
||||
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
|
||||
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
|
||||
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
||||
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
||||
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
|
||||
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.wxMaService.getWxMaConfig().getJsapiTicket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJsapiTicket() throws WxErrorException {
|
||||
return getJsapiTicket(false);
|
||||
@ -43,7 +69,7 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
|
||||
}
|
||||
|
||||
if (this.wxMaService.getWxMaConfig().isJsapiTicketExpired()) {
|
||||
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL, null);
|
||||
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
|
||||
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
|
||||
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
||||
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
||||
|
||||
@ -57,6 +57,25 @@ public interface WxMaConfig {
|
||||
*/
|
||||
void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
|
||||
|
||||
String getCardApiTicket();
|
||||
|
||||
Lock getCardApiTicketLock();
|
||||
|
||||
boolean isCardApiTicketExpired();
|
||||
|
||||
/**
|
||||
* 强制将卡券api ticket过期掉
|
||||
*/
|
||||
void expireCardApiTicket();
|
||||
|
||||
/**
|
||||
* 应该是线程安全的
|
||||
*
|
||||
* @param 卡券apiTicket 新的卡券api ticket值
|
||||
* @param expiresInSeconds 过期时间,以秒为单位
|
||||
*/
|
||||
void updateCardApiTicket(String apiTicket, int expiresInSeconds);
|
||||
|
||||
String getAppid();
|
||||
|
||||
String getSecret();
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
package cn.binarywang.wx.miniapp.config;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
|
||||
/**
|
||||
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
|
||||
*
|
||||
@ -32,8 +31,14 @@ public class WxMaInMemoryConfig implements WxMaConfig {
|
||||
protected volatile String jsapiTicket;
|
||||
protected volatile long jsapiTicketExpiresTime;
|
||||
|
||||
//微信卡券的ticket单独缓存
|
||||
protected volatile String cardApiTicket;
|
||||
protected volatile long cardApiTicketExpiresTime;
|
||||
|
||||
|
||||
protected Lock accessTokenLock = new ReentrantLock();
|
||||
protected Lock jsapiTicketLock = new ReentrantLock();
|
||||
protected Lock cardApiTicketLock = new ReentrantLock();
|
||||
|
||||
/**
|
||||
* 临时文件目录
|
||||
@ -103,6 +108,34 @@ public class WxMaInMemoryConfig implements WxMaConfig {
|
||||
this.jsapiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCardApiTicket() {
|
||||
return this.cardApiTicket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lock getCardApiTicketLock() {
|
||||
return this.cardApiTicketLock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCardApiTicketExpired() {
|
||||
return System.currentTimeMillis() > this.cardApiTicketExpiresTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expireCardApiTicket() {
|
||||
this.cardApiTicketExpiresTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCardApiTicket(String cardApiTicket, int expiresInSeconds) {
|
||||
this.cardApiTicket = cardApiTicket;
|
||||
// 预留200秒的时间
|
||||
this.cardApiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expireAccessToken() {
|
||||
this.expiresTime = 0;
|
||||
|
||||
Reference in New Issue
Block a user