package com.chinaitop.depot.intelligent.SendMessagePT;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

//短信发送平台
public class SendMessagePT {

    public boolean sendingSMS(SmsDataVO smsDataVO) throws Exception {
        String PostData = "sname=dlbjszls&spwd=wwtl1234&scorpid=&sprdid=1012888&sdst=" + smsDataVO.getSdst() + "&smsg="
                + java.net.URLEncoder.encode(smsDataVO.getSmsg() + "【天津市粮库智能化平台】", "utf-8");
        String ret = Send.SMS(PostData, "http://cf.51welink.com/submitdata/Service.asmx/g_Submit");
        // 通过解析xml获得返回值
        List<SmsDataVO> list = ReadXMLByJDom.getBooks(ret);
        if(list.get(0).getState()==0) {//0 发送成功
            // 格式化时间
            String str = "20" + list.get(1).getMsgId();
            String str1 = str.substring(0, str.length() - 7);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Date sendDate = sdf.parse(str1);
            // 赋值
            smsDataVO.setState(list.get(0).getState());
            smsDataVO.setMsgId(list.get(1).getMsgId());
            smsDataVO.setMsgState(list.get(2).getMsgState());
            smsDataVO.setReserve(list.get(3).getReserve());
            smsDataVO.setSendDate(sendDate);
        }else {//1 发送失败
            // 赋值
            smsDataVO.setState(1);
            smsDataVO.setMsgId(list.get(1).getMsgId());
            smsDataVO.setMsgState(list.get(2).getMsgState());
            smsDataVO.setReserve(list.get(3).getReserve());
        }
        return true;
    }
}