1.生成token是一个spring控制器
基于项目和项目之间的调用秘钥生成之后放redis,两小时后失效
package com.csair.openapi.controller.basic;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.csair.openapi.basic.annotation.WEBApi;
import com.csair.openapi.qo.sub.TokenCredential;
import com.csair.openapi.vo.sub.TokenSuccess;
@RestController
@RequestMapping("/credential")
public class TokenCredentialController {
@Autowired
private RedisTemplate<String, String> redisTemplate;
private Map<String, String> key = new HashMap<String, String>();
@PostConstruct
public void init() {
key.put("lps", "lrKvmMg3h9c8UQsvzDn0S4X");
}
@RequestMapping(value = "/getToken")
@ResponseBody
@WEBApi
public Object export(HttpServletRequest request,HttpServletResponse response,@RequestBody TokenCredential limitsAuthority) throws Exception {
TokenSuccess tokenSuccess = new TokenSuccess();
if (limitsAuthority!=null&&limitsAuthority.getAppid()!=null&&limitsAuthority.getSecret()!=null) {//校验用户是否有权限
String appid= limitsAuthority.getAppid();
String secretPass =(String) key.get(appid);
String secret = limitsAuthority.getSecret();
if (secret.equals(secretPass)) {
String Timestamp= System.currentTimeMillis()+"";
String token = md5Password(appid+s