主题 : jeecmsv7 定时任务中 获取微信token失败的问题
级别: 解元
UID: 92205
积分:282 加为好友
威望: 13 精华: 0
主题:30 回复:134
注册时间:2016-09-03
在线时长:0
1#   发表于:2016-12-16 15:26:09  IP:124.192.*.*
任务类中  继承了 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;
}
}
         
级别: 版主
UID: 70293
积分:78391 加为好友
威望: 1 精华: 0
主题:7 回复:68397
注册时间:2014-12-03
在线时长:0
2#   发表于:2016-12-16 15:26:37  IP:117.125.*.*
抱歉,论坛不提供二次开发方面的服务
1
1 共1页