master
parent
ba9419239e
commit
4e3ebe2646
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,22 @@
|
||||
package com.bsd.cases.model;
|
||||
|
||||
public class FillterConstants {
|
||||
|
||||
public static String EQUAL = "is";
|
||||
|
||||
public static String EQUALSYM = "=";
|
||||
|
||||
public static String LIKE = "like";
|
||||
|
||||
public static String LIKESYM = "regex";
|
||||
|
||||
public static String IN = "in";
|
||||
|
||||
public static String GTE = "gte";
|
||||
|
||||
public static String GTESYM = ">=";
|
||||
|
||||
public static String LTE = "lte";
|
||||
|
||||
public static String LTESYM = "<=";
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package com.bsd.cases.service.impl;
|
||||
|
||||
import com.bsd.cases.service.WxMpConfigStorage;
|
||||
import com.bsd.cases.service.WxMpService;
|
||||
import com.bsd.cases.util.wx.common.bean.WxAccessToken;
|
||||
import com.bsd.cases.util.wx.common.bean.result.WxError;
|
||||
import com.bsd.cases.util.wx.common.exception.WxErrorException;
|
||||
import com.bsd.cases.util.wx.common.session.StandardSessionManager;
|
||||
import com.bsd.cases.util.wx.common.session.WxSessionManager;
|
||||
import com.bsd.cases.util.wx.common.util.crypto.SHA1;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
|
||||
|
||||
/**
|
||||
* 全局的是否正在刷新access token的锁
|
||||
*/
|
||||
protected final Object globalAccessTokenRefreshLock = new Object();
|
||||
|
||||
/**
|
||||
* 全局的是否正在刷新jsapi_ticket的锁
|
||||
*/
|
||||
protected final Object globalJsapiTicketRefreshLock = new Object();
|
||||
|
||||
protected WxMpConfigStorage wxMpConfigStorage;
|
||||
|
||||
protected CloseableHttpClient httpClient;
|
||||
|
||||
protected HttpHost httpProxy;
|
||||
|
||||
private int retrySleepMillis = 1000;
|
||||
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
protected WxSessionManager sessionManager = new StandardSessionManager();
|
||||
|
||||
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
||||
try {
|
||||
return SHA1.gen(wxMpConfigStorage.getToken(), timestamp, nonce).equals(signature);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccessToken() throws WxErrorException {
|
||||
return getAccessToken(false);
|
||||
}
|
||||
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
if (forceRefresh) {
|
||||
wxMpConfigStorage.expireAccessToken();
|
||||
}
|
||||
if (wxMpConfigStorage.isAccessTokenExpired()) {
|
||||
synchronized (globalAccessTokenRefreshLock) {
|
||||
if (wxMpConfigStorage.isAccessTokenExpired()) {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
|
||||
+ "&appid=" + wxMpConfigStorage.getAppId()
|
||||
+ "&secret=" + wxMpConfigStorage.getSecret();
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
CloseableHttpResponse response = getHttpclient().execute(httpGet);
|
||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
WxError error = WxError.fromJson(resultContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
|
||||
} catch (ClientProtocolException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return wxMpConfigStorage.getAccessToken();
|
||||
}
|
||||
|
||||
protected CloseableHttpClient getHttpclient() {
|
||||
return httpClient;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.bsd.cases.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CaseVo {
|
||||
|
||||
}
|
Loading…
Reference in New Issue