添加WeixinAccount为参数的构造函数
This commit is contained in:
parent
52f485fa17
commit
1371d1d5c7
@ -55,16 +55,18 @@ weixin.properties说明
|
||||
> bill_path=/tmp/weixin/bill <br/>
|
||||
> ca_file=/tmp/weixin/xxxxx.p12 <br/>
|
||||
|
||||
2.实例化一个`WeixinProxy`对象,调用API.
|
||||
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口
|
||||
|
||||
WeixinProxy weixinProxy = new WeixinProxy();
|
||||
// weixinProxy = new WeixinProxy(appid,appsecret);
|
||||
// weixinProxy = new WeixinProxy(weixinAccount);
|
||||
weixinProxy.getUser(openId);
|
||||
|
||||
3.针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`(继承`AbstractTokenHolder`并重写`getToken`方法),默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用`RedisTokenHolder`.
|
||||
|
||||
WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenHolder());
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenHolder(appid,appsecret));
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenHolder(weixinAccount));
|
||||
|
||||
4.`mvn package`.
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ import com.foxinmy.weixin4j.type.MediaType;
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php">api文档</a>
|
||||
*/
|
||||
public class WeixinProxy {
|
||||
|
||||
private final MediaApi mediaApi;
|
||||
private final NotifyApi notifyApi;
|
||||
private final MassApi massApi;
|
||||
@ -64,14 +65,15 @@ public class WeixinProxy {
|
||||
private final PayApi payApi;
|
||||
|
||||
/**
|
||||
* 默认采用文件存放Token跟配置文件中的appi信息
|
||||
* 默认采用文件存放Token信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(new FileTokenHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* 也可接受传递过来的appid跟appsecret
|
||||
* appid,appsecret<br/>
|
||||
* <font color="red">将无法调用支付相关接口</font>
|
||||
*
|
||||
* @param appid
|
||||
* @param appsecret
|
||||
@ -80,6 +82,20 @@ public class WeixinProxy {
|
||||
this(new FileTokenHolder(appid, appsecret));
|
||||
}
|
||||
|
||||
/**
|
||||
* WeixinAccount对象
|
||||
*
|
||||
* @param weixinAccount
|
||||
*/
|
||||
public WeixinProxy(WeixinAccount weixinAccount) {
|
||||
this(new FileTokenHolder(weixinAccount));
|
||||
}
|
||||
|
||||
/**
|
||||
* TokenHolder对象
|
||||
*
|
||||
* @param tokenHolder
|
||||
*/
|
||||
public WeixinProxy(TokenHolder tokenHolder) {
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.notifyApi = new NotifyApi(tokenHolder);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user