获取ticket
parent
1a8c1d4a58
commit
34e5b63738
@ -0,0 +1,124 @@
|
||||
package com.bsd.say.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "wechat.redis")
|
||||
public class RedisProperies extends JedisPoolConfig {
|
||||
private String host = "111.229.204.101";
|
||||
private int port = 63790;
|
||||
private String password = "1qaz2wsx";
|
||||
private int database = 4;
|
||||
private int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
|
||||
private int soTimeout = Protocol.DEFAULT_TIMEOUT;
|
||||
private String clientName;
|
||||
private boolean ssl;
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
private SSLParameters sslParameters;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
|
||||
public boolean isSsl() {
|
||||
return ssl;
|
||||
}
|
||||
|
||||
public void setSsl(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public SSLSocketFactory getSslSocketFactory() {
|
||||
return sslSocketFactory;
|
||||
}
|
||||
|
||||
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
}
|
||||
|
||||
public SSLParameters getSslParameters() {
|
||||
return sslParameters;
|
||||
}
|
||||
|
||||
public void setSslParameters(SSLParameters sslParameters) {
|
||||
this.sslParameters = sslParameters;
|
||||
}
|
||||
|
||||
public HostnameVerifier getHostnameVerifier() {
|
||||
return hostnameVerifier;
|
||||
}
|
||||
|
||||
public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
if (host == null || "".equals(host)) {
|
||||
host = Protocol.DEFAULT_HOST;
|
||||
}
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
if ("".equals(password)) {
|
||||
password = null;
|
||||
}
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
if ("".equals(clientName)) {
|
||||
clientName = null;
|
||||
}
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public int getSoTimeout() {
|
||||
return soTimeout;
|
||||
}
|
||||
|
||||
public void setSoTimeout(int soTimeout) {
|
||||
this.soTimeout = soTimeout;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.bsd.say.service;
|
||||
|
||||
import com.bsd.say.config.RedisProperies;
|
||||
import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
|
||||
import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter;
|
||||
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.stereotype.Service;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Service
|
||||
public class WxOpenServiceDemo extends WxOpenServiceImpl {
|
||||
@Value("${wechat.aesKey}")
|
||||
private String aesKey;
|
||||
@Value("${wechat.componentToken}")
|
||||
private String componentToken;
|
||||
@Value("${wechat.appId}")
|
||||
private String appId;
|
||||
@Value("${wechat.componentAppId}")
|
||||
private String componentAppId;
|
||||
@Value("${wechat.componentAppSecret}")
|
||||
private String componentAppSecret;
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static JedisPool pool;
|
||||
private WxOpenMessageRouter wxOpenMessageRouter;
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
WxOpenInRedisConfigStorage inRedisConfigStorage = new WxOpenInRedisConfigStorage(getJedisPool());
|
||||
inRedisConfigStorage.setComponentAppId(componentAppId);
|
||||
inRedisConfigStorage.setComponentAppSecret(componentAppSecret);
|
||||
inRedisConfigStorage.setComponentToken(componentToken);
|
||||
inRedisConfigStorage.setComponentAesKey(aesKey);
|
||||
setWxOpenConfigStorage(inRedisConfigStorage);
|
||||
wxOpenMessageRouter = new WxOpenMessageRouter(this);
|
||||
wxOpenMessageRouter.rule().handler((wxMpXmlMessage, map, wxMpService, wxSessionManager) -> {
|
||||
logger.info("\n接收到 {} 公众号请求消息,内容:{}", wxMpService.getWxMpConfigStorage().getAppId(), wxMpXmlMessage);
|
||||
return null;
|
||||
}).next();
|
||||
}
|
||||
public WxOpenMessageRouter getWxOpenMessageRouter(){
|
||||
return wxOpenMessageRouter;
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool() {
|
||||
RedisProperies redisProperies = new RedisProperies();
|
||||
if (pool == null) {
|
||||
synchronized (WxOpenServiceDemo.class) {
|
||||
if (pool == null) {
|
||||
pool = new JedisPool(redisProperies, redisProperies.getHost(),
|
||||
redisProperies.getPort(), redisProperies.getConnectionTimeout(),
|
||||
redisProperies.getSoTimeout(), redisProperies.getPassword(),
|
||||
redisProperies.getDatabase(), redisProperies.getClientName(),
|
||||
redisProperies.isSsl(), redisProperies.getSslSocketFactory(),
|
||||
redisProperies.getSslParameters(), redisProperies.getHostnameVerifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue