package com.ematou.wxservice.wechatservice;

import com.ematou.wxservice.config.WeChatGeneralConfig;
import com.ematou.wxservice.entity.vo.AccessToken;
import com.ematou.wxservice.mp.menu.MenuButtonManager;
import com.ematou.wxservice.service.WeChatService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@SpringBootTest
class WechatserviceApplicationTests {

    private static final Logger logger = LoggerFactory.getLogger(WechatserviceApplicationTests.class);

    private static String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";

    @Autowired
    WeChatGeneralConfig weChatGeneralConfig;

    @Autowired
    RestTemplate restTemplate;

    @Test
    void contextLoads() {

        // 调用接口获取access_token
        Map map = restTemplate.getForObject(String.format(getAccessTokenUrl, weChatGeneralConfig.getAppId(), weChatGeneralConfig.getAppSecret()), Map.class);

        System.out.println(map);



    }


    @Autowired
    WeChatService weChatService;

    @Test
    void testGetGlobalAccessToken(){
        AccessToken accessToken = weChatService.getAccessToken();
        System.out.println(accessToken);
    }

    @Autowired
    MenuButtonManager manager;

    @Test
    void testCreateMenu() throws InterruptedException {

        manager.init();

    }

}
