重构token实现机制
This commit is contained in:
parent
5b40a3728c
commit
9f8af3f725
@ -220,8 +220,16 @@ netty的代码没有放到maven中心仓库,也没什么意义,因为最终需
|
|||||||
|
|
||||||
+ **weixin4j-qy**: 新增批量删除员工接口
|
+ **weixin4j-qy**: 新增批量删除员工接口
|
||||||
|
|
||||||
|
* 2015-01-10
|
||||||
|
|
||||||
|
+ **weixin4j-base**: 重构token实现机制
|
||||||
|
|
||||||
接下来
|
接下来
|
||||||
------
|
------
|
||||||
|
* 公众号数据分析接口
|
||||||
|
|
||||||
|
* 公众号服务应用
|
||||||
|
|
||||||
* 企业号第三方应用
|
* 企业号第三方应用
|
||||||
|
|
||||||
* 微信小店
|
* 微信小店
|
||||||
|
|||||||
@ -41,4 +41,8 @@ weixin4j-base
|
|||||||
|
|
||||||
* 2015-01-04
|
* 2015-01-04
|
||||||
|
|
||||||
+ ConfigUtil类新增获取classpath目录下的资源路径的方法
|
+ ConfigUtil类新增获取classpath目录下的资源路径的方法
|
||||||
|
|
||||||
|
* 2015-01-10
|
||||||
|
|
||||||
|
+ 重构token实现机制
|
||||||
@ -100,11 +100,16 @@ public class HttpRequest {
|
|||||||
StringBuilder sb = new StringBuilder(url);
|
StringBuilder sb = new StringBuilder(url);
|
||||||
if (parameters != null && parameters.length > 0) {
|
if (parameters != null && parameters.length > 0) {
|
||||||
if (url.indexOf("?") < 0) {
|
if (url.indexOf("?") < 0) {
|
||||||
sb.append(String.format("?%s=%s", parameters[0].getName(),
|
sb.append("?");
|
||||||
parameters[0].getValue()));
|
} else {
|
||||||
|
sb.append("&");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
sb.append(String.format("%s=%s", parameters[0].getName(),
|
||||||
sb.append(parameters[i].toGetPara());
|
parameters[0].getValue()));
|
||||||
|
if (parameters.length > 1) {
|
||||||
|
for (int i = 1; i < parameters.length; i++) {
|
||||||
|
sb.append(parameters[i].toGetPara());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return doRequest(new HttpGet(sb.toString()));
|
return doRequest(new HttpGet(sb.toString()));
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.model;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token,正常情况下access_token有效期为7200秒,
|
* access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token,正常情况下access_token有效期为7200秒,
|
||||||
@ -15,19 +14,27 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html">微信公众平台获取token</a>
|
* href="http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html">微信公众平台获取token</a>
|
||||||
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8">微信企业号的主动模式</a>
|
* @see <a
|
||||||
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8">微信企业号的主动模式</a>
|
||||||
*/
|
*/
|
||||||
@XStreamAlias("app-token")
|
|
||||||
public class Token implements Serializable {
|
public class Token implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7564855472419104084L;
|
private static final long serialVersionUID = -7564855472419104084L;
|
||||||
|
|
||||||
@JSONField(name = "access_token")
|
@JSONField(name = "access_token")
|
||||||
private String accessToken;
|
private String accessToken;
|
||||||
@JSONField(name = "expires_in")
|
@JSONField(name = "expires_in")
|
||||||
private int expiresIn;
|
private int expiresIn;
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
|
public Token() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Token(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAccessToken() {
|
public String getAccessToken() {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.token;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取weixin.properties中的id&secret信息
|
|
||||||
*
|
|
||||||
* @className AbstractTokenHolder
|
|
||||||
* @author jy
|
|
||||||
* @date 2014年10月6日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public abstract class AbstractTokenHolder implements TokenHolder {
|
|
||||||
|
|
||||||
protected final HttpRequest request = new HttpRequest();
|
|
||||||
protected final WeixinAccount weixinAccount;
|
|
||||||
|
|
||||||
public AbstractTokenHolder(AccountType accountType) {
|
|
||||||
this.weixinAccount = ConfigUtil
|
|
||||||
.getWeixinAccount(accountType.getClazz());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AbstractTokenHolder(WeixinAccount weixinAccount) {
|
|
||||||
this.weixinAccount = weixinAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeixinAccount getAccount() {
|
|
||||||
return weixinAccount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,87 +1,67 @@
|
|||||||
package com.foxinmy.weixin4j.token;
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.thoughtworks.xstream.XStream;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
/**
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
* 用FILE保存TOKEN
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
*
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
* @className FileTokenHolder
|
||||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
* @author jy
|
||||||
|
* @date 2015年1月9日
|
||||||
/**
|
* @since JDK 1.7
|
||||||
* 基于文件保存的Token获取类
|
* @see com.foxinmy.weixin4j.token.TokenCreator
|
||||||
*
|
* @see com.foxinmy.weixin4j.token.WeixinTokenCreator
|
||||||
* @className FileTokenHolder
|
*/
|
||||||
* @author jy.hu
|
public class FileTokenHolder implements TokenHolder {
|
||||||
* @date 2014年9月27日
|
private final XStream xstream;
|
||||||
* @since JDK 1.7
|
private final String tokenPath;
|
||||||
* @see <a
|
private final TokenCreator tokenCretor;
|
||||||
* href="http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html">微信公众平台获取token说明</a>
|
|
||||||
* @see <a
|
public FileTokenHolder(TokenCreator tokenCretor) {
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8">微信企业号获取token说明</a>
|
this(ConfigUtil.getValue("token_path"), tokenCretor);
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
}
|
||||||
*/
|
|
||||||
public class FileTokenHolder extends AbstractTokenHolder {
|
public FileTokenHolder(String tokenPath, TokenCreator tokenCretor) {
|
||||||
|
this.tokenPath = tokenPath;
|
||||||
public FileTokenHolder(AccountType accountType) {
|
this.tokenCretor = tokenCretor;
|
||||||
super(accountType);
|
xstream = new XStream();
|
||||||
}
|
xstream.ignoreUnknownElements();
|
||||||
|
xstream.autodetectAnnotations(true);
|
||||||
public FileTokenHolder(WeixinAccount weixinAccount) {
|
xstream.alias("xml", Token.class);
|
||||||
super(weixinAccount);
|
xstream.processAnnotations(Token.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 获取token
|
public Token getToken() throws WeixinException {
|
||||||
* <p>
|
File token_file = new File(String.format("%s/%s.xml", tokenPath,
|
||||||
* 正常情况下返回{"access_token":"ACCESS_TOKEN","expires_in":7200},否则抛出异常.
|
tokenCretor.getCacheKey()));
|
||||||
* </p>
|
Token token = null;
|
||||||
*
|
Calendar ca = Calendar.getInstance();
|
||||||
* @return token对象
|
long now_time = ca.getTimeInMillis();
|
||||||
* @throws WeixinException
|
try {
|
||||||
* @see <a
|
if (token_file.exists()) {
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96access_token">获取token说明</a>
|
token = (Token) xstream
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
.fromXML(new FileInputStream(token_file));
|
||||||
*/
|
long expire_time = token.getTime()
|
||||||
@Override
|
+ (token.getExpiresIn() * 1000) - 2;
|
||||||
public Token getToken() throws WeixinException {
|
if (expire_time > now_time) {
|
||||||
String id = weixinAccount.getId();
|
return token;
|
||||||
if (StringUtils.isBlank(id)
|
}
|
||||||
|| StringUtils.isBlank(weixinAccount.getSecret())) {
|
}
|
||||||
throw new IllegalArgumentException("id or secret not be null!");
|
token = tokenCretor.createToken();
|
||||||
}
|
xstream.toXML(token, new FileOutputStream(token_file));
|
||||||
File token_file = new File(String.format("%s/token_%s.xml",
|
} catch (IOException e) {
|
||||||
ConfigUtil.getValue("token_path"), id));
|
throw new WeixinException(e.getMessage());
|
||||||
Token token = null;
|
}
|
||||||
Calendar ca = Calendar.getInstance();
|
return token;
|
||||||
long now_time = ca.getTimeInMillis();
|
}
|
||||||
try {
|
}
|
||||||
if (token_file.exists()) {
|
|
||||||
token = XmlStream.get(new FileInputStream(token_file),
|
|
||||||
Token.class);
|
|
||||||
long expire_time = token.getTime()
|
|
||||||
+ (token.getExpiresIn() * 1000) - 2;
|
|
||||||
if (expire_time > now_time) {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Response response = request.get(weixinAccount.getTokenUrl());
|
|
||||||
token = response.getAsObject(new TypeReference<Token>() {
|
|
||||||
});
|
|
||||||
token.setTime(now_time);
|
|
||||||
XmlStream.to(token, new FileOutputStream(token_file));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new WeixinException(e.getMessage());
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,96 +1,81 @@
|
|||||||
package com.foxinmy.weixin4j.token;
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
/**
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
* 用REDIS保存TOKEN
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
*
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
* @className RedisTokenHolder
|
||||||
|
* @author jy
|
||||||
/**
|
* @date 2015年1月9日
|
||||||
* 基于redis保存的Token获取类
|
* @since JDK 1.7
|
||||||
*
|
* @see com.foxinmy.weixin4j.token.TokenCreator
|
||||||
* @className RedisTokenHolder
|
* @see com.foxinmy.weixin4j.token.WeixinTokenCreator
|
||||||
* @author jy.hu
|
*/
|
||||||
* @date 2014年9月27日
|
public class RedisTokenHolder implements TokenHolder {
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
private JedisPool jedisPool;
|
||||||
* href="http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html">微信公众平台获取token说明</a>
|
private final TokenCreator tokenCretor;
|
||||||
* @see <a href=
|
|
||||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8"
|
public final static int MAX_TOTAL = 50;
|
||||||
* >微信企业号获取token说明</a>
|
public final static int MAX_IDLE = 5;
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
public final static int MAX_WAIT_MILLIS = 2000;
|
||||||
*/
|
public final static boolean TEST_ON_BORROW = false;
|
||||||
public class RedisTokenHolder extends AbstractTokenHolder {
|
public final static boolean TEST_ON_RETURN = true;
|
||||||
|
|
||||||
private JedisPool jedisPool;
|
public RedisTokenHolder(TokenCreator tokenCretor) {
|
||||||
|
this("localhost", 6379, tokenCretor);
|
||||||
private void createPool(String host, int port) {
|
}
|
||||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
|
||||||
poolConfig.setMaxTotal(50);
|
public RedisTokenHolder(String host, int port, TokenCreator tokenCretor) {
|
||||||
poolConfig.setMaxIdle(5);
|
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||||
poolConfig.setMaxWaitMillis(2000);
|
jedisPoolConfig.setMaxTotal(MAX_TOTAL);
|
||||||
poolConfig.setTestOnBorrow(false);
|
jedisPoolConfig.setMaxIdle(MAX_IDLE);
|
||||||
poolConfig.setTestOnReturn(true);
|
jedisPoolConfig.setMaxWaitMillis(MAX_WAIT_MILLIS);
|
||||||
this.jedisPool = new JedisPool(poolConfig, host, port);
|
jedisPoolConfig.setTestOnBorrow(TEST_ON_BORROW);
|
||||||
}
|
jedisPoolConfig.setTestOnReturn(TEST_ON_RETURN);
|
||||||
|
this.jedisPool = new JedisPool(jedisPoolConfig, host, port);
|
||||||
public RedisTokenHolder(String host, int port, AccountType accountType) {
|
this.tokenCretor = tokenCretor;
|
||||||
super(accountType);
|
}
|
||||||
createPool(host, port);
|
|
||||||
}
|
public RedisTokenHolder(String host, int port,
|
||||||
|
JedisPoolConfig jedisPoolConfig, TokenCreator tokenCretor) {
|
||||||
public RedisTokenHolder(AccountType accountType) {
|
this(new JedisPool(jedisPoolConfig, host, port), tokenCretor);
|
||||||
this("localhost", 6379, accountType);
|
}
|
||||||
}
|
|
||||||
|
public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCretor) {
|
||||||
public RedisTokenHolder(WeixinAccount weixinAccount) {
|
this.jedisPool = jedisPool;
|
||||||
this("localhost", 6379, weixinAccount);
|
this.tokenCretor = tokenCretor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisTokenHolder(String host, int port, WeixinAccount weixinAccount) {
|
@Override
|
||||||
super(weixinAccount);
|
public Token getToken() throws WeixinException {
|
||||||
createPool(host, port);
|
Token token = null;
|
||||||
}
|
Jedis jedis = null;
|
||||||
|
try {
|
||||||
@Override
|
jedis = jedisPool.getResource();
|
||||||
public Token getToken() throws WeixinException {
|
String cacheKey = tokenCretor.getCacheKey();
|
||||||
String id = weixinAccount.getId();
|
String accessToken = jedis.get(cacheKey);
|
||||||
if (StringUtils.isBlank(id)
|
if (StringUtils.isBlank(accessToken)) {
|
||||||
|| StringUtils.isBlank(weixinAccount.getSecret())) {
|
token = tokenCretor.createToken();
|
||||||
throw new IllegalArgumentException("id or secret not be null!");
|
jedis.setex(cacheKey, (int) token.getExpiresIn(),
|
||||||
}
|
token.getAccessToken());
|
||||||
Token token = null;
|
} else {
|
||||||
Jedis jedis = null;
|
token = new Token(accessToken);
|
||||||
try {
|
}
|
||||||
jedis = jedisPool.getResource();
|
} catch (JedisException e) {
|
||||||
Calendar now = Calendar.getInstance();
|
jedisPool.returnBrokenResource(jedis);
|
||||||
String key = String.format("token:%s", id);
|
} finally {
|
||||||
String accessToken = jedis.get(key);
|
jedisPool.returnResource(jedis);
|
||||||
if (StringUtils.isBlank(accessToken)) {
|
}
|
||||||
token = request.get(weixinAccount.getTokenUrl()).getAsObject(
|
return token;
|
||||||
new TypeReference<Token>() {
|
}
|
||||||
});
|
}
|
||||||
jedis.setex(key, token.getExpiresIn(),
|
|
||||||
token.getAccessToken());
|
|
||||||
token.setTime(now.getTimeInMillis());
|
|
||||||
} else {
|
|
||||||
token = new Token();
|
|
||||||
token.setAccessToken(accessToken);
|
|
||||||
}
|
|
||||||
} catch (JedisException e) {
|
|
||||||
jedisPool.returnBrokenResource(jedis);
|
|
||||||
} finally {
|
|
||||||
jedisPool.returnResource(jedis);
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TOKEN创建者
|
||||||
|
*
|
||||||
|
* @className TokenCreator
|
||||||
|
* @author jy
|
||||||
|
* @date 2015年1月10日
|
||||||
|
* @since JDK 1.7
|
||||||
|
* @see
|
||||||
|
*/
|
||||||
|
public interface TokenCreator {
|
||||||
|
/**
|
||||||
|
* 返回缓存KEY的名称
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getCacheKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws MeetException
|
||||||
|
*/
|
||||||
|
public Token createToken() throws WeixinException;
|
||||||
|
}
|
||||||
@ -2,21 +2,18 @@ package com.foxinmy.weixin4j.token;
|
|||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Token接口
|
* token持有者
|
||||||
*
|
*
|
||||||
* @className TokenHolder
|
* @className TokenHolder
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年9月27日
|
* @date 2014年9月27日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
* @see com.foxinmy.weixin4j.token.AbstractTokenHolder
|
|
||||||
* @see com.foxinmy.weixin4j.token.FileTokenHolder
|
* @see com.foxinmy.weixin4j.token.FileTokenHolder
|
||||||
* @see com.foxinmy.weixin4j.token.RedisTokenHolder
|
* @see com.foxinmy.weixin4j.token.RedisTokenHolder
|
||||||
*/
|
*/
|
||||||
public interface TokenHolder {
|
public interface TokenHolder {
|
||||||
public WeixinAccount getAccount();
|
|
||||||
public Token getToken() throws WeixinException;
|
public Token getToken() throws WeixinException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||||
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||||
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信TOKEN创建者
|
||||||
|
*
|
||||||
|
* @className WeixinTokenCreator
|
||||||
|
* @author jy
|
||||||
|
* @date 2015年1月10日
|
||||||
|
* @since JDK 1.7
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html">微信公众平台获取token说明</a>
|
||||||
|
* @see <a
|
||||||
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E5%8A%A8%E8%B0%83%E7%94%A8">微信企业号获取token说明</a>
|
||||||
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
|
*/
|
||||||
|
public class WeixinTokenCreator implements TokenCreator {
|
||||||
|
|
||||||
|
private final HttpRequest request;
|
||||||
|
private final WeixinAccount weixinAccount;
|
||||||
|
|
||||||
|
public WeixinTokenCreator(AccountType accountType) {
|
||||||
|
this(ConfigUtil.getWeixinAccount(accountType.getClazz()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeixinTokenCreator(WeixinAccount weixinAccount) {
|
||||||
|
this.request = new HttpRequest();
|
||||||
|
this.weixinAccount = weixinAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCacheKey() {
|
||||||
|
return weixinAccount.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Token createToken() throws WeixinException {
|
||||||
|
Response response = request.get(weixinAccount.getTokenUrl());
|
||||||
|
Token token = response.getAsObject(new TypeReference<Token>() {
|
||||||
|
});
|
||||||
|
token.setTime(System.currentTimeMillis());
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,9 +15,6 @@ import com.foxinmy.weixin4j.mp.type.BillType;
|
|||||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||||
import com.foxinmy.weixin4j.mp.type.IdType;
|
import com.foxinmy.weixin4j.mp.type.IdType;
|
||||||
import com.foxinmy.weixin4j.mp.type.RefundType;
|
import com.foxinmy.weixin4j.mp.type.RefundType;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,11 +32,8 @@ public class WeixinPayProxy {
|
|||||||
private final Pay2Api pay2Api;
|
private final Pay2Api pay2Api;
|
||||||
private final Pay3Api pay3Api;
|
private final Pay3Api pay3Api;
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认采用文件存放Token信息
|
|
||||||
*/
|
|
||||||
public WeixinPayProxy() {
|
public WeixinPayProxy() {
|
||||||
this(new FileTokenHolder(AccountType.MP));
|
this(ConfigUtil.getWeixinMpAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,18 +43,9 @@ public class WeixinPayProxy {
|
|||||||
* 微信账户
|
* 微信账户
|
||||||
*/
|
*/
|
||||||
public WeixinPayProxy(WeixinMpAccount weixinAccount) {
|
public WeixinPayProxy(WeixinMpAccount weixinAccount) {
|
||||||
this(new FileTokenHolder(weixinAccount));
|
this.pay2Api = new Pay2Api(weixinAccount);
|
||||||
}
|
this.pay3Api = new Pay3Api(weixinAccount);
|
||||||
|
int version = weixinAccount.getVersion();
|
||||||
/**
|
|
||||||
* TokenHolder对象
|
|
||||||
*
|
|
||||||
* @param tokenHolder
|
|
||||||
*/
|
|
||||||
public WeixinPayProxy(TokenHolder tokenHolder) {
|
|
||||||
this.pay2Api = new Pay2Api(tokenHolder);
|
|
||||||
this.pay3Api = new Pay3Api(tokenHolder);
|
|
||||||
int version = ((WeixinMpAccount) tokenHolder.getAccount()).getVersion();
|
|
||||||
if (version == 2) {
|
if (version == 2) {
|
||||||
this.payApi = this.pay2Api;
|
this.payApi = this.pay2Api;
|
||||||
} else if (version == 3) {
|
} else if (version == 3) {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import com.foxinmy.weixin4j.msg.model.MpArticle;
|
|||||||
import com.foxinmy.weixin4j.msg.model.Video;
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.WeixinTokenCreator;
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public class WeixinProxy {
|
|||||||
* 默认采用文件存放Token信息
|
* 默认采用文件存放Token信息
|
||||||
*/
|
*/
|
||||||
public WeixinProxy() {
|
public WeixinProxy() {
|
||||||
this(new FileTokenHolder(AccountType.MP));
|
this(new FileTokenHolder(new WeixinTokenCreator(AccountType.MP)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +88,7 @@ public class WeixinProxy {
|
|||||||
* 微信账户
|
* 微信账户
|
||||||
*/
|
*/
|
||||||
public WeixinProxy(WeixinMpAccount weixinAccount) {
|
public WeixinProxy(WeixinMpAccount weixinAccount) {
|
||||||
this(new FileTokenHolder(weixinAccount));
|
this(new FileTokenHolder(new WeixinTokenCreator(weixinAccount)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -544,8 +545,9 @@ public class WeixinProxy {
|
|||||||
* @see com.foxinmy.weixin4j.mp.model.OauthToken
|
* @see com.foxinmy.weixin4j.mp.model.OauthToken
|
||||||
* @see com.foxinmy.weixin4j.mp.api.UserApi
|
* @see com.foxinmy.weixin4j.mp.api.UserApi
|
||||||
*/
|
*/
|
||||||
public OauthToken getOauthToken(String code) throws WeixinException {
|
public OauthToken getOauthToken(String code, String appid, String appsecret)
|
||||||
return userApi.getOauthToken(code);
|
throws WeixinException {
|
||||||
|
return userApi.getOauthToken(code, appid, appsecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import com.alibaba.fastjson.TypeReference;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
|
||||||
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
@ -33,7 +32,8 @@ public class HelperApi extends MpApi {
|
|||||||
/**
|
/**
|
||||||
* 长链接转短链接
|
* 长链接转短链接
|
||||||
*
|
*
|
||||||
* @param url 待转换的链接
|
* @param url
|
||||||
|
* 待转换的链接
|
||||||
* @return 短链接
|
* @return 短链接
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
@ -65,10 +65,8 @@ public class HelperApi extends MpApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public SemResult semantic(SemQuery semQuery) throws WeixinException {
|
public SemResult semantic(SemQuery semQuery) throws WeixinException {
|
||||||
WeixinMpAccount weixinAccount = (WeixinMpAccount) tokenHolder.getAccount();
|
|
||||||
String semantic_uri = getRequestUri("semantic_uri");
|
String semantic_uri = getRequestUri("semantic_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
semQuery.appid(weixinAccount.getId());
|
|
||||||
Response response = request.post(
|
Response response = request.post(
|
||||||
String.format(semantic_uri, token.getAccessToken()),
|
String.format(semantic_uri, token.getAccessToken()),
|
||||||
semQuery.toJson());
|
semQuery.toJson());
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||||
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
|
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
|
||||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||||
@ -48,7 +49,6 @@ import com.foxinmy.weixin4j.mp.type.IdQuery;
|
|||||||
import com.foxinmy.weixin4j.mp.type.RefundType;
|
import com.foxinmy.weixin4j.mp.type.RefundType;
|
||||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||||
import com.foxinmy.weixin4j.mp.util.ExcelUtil;
|
import com.foxinmy.weixin4j.mp.util.ExcelUtil;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
import com.foxinmy.weixin4j.util.DateUtil;
|
import com.foxinmy.weixin4j.util.DateUtil;
|
||||||
import com.foxinmy.weixin4j.util.MapUtil;
|
import com.foxinmy.weixin4j.util.MapUtil;
|
||||||
@ -66,8 +66,8 @@ public class Pay2Api extends PayApi {
|
|||||||
|
|
||||||
private final HelperApi helperApi;
|
private final HelperApi helperApi;
|
||||||
|
|
||||||
public Pay2Api(TokenHolder tokenHolder) {
|
public Pay2Api(WeixinMpAccount weixinAccount) {
|
||||||
super(tokenHolder);
|
super(weixinAccount);
|
||||||
this.helperApi = new HelperApi(tokenHolder);
|
this.helperApi = new HelperApi(tokenHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ public class Pay2Api extends PayApi {
|
|||||||
}
|
}
|
||||||
String sign = PayUtil
|
String sign = PayUtil
|
||||||
.paysignMd5(map, weixinAccount.getPartnerKey());
|
.paysignMd5(map, weixinAccount.getPartnerKey());
|
||||||
map.put("sign", sign.toLowerCase());
|
map.put("sign", sign.toUpperCase());
|
||||||
|
|
||||||
SSLContext ctx = null;
|
SSLContext ctx = null;
|
||||||
KeyStore ks = null;
|
KeyStore ks = null;
|
||||||
@ -232,6 +232,7 @@ public class Pay2Api extends PayApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.err.println(response.getAsString());
|
||||||
return response.getAsObject(new TypeReference<RefundResult>() {
|
return response.getAsObject(new TypeReference<RefundResult>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
||||||
import com.foxinmy.weixin4j.http.XmlResult;
|
import com.foxinmy.weixin4j.http.XmlResult;
|
||||||
|
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||||
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
|
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
|
||||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||||
@ -38,7 +39,6 @@ import com.foxinmy.weixin4j.mp.type.BillType;
|
|||||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||||
import com.foxinmy.weixin4j.mp.type.IdType;
|
import com.foxinmy.weixin4j.mp.type.IdType;
|
||||||
import com.foxinmy.weixin4j.mp.util.ExcelUtil;
|
import com.foxinmy.weixin4j.mp.util.ExcelUtil;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
import com.foxinmy.weixin4j.util.DateUtil;
|
import com.foxinmy.weixin4j.util.DateUtil;
|
||||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||||
@ -54,8 +54,8 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
|||||||
*/
|
*/
|
||||||
public class Pay3Api extends PayApi {
|
public class Pay3Api extends PayApi {
|
||||||
|
|
||||||
public Pay3Api(TokenHolder tokenHolder) {
|
public Pay3Api(WeixinMpAccount weixinAccount) {
|
||||||
super(tokenHolder);
|
super(weixinAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,7 +16,9 @@ import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
|||||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||||
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.WeixinTokenCreator;
|
||||||
import com.foxinmy.weixin4j.util.DateUtil;
|
import com.foxinmy.weixin4j.util.DateUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,12 +32,13 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
|||||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||||
*/
|
*/
|
||||||
public abstract class PayApi extends MpApi {
|
public abstract class PayApi extends MpApi {
|
||||||
|
|
||||||
protected final TokenHolder tokenHolder;
|
protected final TokenHolder tokenHolder;
|
||||||
protected final WeixinMpAccount weixinAccount;
|
protected final WeixinMpAccount weixinAccount;
|
||||||
|
public PayApi(WeixinMpAccount weixinAccount) {
|
||||||
public PayApi(TokenHolder tokenHolder) {
|
this.weixinAccount = weixinAccount;
|
||||||
this.tokenHolder = tokenHolder;
|
this.tokenHolder = new FileTokenHolder(new WeixinTokenCreator(
|
||||||
this.weixinAccount = (WeixinMpAccount) tokenHolder.getAccount();
|
weixinAccount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
|
||||||
import com.foxinmy.weixin4j.mp.model.Following;
|
import com.foxinmy.weixin4j.mp.model.Following;
|
||||||
import com.foxinmy.weixin4j.mp.model.OauthToken;
|
import com.foxinmy.weixin4j.mp.model.OauthToken;
|
||||||
import com.foxinmy.weixin4j.mp.model.User;
|
import com.foxinmy.weixin4j.mp.model.User;
|
||||||
@ -39,17 +38,19 @@ public class UserApi extends MpApi {
|
|||||||
*
|
*
|
||||||
* @param code
|
* @param code
|
||||||
* 用户授权后返回的code
|
* 用户授权后返回的code
|
||||||
|
* @param appid
|
||||||
|
* @param appsecret
|
||||||
* @return token对象
|
* @return token对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html">获取用户token</a>
|
* href="http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html">获取用户token</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.OauthToken
|
* @see com.foxinmy.weixin4j.mp.model.OauthToken
|
||||||
*/
|
*/
|
||||||
public OauthToken getOauthToken(String code) throws WeixinException {
|
public OauthToken getOauthToken(String code, String appid, String appsecret)
|
||||||
WeixinAccount weixinAccount = tokenHolder.getAccount();
|
throws WeixinException {
|
||||||
String user_token_uri = getRequestUri("sns_user_token_uri");
|
String user_token_uri = getRequestUri("sns_user_token_uri");
|
||||||
Response response = request.get(String.format(user_token_uri,
|
Response response = request.get(String.format(user_token_uri, appid,
|
||||||
weixinAccount.getId(), weixinAccount.getSecret(), code));
|
appsecret, code));
|
||||||
|
|
||||||
return response.getAsObject(new TypeReference<OauthToken>() {
|
return response.getAsObject(new TypeReference<OauthToken>() {
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,4 +20,4 @@ bill_path=/tmp/weixin/bill
|
|||||||
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84 (V2\u7248\u672c\u540e\u7f00\u4e3a*.pfx,V3\u7248\u672c\u540e\u7f00\u4e3a*.p12)
|
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84 (V2\u7248\u672c\u540e\u7f00\u4e3a*.pfx,V3\u7248\u672c\u540e\u7f00\u4e3a*.p12)
|
||||||
ca_file=/tmp/weixin/xxxxx.p12
|
ca_file=/tmp/weixin/xxxxx.p12
|
||||||
# classpath\u8def\u5f84\u4e0b\u53ef\u4ee5\u8fd9\u4e48\u5199
|
# classpath\u8def\u5f84\u4e0b\u53ef\u4ee5\u8fd9\u4e48\u5199
|
||||||
ca_file=classpath:xxxxx.pfx
|
# ca_file=classpath:xxxxx.pfx
|
||||||
@ -7,6 +7,7 @@ import org.junit.Test;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.WeixinTokenCreator;
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +24,7 @@ public class TokenTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
tokenHolder = new FileTokenHolder(AccountType.MP);
|
tokenHolder = new FileTokenHolder(new WeixinTokenCreator(AccountType.MP));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -16,5 +16,7 @@ qr_path=/tmp/weixin/qr
|
|||||||
media_path=/tmp/weixin/media
|
media_path=/tmp/weixin/media
|
||||||
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84
|
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84
|
||||||
bill_path=/tmp/weixin/bill
|
bill_path=/tmp/weixin/bill
|
||||||
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84
|
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84 (V2\u7248\u672c\u540e\u7f00\u4e3a*.pfx,V3\u7248\u672c\u540e\u7f00\u4e3a*.p12)
|
||||||
ca_file=/tmp/weixin/xxxxx.p12 | xxxxx.pfx
|
ca_file=/tmp/weixin/xxxxx.p12
|
||||||
|
# classpath\u8def\u5f84\u4e0b\u53ef\u4ee5\u8fd9\u4e48\u5199
|
||||||
|
# ca_file=classpath:xxxxx.pfx
|
||||||
@ -15,6 +15,7 @@ import com.foxinmy.weixin4j.qy.model.User;
|
|||||||
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.WeixinTokenCreator;
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +37,7 @@ public class WeixinProxy {
|
|||||||
* 默认采用文件存放Token信息
|
* 默认采用文件存放Token信息
|
||||||
*/
|
*/
|
||||||
public WeixinProxy() {
|
public WeixinProxy() {
|
||||||
this(new FileTokenHolder(AccountType.QY));
|
this(new FileTokenHolder(new WeixinTokenCreator(AccountType.QY)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +56,7 @@ public class WeixinProxy {
|
|||||||
* @param weixinAccount
|
* @param weixinAccount
|
||||||
*/
|
*/
|
||||||
public WeixinProxy(WeixinQyAccount weixinAccount) {
|
public WeixinProxy(WeixinQyAccount weixinAccount) {
|
||||||
this(new FileTokenHolder(weixinAccount));
|
this(new FileTokenHolder(new WeixinTokenCreator(weixinAccount)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import org.junit.Test;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.WeixinTokenCreator;
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +24,8 @@ public class TokenTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
tokenHolder = new FileTokenHolder(AccountType.QY);
|
tokenHolder = new FileTokenHolder(
|
||||||
|
new WeixinTokenCreator(AccountType.QY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user