我在使用的时候,调用的WxApi2 getWxApi2没有拿到access_token,
然后我里看到有人用这个@SetupBy,我就放到了前面就能正常获取到了,但是我怕access_token过期,和重复掉去交换access_token,
有时候,不知道怎么的一段时间access_token就是拿到了,这个是为什么?
@IocBean(args = {"refer:dao"})
@SetupBy
public class WxConfigService extends Service<Wx_config> {
public WxConfigService(Dao dao) {
super(dao);
}
public WxApi2 getWxApi2(String wxid) {
Wx_config appInfo = this.fetch(Cnd.where("id", "=", wxid));
DaoAccessTokenStore myDaoAccessTokenStore = new DaoAccessTokenStore(dao());
Map<String, Object> params = new HashMap<>();
params.put("id", appInfo.getId());
myDaoAccessTokenStore.setTableAccessToken("access_token");
myDaoAccessTokenStore.setTableAccessTokenExpires("access_token_expires");
myDaoAccessTokenStore.setTableAccessTokenLastat("access_token_lastat");
myDaoAccessTokenStore.setFetch("select access_token,access_token_expires,access_token_lastat from wx_config where id=@id");
myDaoAccessTokenStore.setUpdate("update wx_config set access_token=@access_token, access_token_expires=@access_token_expires, access_token_lastat=@access_token_lastat where id=@id");
myDaoAccessTokenStore.setParams(params);
WxApi2Impl wxApi2 = new WxApi2Impl();
wxApi2.setAppid(appInfo.getAppid());
wxApi2.setAppsecret(appInfo.getAppsecret());
wxApi2.setEncodingAesKey(appInfo.getEncodingAESKey());
wxApi2.setToken(appInfo.getToken());
wxApi2.setAccessTokenStore(myDaoAccessTokenStore);
return wxApi2;
}
}