/// <summary> /// 根据传入的信息进行短信发送状态的查询 /// 9月26日添加对返回的集合中是否存在指定msgid的对象的判断 /// 若存在则返回true,不存在则返回false /// </summary> /// <param name="result"></param> /// <returns></returns> public bool QueryMsg(SMSModel_Query smsdata, out List<SMSModel_QueryReceive> list_receiveModel) { String _data = null;//XML文本 String _serverURL = "http://wt.3tong.net/http/sms/Report";//服务器地址 string returnMsg; //1 判断参数是否足够 if (!SendBeforeCheck(smsdata)) { list_receiveModel = new List<SMSModel_QueryReceive>(); return false; } _data = ObjTransform.Model2Xml_FormatQuery(smsdata); returnMsg = httpInvoke(_serverURL, _data); //解析服务器反馈信息 if (returnMsg.Length < 1) { list_receiveModel = new List<SMSModel_QueryReceive>(); return false; } //2.2 将接收到的短信发送回执转换为对象 //此处有问题 list_receiveModel = ObjTransform.Xml2Model_queryReceiveMsg(returnMsg); if (this.CheckQueryReceiveLegal(smsdata.smsId, list_receiveModel)) { return true; } else { return false; } }
/// <summary> /// 将查询请求对象转换成xml格式 /// </summary> /// <param name="smsdata"></param> /// <returns></returns> public static string Model2Xml_FormatQuery(SMSModel_Query smsdata) { var _data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<message>" + "<account>" + smsdata.account + "</account>" + "<password>" + Encryption.MD5Encryption(smsdata.password) + "</password>" + "<msgid>" + smsdata.smsId + "</msgid>" + "<phone>" +""/*smsdata.phoneNums*/+ "</phone>" + "</message>"; return _data; }
/// <summary> /// 根据msgid执行查询接收短信状态 /// </summary> /// <param name="msgid"></param> public static void ToQuery(string msgid,out List<SMSModel_QueryReceive> list_queryReceive,out int state) { //IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); //以后通过spring .net 实现 ISMSQuery smsQuery = new SMSFactory.SMSQuery(); IS_SMSContentBLL smsContentBLL = new PMS.BLL.S_SMSContentBLL(); IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); string account = "dh74381"; //账号"dh74381"; string passWord = "******";//密码 = "uAvb3Qey"; //6 查询发送状态(是否加入等待时间?) SMSModel_Query queryMsg = new SMSModel_Query() { account = account, password = passWord, smsId = msgid, //phoneNums=model.PhoneNums }; List<SMSModel_QueryReceive> list_QueryReceive; //根据传入的信息进行查询,并有一个状态信息集合 bool isGetReturnMsg = smsQuery.QueryMsg(queryMsg, out list_QueryReceive); //根据传入的状态集合进行判断当前的状态 var index_state = 0;//smsQuery.GetQueryState(list_QueryReceive);此处已修改 //为变量赋值 list_queryReceive = list_QueryReceive; state = index_state; if (!isGetReturnMsg) { //查询结果有问题,跳出本次查询 state = 2; return; // return Content("服务器错误"); } //当查询返回的集合数量为1,且唯一的对象的desc为成功,则直接跳出,不进行下面的操作,并对state赋值为1 if (list_QueryReceive.Count() == 1 && list_queryReceive.FirstOrDefault().desc == "成功"&&list_queryReceive.FirstOrDefault().phoneNumber==null) { //返回的desc=成功 state = 1; //return; } //7 获取该次发送的SMSContent的ID var list = smsContentBLL.GetListBy(p => p.msgId.Equals(msgid)); int scid = list.FirstOrDefault().ID; //向数据库中写入本集合中的对象 bool isSaveCurrnetMsgOk = smsRecord_CurrentBLL.SaveReceieveMsg(list_QueryReceive, scid); if (list_QueryReceive.Count() == 0) { state = 99; //ToShow("当前取出的对象中接收内容有误"); //return; } }
/// <summary> /// 根据短信实体判断短信实体是否符合标准 /// 符合返回true, /// 不符合返回false /// </summary> /// <param name="smsdata"></param> /// <returns></returns> public bool SendBeforeCheck(SMSModel_Query smsdata) { if (smsdata.account.Length < 1 &/* smsdata.smsId.Length < 1 & */smsdata.password.Length < 1) { return false; } else { return true; } }