package cn.pluss.platform.wx;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 *
 *封装微信模板消息
 *@author: bzg
 *@time: 2021/11/29 18:05
 */
@Data
public class WxTemolateRequest {



    public static String color = "#1E4FF5";
    /**
     * 用户openid
     * @date: 2021/11/29 18:16
     */
    private String touser;

    /**
     * 模板id
     * @date: 2021/11/29 18:16
     */
    private String template_id;

    /**
     * url
     * @date: 2021/11/29 18:16
     */
    private String url;

    /**
     * miniprogram 小程序参数
     * @date: 2021/11/29 18:16
     */
    private JSONObject miniprogram;

    /**
     * 数据体
     * @date: 2021/11/29 18:17
     */
    private JSONObject data;


    public WxTemolateRequest(String touser, String template_id, String url, JSONObject miniprogram) {
        this.touser = touser;
        this.template_id = template_id;
        this.url = url;
        this.miniprogram = miniprogram;
    }

    /**
     * @description:组装template参数
     * @date: 2021/12/9 14:39
     * @param first:
     * @param remark:
     * @param array:
     * @return cn.pluss.platform.wx.WxTemolateRequest
     */
    public WxTemolateRequest buildData(String first,String remark,String[] array){
        JSONObject data = new JSONObject(10);
        JSONObject firstData = new JSONObject(2);
        firstData.put("value",first);
        firstData.put("color",color);
        JSONObject remarkData = new JSONObject(2);
        remarkData.put("value",remark);
        remarkData.put("color",color);

        data.put("first",firstData);
        data.put("remark",remarkData);

        for (int i = 0; i < array.length; i++) {
            JSONObject keyword = new JSONObject(2);
            keyword.put("value",array[i]);
            keyword.put("color",color);
            data.put("keyword"+(i+1),keyword);
        }
        this.data = data;
        return this;
    }
}
