package cn.superdesk.uniorder.common.security;

import cn.superdesk.uniorder.common.exception.constants.ExceptionMsg;
import cn.superdesk.uniorder.common.exception.UnifiedOrderRuntimeException;
import cn.superdesk.uniorder.common.security.crypt.rsa.SignTools;
import cn.superdesk.uniorder.common.HttpClientUtils;

import java.util.HashMap;

public class PushUtil {

	public static String pushMessage(String url, String phone, String messageTitle, String messageType, String workOrderNo, String sound) {
		String sign = null;

		try {
			sign = SignTools.makeSign("1");
		} catch (Exception e) {
			throw new UnifiedOrderRuntimeException(ExceptionMsg.SIGN_CREATE_ERROR.getCode(), ExceptionMsg.SIGN_CREATE_ERROR.getMsg());
		}

		HashMap<String, String> map = new HashMap<>();

		map.put("params", "1");
		map.put("sign", sign);
		map.put("phone", phone);
		map.put("messageTitle", messageTitle);
		map.put("messageType", messageType);
		map.put("workOrderNo", workOrderNo);
		map.put("sound", sound);

		return HttpClientUtils.doPost(url, map);
	}

	public static String pushGrantMessage(String orgId, String url, String h5url, String id, String realname, String mobile, String organizationName, String invoiceCount, String fundCount) {

		String content = "采购基金管理员" + realname + ","
				+ "您好！" + organizationName + "开票金额" + invoiceCount + "元,"
				+ "获得采购基金" + fundCount + "元,完成月结回款即可激活并抵现金使用。"
				+ realname + "的采购基金账单:" + h5url + "?id=" + id + ",回复TD退订！";

		HashMap<String, String> map = new HashMap<>();
		map.put("orgId", orgId);
		map.put("content", content);
		map.put("phones", mobile);
		return HttpClientUtils.doPost(url, map);
	}

	public static String pushActivatedMessage(String orgId, String url, String h5url, String id, String realname, String mobile, String organizationName, String fundCount, String fundBalance) {

		String content = "采购基金管理员" + realname + ","
				+ "您好！" + organizationName + fundCount + "元采购基金已入账,当前余额" + fundBalance + "。"
				+ realname + "的采购基金:" + h5url + "?id=" + id + ",回复TD退订！";

		HashMap<String, String> map = new HashMap<>();

		map.put("orgId", orgId);
		map.put("content", content);
		map.put("phones", mobile);

		return HttpClientUtils.doPost(url, map);
	}

}
