package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.service.ICorpWeixinService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.impl.WxCpOAuth2ServiceImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CorpWeixinServiceImpl implements ICorpWeixinService {
/*    public static void main(String[] args) {
        val configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId("ww24b8a47826f5875f");
        configStorage.setAgentId(1000017);
        configStorage.setCorpSecret("jkFkOtUZPc6WVnh6lth_fUIMXSDzFcaK8tdTQ9MGbtc");
        configStorage.setToken("hcst2019");
        configStorage.setAesKey("hcst2019");
        val service = new WxCpServiceImpl();

        service.setWxCpConfigStorage(configStorage);
        WxCpOAuth2Service wxCpOAuth2Service = new WxCpOAuth2ServiceImpl(service);
        try {
            WxCpMessage message = new WxCpMessage();
            message.setToUser("YuMeng");
            message.setAgentId(1000017);
            message.setContent("测试消息");
            message.setMsgType("text");
            service.messageSend(message);
//            service.post("https://qyapi.weixin.qq.com/cgi-bin/message/send","touser=YiErSanSi&content=123&agentid=1000002&msgtype=text");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }*/


    public static void main(String[] args) {
        val configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId("ww24b8a47826f5875f");
        configStorage.setAgentId(1000004);
        configStorage.setCorpSecret("1YWGDtuZWrQDl6US3OPHG8_pvuNgP1TeUsOmfRk6GmQ");
       /* configStorage.setToken("hcst2019");
        configStorage.setAesKey("hcst2019");*/
        val service = new WxCpServiceImpl();

        service.setWxCpConfigStorage(configStorage);
        WxCpOAuth2Service wxCpOAuth2Service = new WxCpOAuth2ServiceImpl(service);
        try {
            WxCpMessage message = new WxCpMessage();
            message.setToUser("YuMeng");
            message.setAgentId(1000004);
            message.setContent("测试消息");
            message.setMsgType("text");
            service.messageSend(message);
//            service.post("https://qyapi.weixin.qq.com/cgi-bin/message/send","touser=YiErSanSi&content=123&agentid=1000002&msgtype=text");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
