package com.kiisoo.ic.wx.service;

import com.kiisoo.ic.common.utils.WeixinApi;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author dexiang.jiang
 * @date 2020/03/11 15:29
 */
@Service
public class WxAccessService {

    public static String WX_TOKEN_REDIS = "qy_wx_token";

    public static String WX_TICKET_REDIS = "qy_wx_ticket";

    /**
     * 获取微信token
     *
     * @return 返回token令牌
     * @author dexiang.jiang
     * @date 2020/03/11 15:29
     */
    public synchronized String getToken() throws IOException {
//        if (RedisClient.exists(WX_TOKEN_REDIS)) {
//            return RedisClient.get(WX_TOKEN_REDIS);
//        }

        String token = WeixinApi.readToken();
//        RedisClient.set(WX_TOKEN_REDIS, token, "NX", "EX", 7000L);
        return token;
    }

    /**
     * 获取ticket 凭证
     *
     * @return 返回凭证
     * @author dexiang.jiang
     * @date 2020/03/11 15:29
     */
    public String getTicket() throws IOException {
//        if (RedisClient.exists(WX_TICKET_REDIS)) {
//            return RedisClient.get(WX_TICKET_REDIS);
//        }

        String ticket = WeixinApi.getJsTicketByFile();
//        RedisClient.set(WX_TICKET_REDIS, ticket, "NX", "EX", 3600L);
        return ticket;
    }
}
