package com.ssj.api.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ssj.api.security.annotation.IgnoreSecurity;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.security.manager.TokenManager;
import com.ssj.framework.core.util.ResponseConstant;
import com.ssj.framework.core.util.ResponseEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "微信相关的", tags = "微信相关的")
@RestController
@RequestMapping("/open/api/wx")
public class ApiWxController extends BaseController {
	
	@Autowired
	private TokenManager tokenManager;
	
	@IgnoreSecurity
	@RequestMapping(value = "/accessToken")
    @ApiOperation(value = "获取accessToken接口",  notes = "获取accessToken接口")
    public ResponseEntity getAccessToken() {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
        	Map<String, Object> data =tokenManager.getSSJAccessTokenAndTime();
            responseEntity.success(data, "获取accessToken成功");
        } catch (Exception e) {
            logger.error("获取accessToken接口", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }
	
	
	@IgnoreSecurity
	@RequestMapping(value = "/jsAccessToken")
    @ApiOperation(value = "获取jsAccessToken接口",  notes = "获取jsAccessToken接口")
    public ResponseEntity getJSAccessToken() {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
        	Map<String, Object> data =tokenManager.getSSJJSAccessTokenAndTime();
            responseEntity.success(data, "获取accessToken成功");
        } catch (Exception e) {
            logger.error("获取accessToken接口", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }
	
	
}
