AccessTokenServlet.java 838 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
package com.lyms.talkonlineweb.task;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

@Component
public class AccessTokenServlet extends HttpServlet {
final String appId ="wxd3c36244d006cb90";//公众号appid
final String appSecret ="fc80b5dd03a581a088adcd2c65a7e10a";//公众号AppSecret

/**
* 启动后开启线程每1小时59获取一次token,保证长期有效。(微信公众号规定2小时token失效,每天只能获取2000次。)
* @throws ServletException
*/
@PostConstruct
public void init() throws ServletException {
TokenThread.appId = appId;
TokenThread.appSecret = appSecret;
new Thread(new TokenThread()).start(); //启动进程
}
}