package com.palmnest.application.core.util;

import java.io.IOException;
import java.util.Date;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.alibaba.fastjson.JSONObject;

public class SupperAppMessageUtil {


	static void start() {

		JSONObject mainJson = new JSONObject();

		mainJson.put("FromSys", "WCF");//应用编号
		mainJson.put("MsgType", "IM.MSG");//发送消息类型
		mainJson.put("Sender", "jibo");//发送者帐号
		mainJson.put("SendName", "季波");//发送者名称
		mainJson.put("Targets", "qingzhangyin");//接受者用户帐号
		mainJson.put("Flag", "0");//1需要；0 不需要-是否需要回执
		/*发送系统编号年月日时分秒6位序列号
		示例：
		系统编号1001
		则某时消息ID
		1001201408152020200001*/
		mainJson.put("MsgId", "1001" + new Date().getTime());
		mainJson.put("TargetTime", DateUtils.getTime("yyyy-MM-dd HH:mm:ss"));//YYYY-MM-DD HH:MM:SS
		mainJson.put("Priority", "1");//优先级
		mainJson.put("TerControl", "2");//0 ：pc； 1：移动端；2：pc和移动端都通知

		StringBuilder sb = new StringBuilder();
		sb.append("https://baike.baidu.com/").append("\n");
		sb.append("订单编码:").append("123456").append("\n");
		sb.append("订单状态").append("下单成功").append("\n");
		//msg.

		mainJson.put("MSContent", sb.toString());

		String postData = mainJson.toString();

		System.out.println(postData);
		Connection connection = Jsoup.connect("http://120.79.80.138:7007/").ignoreContentType(true);

		connection.data("aaa", "ccc"); //
		connection.header("Content-Type", "application/json; charset=UTF-8"); // 这是重点
		connection.header("Accept", "text/*, */*; q=0.01");
		connection.timeout(15000);
		connection.requestBody(postData);
		Document document;
		try {
			document = connection.post();
			String result = document.text();
			System.out.println(result);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static int count = 0;

	public static void main(String[] args) {


		for (int i = 0; i < 1; i++) {
			start();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

	}

}
