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.context.annotation.Primary;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@Primary
public class CorpWeixinServiceImpl implements ICorpWeixinService {
    public static void main(String[] args) {
        val configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId("ww24b8a47826f5875f");
        configStorage.setAgentId(1000002);
        configStorage.setCorpSecret("MJIlySADGPlgvADnkFQPUpfZD4yV-4WN6066OgNnb0s");
        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("YiErSanSi");
            message.setAgentId(1000002);
            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();
        }

    }

}
