import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class QWmediaTest {

    private static Logger logger = LoggerFactory.getLogger(QWmediaTest.class);
    @Autowired
    private QywxSuiteApiService qywxSuiteApiService ;
    @Autowired
    private WxEnterpriseService wxEnterpriseService;

    private static final String LARGE_IMAGE_URL = "https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4582434f589b494aa4f27df6e3aa3770.png?imageView2/2/w/1080/h/10800/format/jpg";
    private static final String QR_CODE_URL = "https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png";
    private static final String STORE_NAME = "门店CCA";
    private static final String GUIDE_NAME = "宇智222";

    @Test
    public void test() throws Exception{
        WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo("b18ffdc9d0644912865a248859914d80") ;
        CombinedQDTO combinedQDTO = new CombinedQDTO();
        combinedQDTO.setImageUrl(LARGE_IMAGE_URL);
        combinedQDTO.setQrCodeUrl(QR_CODE_URL);
        combinedQDTO.setShowStyle(1);
        combinedQDTO.setLineOne(STORE_NAME);
        combinedQDTO.setLineTwo(GUIDE_NAME);
        String[] arr = null ;
        byte[] combinedImageData = ImageCombined.getCombinedImage(combinedQDTO);
        // 将 BufferedImage 写入 ByteArrayOutputStream
        if(LARGE_IMAGE_URL.contains("?")) {
            arr = LARGE_IMAGE_URL.split("\\?")[0].split("/") ;
        }else {
            arr = LARGE_IMAGE_URL.split("/");
        }
//        JSONResponse test = qywxSuiteApiService.uploadAttachment(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), combinedImageData, arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode(), qwDTO.isSelf(), qwDTO.getUrlHost());
//        System.out.println(JSON.toJSONString(test));

    }

}
