任务类中 继承了 QuartzJobBean
方法:
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
SchedulerContext schCtx = context.getScheduler().getContext();
// 获取Spring中的上下文
ApplicationContext appCtx = (ApplicationContext) schCtx.get("applicationContext");
this.weixinSvc = (WeiXinSvc) appCtx.getBean("weiXinSvc");
// 这里是调用平台获取token的方法
String access_token = weixinSvc.getToken();
//这里是impl
public String getToken() {
String tokenGetUrl=PropertyUtils.getPropertyValue(new File(realPathResolver.get(Constants.JEECMS_CONFIG)),TOKEN_KEY);
String appid="";
String secret="";
CmsSite site=CmsThreadVariable.getSite();
if(site!=null){
appid=site.getAttr().get(com.jeecms.core.Constants.WEIXIN_APPKEY);
secret=site.getAttr().get(com.jeecms.core.Constants.WEIXIN_APPSECRET);
}
//这里只输出 ====
log.error(appid+" ===="+secret);
JSONObject tokenJson=new JSONObject();
if(StringUtils.isNotBlank(appid)&&StringUtils.isNotBlank(secret)){
tokenGetUrl+="&appid="+appid+"&secret="+secret;
tokenJson=getUrlResponse(tokenGetUrl);
try {
return (String) tokenJson.get("access_token");
} catch (JSONException e) {
log.error("获取微信token失败");
return null;
}
}else{
return null;
}
}
|
|