QyAttachmentTest.java 4.54 KB
package cn.com.glsx.entmicro.service;

import cn.com.glsx.entmicro.constants.DracConstant;
import cn.com.glsx.entmicro.request.one.template.QyAttachmentVo;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangxw
 * @version 1.0.0
 * @ClassName QyAttachmentTest.java
 * @description: ${description}
 * @createTime 2021年11月13日 16:04:00
 */
public class QyAttachmentTest {

    /*
        public static final Integer TEXT = 1;
        public static final Integer IMAGE = 2;
        public static final Integer VEDIO = 3;
        public static final Integer URI = 4;
        public static final Integer MINIPROGRAM = 5;
        public static final Integer FILE = 6;

        public static final String TEXT = "text";
        public static final String IMAGE = "image";
        public static final String VEDIO = "video";
        public static final String URI = "link";
        public static final String MINIPROGRAM = "miniprogram";
        public static final String FILE = "file";
     */
    @Test
    public void testQyAttachment() {
        QyAttachmentVo textAtt = initTextAttachment();
        QyAttachmentVo imageAtt = initImageAttachment();
        QyAttachmentVo videoAtt = initVideoAttachment();
        QyAttachmentVo linkAtt = initLinkAttachment();
        QyAttachmentVo miniAtt = initMiniAttachment();
        QyAttachmentVo fileAtt = initFileAttachment();

        List<QyAttachmentVo> attList = new ArrayList<>();
        attList.add(textAtt);
        attList.add(imageAtt);
        attList.add(videoAtt);
        attList.add(linkAtt);
        attList.add(miniAtt);
        attList.add(fileAtt);
        System.out.println("==" + JSONObject.toJSONString(attList).replace("\\", "").replace("\"{", "{").replace("}\"", "}"));
    }

    private QyAttachmentVo initTextAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.TEXT);
        att.setAttContent("欢迎加我为好友");
        return att;
    }

    private QyAttachmentVo initImageAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.IMAGE);
        att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
        return att;
    }

    private QyAttachmentVo initVideoAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.VEDIO);
        att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
        return att;
    }

    private QyAttachmentVo initLinkAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.URI);
        att.setAttContent("{\"title\": \"消息标题\",\"url\": \"https://example.link.com/path\"}");
        return att;
    }

    private QyAttachmentVo initMiniAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.MINIPROGRAM);
        att.setAttContent("{\"title\": \"消息标题\",\"pic_url\": \"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"appid\": \"wx8bd80126147dfAAA\",\"page\": \"/path/index.html\"}");
        return att;
    }

    private QyAttachmentVo initFileAttachment() {
        QyAttachmentVo att = new QyAttachmentVo();
        att.setAttType(DracConstant.AttType.FILE);
        att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
        return att;
    }

    @Test
    public void testParseAttJson() {
        String base = "[{\"attContent\":\"欢迎加我为好友\",\"attType\":1},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":2},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":3},{\"attContent\":{\"title\": \"消息标题\",\"url\": \"https://example.link.com/path\"},\"attType\":4},{\"attContent\":{\"title\": \"消息标题\",\"pic_url\": \"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"appid\": \"wx8bd80126147dfAAA\",\"page\": \"/path/index.html\"},\"attType\":5},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":6}]";
        List<QyAttachmentVo> attachmentVoList = JSONObject.parseArray(base, QyAttachmentVo.class);
        System.out.println("==" + JSONObject.toJSONString(attachmentVoList));
    }
}