package com.iamberry.wechat.test;

import com.iamberry.wechat.core.entity.wx.QRCJson;
import com.iamberry.wechat.file.FileUtils;
import com.iamberry.wechat.tools.*;
import com.iamberry.wechat.utils.DownloadWXCodeUtil;

import java.awt.*;
import java.util.Date;

public class Test {

    public static void main(String[] args) {

        //生成机器二维码
//        String json = String.format(NameUtils.QR_SCENE_STR, 2592000, ResultInfo.barCodeActivity + "oZ9pv02WMRQgyDVRY1a_daYecwHI");
//        QRCJson qrc = WeixinUtil.createQrcode(json);
//
//        if(true){
//            return;
//        }
        long start = new Date().getTime();

        long x = new Date().getTime();
        String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEb8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyMVF4SHRiX2ZkaWgxa19aMDFyMU0AAgQ-8BhbAwQAjScA";
        String headUrl = "http://thirdwx.qlogo.cn/mmopen/Q3auHgzwzM5DPUwVaYlrN50M0vLJP3eNflBicuBCGdADmKJuZsf5Og1NxCc9FicibsWzrxZWtMibpdFviaItufuJK71C7kbKd2myN6FV7fYckCzA/0";
//        String headUrl = "http://wx.qlogo.cn/mmopen/acXuSfhaRb50M9xJOAOBTa8wlFGSJyasFtibIv6YbRgvPFmYBtMzj4CO1hUmibkUGtNZlHSxIf76LSoHo7nfVR92V1VXFib3XFu/0";
        try {
            DownloadWXCodeUtil.downloadByNIO2(url,"ceshi.png","E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test\\",PosterNumUtils.CODE_WIDTH,PosterNumUtils.CODE_HEIGHT,false);
            DownloadWXCodeUtil.downloadByNIO2(headUrl,"head.png","E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test\\",PosterNumUtils.HEAD_WIDTH,PosterNumUtils.HEAD_HEIGHT,false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long y = new Date().getTime();

        String oldImg = "E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\ditu.jpg";

        String newPath = "E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test";
        String headImg = "E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test\\head.png";
        String newCodeImg = "E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test\\ceshi.png";
        String newImg = "E:\\java-work\\iamberry-tooth\\tooth-wechat-web\\src\\main\\webapp\\common\\images\\activity\\test\\ditu.jpg";

        String text = "小茗同学";

        long m = new Date().getTime();
        /*复制海报*/
        FileUtils.copyFile(oldImg,newImg);
        try{
            /*添加文字*/
            ImageUtils.pressPost(newImg,
                headImg,PosterNumUtils.HEAD_X,PosterNumUtils.HEAD_Y,
                newCodeImg,PosterNumUtils.CODE_X,PosterNumUtils.CODE_Y,
                text,PosterNumUtils.TEXT_X,PosterNumUtils.TEXT_Y,new Color(129,129,129),PosterNumUtils.TEXT_FONT_SIZE
            );
        }catch (Exception e){
            e.printStackTrace();
        }
//        ImageUtils.pressImage(newImg,headImg,PosterNumUtils.HEAD_X,PosterNumUtils.HEAD_Y,1);
//        ImageUtils.pressImage(newImg,newCodeImg,PosterNumUtils.CODE_X,PosterNumUtils.CODE_Y,1);
//        ImageUtils.pressText(newImg,text,PosterNumUtils.TEXT_X,PosterNumUtils.TEXT_Y,Color.black,PosterNumUtils.TEXT_FONT_SIZE);
        long n = new Date().getTime();

        long end = new Date().getTime();
        System.out.println("下载："+ (y-x));
        System.out.println("添加水印："+ (n-m));
        System.out.println("生成时间为："+ (end-start));
    }

}
