package com.bcxin.ins.weixin.util.weixin.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.bcxin.ins.weixin.util.weixin.service.WeiXinService;
import com.bcxin.ins.weixin.util.weixin.util.AccessToken;
import com.bcxin.ins.weixin.util.weixin.util.ConstantWeiXin;
import com.bcxin.ins.weixin.util.weixin.util.WeixinUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 微信业务处理
 * 2017-8-16
 */
@Service
@Transactional
public class WeiXinServiceImpl implements WeiXinService {


    public static Logger logger = LoggerFactory.getLogger(WeiXinServiceImpl.class);



    @Override
    public AccessToken getAccessToken() {
        String url = ConstantWeiXin.GET_TOKEN.replace("CORPID", ConstantWeiXin.CORPID).replace("SECRET", ConstantWeiXin.SECRET);
        JSONObject json = WeixinUtil.httpRequest(url, "GET", null);
        AccessToken accessToken = null;
        if (json != null) {
            logger.info("获取getAccessToken" + json.toString());
            accessToken = new AccessToken();
            accessToken.setToken(json.getString("access_token"));
            accessToken.setExpiresIn(json.getInteger("expires_in"));
            return accessToken;
        }
        return null;
    }


}
