/// <summary> /// 添加用户信息到缓存 /// </summary> /// <param name="objUser"></param> public static void AddCacheUser(SmsServer.Model.SmsUser objUser) { lock (pUserList) { pUserList[objUser.UserID + objUser.UserPwd] = objUser; } }
/// <summary> /// 获取通道信息 /// </summary> /// <param name="objUser"></param> /// <param name="objMsg"></param> /// <returns></returns> private bool GetSpgateInfo(SmsUserData objUser, SmsMsgSendStr objMsg) { string strSpgateNumber = ""; int iPhoneCount = 0; for (int i = 0; i < 4; i++) { switch (i) { case 0: strSpgateNumber = objUser.MobileSpgate; break; case 1: strSpgateNumber = objUser.UnicomSpgate; break; case 2: strSpgateNumber = objUser.TelecomSpgate; break; case 3: strSpgateNumber = objUser.ChinaPhoneSpgate; break; default: strSpgateNumber = ""; break; } if (i == 0) { iPhoneCount = objMsg.PhoneCount[i] + objMsg.PhoneCount[4]; } else { iPhoneCount = objMsg.PhoneCount[i]; } if (iPhoneCount > 0) { if (strSpgateNumber == "") { return(false); } if (!DataCache.GetCacheSpgate(strSpgateNumber, ref objMsg.PhoneSpgate[i])) { return(false); } } } return(true); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SmsServer.Model.SmsUser model) { try { MyDataBase.db.Update(SmsPlatForm.SmsUser) .AddColumn(SmsPlatForm.SmsUser.Status, model.Status) .AddColumn(SmsPlatForm.SmsUser.MaxCount, model.MaxCount) .AddColumn(SmsPlatForm.SmsUser.MinCount, model.MinCount) .AddColumn(SmsPlatForm.SmsUser.AuditNum, model.AuditNum) .AddColumn(SmsPlatForm.SmsUser.IsAudit, model.IsAudit) .AddColumn(SmsPlatForm.SmsUser.MaxLen, model.MaxLen) .AddColumn(SmsPlatForm.SmsUser.MobileLen, model.MobileLen) .AddColumn(SmsPlatForm.SmsUser.UnicomLen, model.UnicomLen) .AddColumn(SmsPlatForm.SmsUser.TelecomLen, model.TelecomLen) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneLen, model.ChinaPhoneLen) .AddColumn(SmsPlatForm.SmsUser.SignStr, model.SignStr) .AddColumn(SmsPlatForm.SmsUser.HasIndex, model.HasIndex) .AddColumn(SmsPlatForm.SmsUser.MobileSpgate, model.MobileSpgate) .AddColumn(SmsPlatForm.SmsUser.UnicomSpgate, model.UnicomSpgate) .AddColumn(SmsPlatForm.SmsUser.TelecomSpgate, model.TelecomSpgate) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneSpgate, model.ChinaPhoneSpgate) .AddColumn(SmsPlatForm.SmsUser.MobileMap, model.MobileMap) .AddColumn(SmsPlatForm.SmsUser.UnicomMap, model.UnicomMap) .AddColumn(SmsPlatForm.SmsUser.TelecomMap, model.TelecomMap) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneMap, model.ChinaPhoneMap) .AddColumn(SmsPlatForm.SmsUser.MobileSubport, model.MobileSubport) .AddColumn(SmsPlatForm.SmsUser.UnicomSubport, model.UnicomSubport) .AddColumn(SmsPlatForm.SmsUser.TelecomSubport, model.TelecomSubport) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneSubport, model.ChinaPhoneSubport) .AddColumn(SmsPlatForm.SmsUser.HistoryType, model.HistoryType) .AddColumn(SmsPlatForm.SmsUser.UserName, model.UserName) .AddColumn(SmsPlatForm.SmsUser.CompanyName, model.CompanyName) .AddColumn(SmsPlatForm.SmsUser.Phone, model.Phone) .AddColumn(SmsPlatForm.SmsUser.IsSpgateFee, model.IsSpgateFee) .AddColumn(SmsPlatForm.SmsUser.ExtraInfo, model.ExtraInfo) .Where(SmsPlatForm.SmsUser.UserID == model.UserID).Execute(); return(true); } catch (Exception ee) { return(false); } }
/// <summary> /// 取得各通道拆分后的信息 /// </summary> /// <param name="objUser"></param> /// <param name="objMsg"></param> /// <param name="strMsg"></param> private void GetSpliteMsg(SmsUserData objUser, SmsMsgSendStr objMsg, string strMsg) { SmsSpgate spgate = new SmsSpgate(); int iPhoneCount = 0; for (int i = 0; i < 4; i++) { if (i == 0) { iPhoneCount = objMsg.PhoneCount[i] + objMsg.PhoneCount[4]; } else { iPhoneCount = objMsg.PhoneCount[i]; } if (iPhoneCount > 0) //绑定好了通道,//拆分好信息保存进数组 { SplitMessage(strMsg, objMsg.PhoneSpgate[i].MsgLen, objUser.HasIndex, ref objMsg.MessageArray[i], out objMsg.MsgArrayLen[i]); } } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(SmsServer.Model.SmsUser model) { MyDataBase.db.Insert(SmsPlatForm.SmsUser) .AddColumn(SmsPlatForm.SmsUser.UserID, model.UserID) .AddColumn(SmsPlatForm.SmsUser.UserPwd, model.UserPwd) .AddColumn(SmsPlatForm.SmsUser.ParentID, model.ParentID) .AddColumn(SmsPlatForm.SmsUser.UserClass, model.UserClass) .AddColumn(SmsPlatForm.SmsUser.Status, model.Status) .AddColumn(SmsPlatForm.SmsUser.DisabledBy, model.DisabledBy) .AddColumn(SmsPlatForm.SmsUser.SendedNum, model.SendedNum) .AddColumn(SmsPlatForm.SmsUser.Balance, model.Balance) .AddColumn(SmsPlatForm.SmsUser.MaxCount, model.MaxCount) .AddColumn(SmsPlatForm.SmsUser.MinCount, model.MinCount) .AddColumn(SmsPlatForm.SmsUser.AuditNum, model.AuditNum) .AddColumn(SmsPlatForm.SmsUser.IsAudit, model.IsAudit) .AddColumn(SmsPlatForm.SmsUser.MaxLen, model.MaxLen) .AddColumn(SmsPlatForm.SmsUser.MobileLen, model.MobileLen) .AddColumn(SmsPlatForm.SmsUser.UnicomLen, model.UnicomLen) .AddColumn(SmsPlatForm.SmsUser.TelecomLen, model.TelecomLen) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneLen, model.ChinaPhoneLen) .AddColumn(SmsPlatForm.SmsUser.SignStr, model.SignStr) .AddColumn(SmsPlatForm.SmsUser.HasIndex, model.HasIndex) .AddColumn(SmsPlatForm.SmsUser.MobileSpgate, model.MobileSpgate) .AddColumn(SmsPlatForm.SmsUser.UnicomSpgate, model.UnicomSpgate) .AddColumn(SmsPlatForm.SmsUser.TelecomSpgate, model.TelecomSpgate) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneSpgate, model.ChinaPhoneSpgate) .AddColumn(SmsPlatForm.SmsUser.UnicomMap, model.UnicomMap) .AddColumn(SmsPlatForm.SmsUser.TelecomMap, model.TelecomMap) .AddColumn(SmsPlatForm.SmsUser.ChinaPhoneMap, model.ChinaPhoneMap) .AddColumn(SmsPlatForm.SmsUser.HistoryType, model.HistoryType) .AddColumn(SmsPlatForm.SmsUser.CreatTime, model.CreatTime) .AddColumn(SmsPlatForm.SmsUser.UserName, model.UserName) .AddColumn(SmsPlatForm.SmsUser.CompanyName, model.CompanyName) .AddColumn(SmsPlatForm.SmsUser.Phone, model.Phone) .AddColumn(SmsPlatForm.SmsUser.ExtraInfo, model.ExtraInfo).Execute(); return(true); }
/****************************************************************/ /// <summary> /// 从缓存中取用户信息 /// </summary> /// <param name="strUserKey"></param> /// <param name="objUser"></param> public static bool GetCacheUser(string strUserID, string strPwd, ref SmsServer.Model.SmsUser objUser) { bool bExist = false; string strUserKey = strUserID + strPwd; lock (pUserList) { bExist = pUserList.ContainsKey(strUserKey); if (bExist) { objUser = pUserList[strUserKey]; } } if (!bExist) { objUser = new SmsUser().GetSelectSmsUser(strUserID, strPwd); if (objUser == null) { return(false); } AddCacheUser(objUser); } return(true); }
/// <summary> /// 计算应扣费总额 /// </summary> /// <param name="objUser"></param> /// <param name="objMsg"></param> /// <returns></returns> private int ComputeTotalFee(SmsUserData objUser, SmsMsgSendStr objMsg) { int iTotalCount = 0; int iFeeMap = -1; int iSplitLen = 0; int iMobileSingleFee = 0; for (int i = 0; i < 6; i++) { if (objMsg.FeePhoneCount[i] > 0) { switch (i) { case 0: //iFeeMap = objUser.MobileMap == null ? i : (int)objUser.MobileMap; iSplitLen = (int)objUser.MobileLen; break; case 1: //iFeeMap = objUser.UnicomMap == null ? i : (int)objUser.UnicomMap; iSplitLen = (int)objUser.UnicomLen; break; case 2: //iFeeMap = objUser.TelecomMap == null ? i : (int)objUser.TelecomMap; iSplitLen = (int)objUser.TelecomLen; break; case 3: //iFeeMap = objUser.ChinaPhoneMap == null ? i : (int)objUser.ChinaPhoneMap; iSplitLen = (int)objUser.ChinaPhoneLen; break; case 4: //iFeeMap = 0; iSplitLen = (int)objUser.MobileLen; break; case 5: //iFeeMap = 0; iSplitLen = (int)objUser.MobileLen; break; } iFeeMap = objMsg.FeeMap[i]; if (i == 0) { iMobileSingleFee = GetFee(iSplitLen, objMsg, iFeeMap, 0); iTotalCount += iMobileSingleFee * objMsg.FeePhoneCount[i]; } else if (i > 3) { if (iMobileSingleFee == 0) { iMobileSingleFee = GetFee(iSplitLen, objMsg, iFeeMap, 0); } iTotalCount += iMobileSingleFee * objMsg.FeePhoneCount[i]; } else { iTotalCount += GetFee(iSplitLen, objMsg, iFeeMap, i) * objMsg.FeePhoneCount[i]; } } } return(iTotalCount); }
/// <summary> /// 获取各号段号码数及计费号码数,及各号段号码列表 /// </summary> /// <param name="strPhoneArray"></param> /// <param name="objUser"></param> /// <param name="objMsg"></param> private void GetPhoneList(string[] strPhoneArray, SmsUserData objUser, SmsMsgSendStr objMsg) { int iCheckLevel = 1; //先获取号段列表 int iFlag = -1; string strPhone = string.Empty; int iType = -1; int iCurrNum = -1; foreach (string strMobile in strPhoneArray) { iFlag = GetPhoneSectionNum(strMobile, DataCache.pPhoneSection); strPhone = strMobile + ","; iCurrNum++; switch (iFlag) { case -1://有非法字符 switch (iCheckLevel) { case 1: //低 objMsg.PhoneList[4].Append(strPhone); objMsg.PhoneCount[4]++; objMsg.FeePhoneCount[4]++; objMsg.FeeMap[4] = 0; objMsg.MsgIdOffset[4].Append(iCurrNum.ToString() + ","); break; } break; case -2: //长度不符合 //判断长度,结合长度差距与判断等级来确定是否扣费但是不发 break; case 3: objMsg.FeePhoneCount[0]++; iType = objUser.MobileMap == null ? iFlag : (int)objUser.MobileMap; objMsg.FeeMap[0] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum);//根据号段映射来判断扣费增加的号段 break; case 4: objMsg.FeePhoneCount[1]++; iType = objUser.UnicomMap == null ? iFlag : (int)objUser.UnicomMap; objMsg.FeeMap[1] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; case 5: objMsg.FeePhoneCount[2]++; iType = objUser.TelecomMap == null ? iFlag : (int)objUser.TelecomMap; objMsg.FeeMap[2] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; case 6: objMsg.FeePhoneCount[3]++; iType = objUser.ChinaPhoneMap == null ? iFlag : (int)objUser.ChinaPhoneMap; objMsg.FeeMap[3] = iType; // AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; default: ///默认扣费不发送 objMsg.PhoneList[4].Append(strPhone); objMsg.PhoneCount[4]++; objMsg.FeePhoneCount[4]++; objMsg.FeeMap[4] = 0; objMsg.MsgIdOffset[4].Append(iCurrNum.ToString() + ","); break; } } }
/// <summary> /// 对外的信息发送接口 /// </summary> /// <param name="strUserID"></param> /// <param name="strPwd"></param> /// <param name="strPhone"></param> /// <param name="strMsg"></param> /// <param name="strSubport"></param> /// <returns></returns> public string SendMessage(string strUserID, string strPwd, string strPhone, string strMsg, string strSubport) { //此处传进来的参数已经经过了空参数与非法参数的检查 if (string.IsNullOrEmpty(strUserID) || string.IsNullOrEmpty(strPwd) || string.IsNullOrEmpty(strPhone) || string.IsNullOrEmpty(strMsg)) { return("-1"); //参数为空 } //验证账号密码、子端口格式 if (!DataVerify.IsIllegalUser(strUserID) || !DataVerify.IsIllegalUser(strPwd)) { return("-2"); //账号或者密码非法 } else if (!string.IsNullOrEmpty(strSubport)) { if (!DataVerify.IsNumber(strSubport) || strSubport.Length > 6) { return("-3"); //子端口格式非法 } //strSubport = ""; } //获取用户信息,判断密码是否正确 SmsUserData objUser = new SmsUserData(); DataCache.GetCacheUser(strUserID, strPwd, ref objUser); if (object.Equals(null, objUser)) { //用户名或密码错误 return("-11"); } //判断账号是否被禁用 if (objUser.Status == 1)//账号被禁用,0正常,1禁用 { return("-12"); } //如果余额已经小于等于0 if (objUser.Balance <= 0) { return("-15"); //余额不足 } //判断信息内容是否超长[加上签名后的],也就是说可以发的长度是设置长度减去签名长度 int iMsgLen = 0; strMsg = strMsg + objUser.SignStr.Trim(); iMsgLen = strMsg.Length; if (iMsgLen > objUser.MaxLen) { return("-13"); } //判断是否有非法关键词 if (objUser.IsCheckIllegal == 1) //需要检测非法关键词 { if (IsContainIllegal(strMsg)) { return("-14"); } } string[] strPhoneArray = strPhone.Split(','); if (strPhoneArray.Length > objUser.MaxCount) { return("-16"); //发送号码数太多 } if (strPhoneArray.Length < objUser.MinCount) { return("-17"); //发送号码数太少 } SmsMsgSendStr objMsg = new SmsMsgSendStr(); GetPhoneList(strPhoneArray, objUser, objMsg); //获取通道信息 if (!GetSpgateInfo(objUser, objMsg)) { return("-18"); //有通道未绑定 } //获取信息拆分结果 GetSpliteMsg(objUser, objMsg, strMsg); //计算扣费数 int iTotalCount = ComputeTotalFee(objUser, objMsg);//进行扣费处理,此处难在信息的拆分上[计算一条信息要扣多少条] if (iTotalCount == 0) { return("-19"); //无有效号码 } //验证完毕,扣余额。开始发送,如果余额不足,则不扣,在存储过程中扣费 if (!new SmsUser().UpdateBalance(strUserID, iTotalCount)) { return("-15"); //扣除余额失败,余额不足 } //发送 SendMessage(objUser, objMsg, strSubport, iTotalCount); return("1"); }
private string SendMessage(SmsUserData objUser, SmsMsgSendStr objMsg, string strSubport, int iTotalCount) { //1。根据审核标识来判断是写入审核表,还是进行发送处理 // if (objUser.IsAudit == 1) // { // if (iTotalCount >= objUser.AuditNum) // { // //插入等待审核表 // return "12";//发送成功 // } // } //以上判断是否插入审核表 SmsTaskEx objSmsTask = new SmsTaskEx(); objSmsTask.SendFlag = 0; //标识是否号码是正确的 objSmsTask.SaveType = objUser.HistoryType; //objSmsTask.SubPort = strSubport; objSmsTask.SubPortEx = strSubport; objSmsTask.SendTime = DateTime.Now; objSmsTask.SubTime = DateTime.Now; objSmsTask.UserID = objUser.UserID; objSmsTask.ParentID = objUser.ParentID; for (int i = 0; i < 4; i++) //发送真实信息 { if (objMsg.PhoneCount[i] > 0) //如果有号码需要发送 { objSmsTask.SpgateNo = objMsg.PhoneSpgate[i].GateNumber; objSmsTask.PhoneList = objMsg.PhoneList[i].ToString(); objSmsTask.PhoneNum = objMsg.PhoneCount[i]; switch (i) { case 0: objSmsTask.SubPort = objUser.MobileSubport; break; case 1: objSmsTask.SubPort = objUser.UnicomSubport; break; case 2: objSmsTask.SubPort = objUser.TelecomSubport; break; case 3: objSmsTask.SubPort = objUser.ChinaPhoneSubport; break; } for (int j = 0; j < 4; j++) { if (objMsg.FeeMap[j] == i) //如果j号段映射到了i号段上,那么在i通道上的j号段号码数为j号段扣费号码数,i通道上j号段的拆分扣费数 { switch (j) { case 0: objSmsTask.SubPort = objUser.MobileSubport; objSmsTask.MobileNum = objMsg.FeePhoneCount[j]; break; case 1: objSmsTask.SubPort = objUser.UnicomSubport; objSmsTask.UnicomNum = objMsg.FeePhoneCount[j]; break; case 2: objSmsTask.SubPort = objUser.TelecomSubport; objSmsTask.TelecomNum = objMsg.FeePhoneCount[j]; break; case 3: objSmsTask.SubPort = objUser.ChinaPhoneSubport; objSmsTask.ChinaNum = objMsg.FeePhoneCount[j]; break; } } } SendMessageQueue(objSmsTask, objMsg.MessageArray[i], objMsg.SingleMsgFeeNum, objMsg.MsgArrayLen[i], objMsg.PhoneSpgate[i].BusinessID); } } //发送错误号码的信息,统一流程 if (objMsg.PhoneCount[4] > 0) { objSmsTask.SendFlag = 1; objSmsTask.SubPort = objUser.MobileSubport; objSmsTask.SpgateNo = objMsg.PhoneSpgate[0].GateNumber; objSmsTask.PhoneList = objMsg.PhoneList[4].ToString(); objSmsTask.PhoneNum = objMsg.PhoneCount[4]; objSmsTask.MobileNum = objMsg.FeePhoneCount[4]; //将扣费不发送号码全分到移动上 objSmsTask.UnicomNum = 0; objSmsTask.TelecomNum = 0; objSmsTask.ChinaNum = 0; SendMessageQueue(objSmsTask, objMsg.MessageArray[0], objMsg.SingleMsgFeeNum, objMsg.MsgArrayLen[0], objMsg.PhoneSpgate[0].BusinessID); } return("1"); }
private string SendMessage(SmsUserData objUser,SmsMsgSendStr objMsg,string strSubport,int iTotalCount) { //1。根据审核标识来判断是写入审核表,还是进行发送处理 // if (objUser.IsAudit == 1) // { // if (iTotalCount >= objUser.AuditNum) // { // //插入等待审核表 // return "12";//发送成功 // } // } //以上判断是否插入审核表 SmsTaskEx objSmsTask = new SmsTaskEx(); objSmsTask.SendFlag = 0; //标识是否号码是正确的 objSmsTask.SaveType = objUser.HistoryType; //objSmsTask.SubPort = strSubport; objSmsTask.SubPortEx = strSubport; objSmsTask.SendTime = DateTime.Now; objSmsTask.SubTime = DateTime.Now; objSmsTask.UserID = objUser.UserID; objSmsTask.ParentID = objUser.ParentID; for (int i = 0; i < 4;i++ ) //发送真实信息 { if (objMsg.PhoneCount[i] > 0) //如果有号码需要发送 { objSmsTask.SpgateNo = objMsg.PhoneSpgate[i].GateNumber; objSmsTask.PhoneList = objMsg.PhoneList[i].ToString(); objSmsTask.PhoneNum = objMsg.PhoneCount[i]; switch (i) { case 0: objSmsTask.SubPort = objUser.MobileSubport; break; case 1: objSmsTask.SubPort = objUser.UnicomSubport; break; case 2: objSmsTask.SubPort = objUser.TelecomSubport; break; case 3: objSmsTask.SubPort = objUser.ChinaPhoneSubport; break; } for (int j = 0; j < 4;j++ ) { if (objMsg.FeeMap[j] == i) //如果j号段映射到了i号段上,那么在i通道上的j号段号码数为j号段扣费号码数,i通道上j号段的拆分扣费数 { switch (j) { case 0: objSmsTask.SubPort = objUser.MobileSubport; objSmsTask.MobileNum = objMsg.FeePhoneCount[j]; break; case 1: objSmsTask.SubPort = objUser.UnicomSubport; objSmsTask.UnicomNum = objMsg.FeePhoneCount[j]; break; case 2: objSmsTask.SubPort = objUser.TelecomSubport; objSmsTask.TelecomNum = objMsg.FeePhoneCount[j]; break; case 3: objSmsTask.SubPort = objUser.ChinaPhoneSubport; objSmsTask.ChinaNum = objMsg.FeePhoneCount[j]; break; } } } SendMessageQueue(objSmsTask, objMsg.MessageArray[i], objMsg.SingleMsgFeeNum, objMsg.MsgArrayLen[i], objMsg.PhoneSpgate[i].BusinessID); } } //发送错误号码的信息,统一流程 if (objMsg.PhoneCount[4] > 0) { objSmsTask.SendFlag = 1; objSmsTask.SubPort = objUser.MobileSubport; objSmsTask.SpgateNo = objMsg.PhoneSpgate[0].GateNumber; objSmsTask.PhoneList = objMsg.PhoneList[4].ToString(); objSmsTask.PhoneNum = objMsg.PhoneCount[4]; objSmsTask.MobileNum = objMsg.FeePhoneCount[4]; //将扣费不发送号码全分到移动上 objSmsTask.UnicomNum = 0; objSmsTask.TelecomNum = 0; objSmsTask.ChinaNum = 0; SendMessageQueue(objSmsTask, objMsg.MessageArray[0], objMsg.SingleMsgFeeNum, objMsg.MsgArrayLen[0], objMsg.PhoneSpgate[0].BusinessID); } return "1"; }
/// <summary> /// 获取通道信息 /// </summary> /// <param name="objUser"></param> /// <param name="objMsg"></param> /// <returns></returns> private bool GetSpgateInfo(SmsUserData objUser, SmsMsgSendStr objMsg) { string strSpgateNumber = ""; int iPhoneCount = 0; for (int i = 0; i < 4;i++ ) { switch(i) { case 0: strSpgateNumber = objUser.MobileSpgate; break; case 1: strSpgateNumber = objUser.UnicomSpgate; break; case 2: strSpgateNumber = objUser.TelecomSpgate; break; case 3: strSpgateNumber = objUser.ChinaPhoneSpgate; break; default: strSpgateNumber = ""; break; } if (i == 0) { iPhoneCount = objMsg.PhoneCount[i] + objMsg.PhoneCount[4]; } else { iPhoneCount = objMsg.PhoneCount[i]; } if (iPhoneCount > 0) { if (strSpgateNumber == "") { return false; } if (!DataCache.GetCacheSpgate(strSpgateNumber, ref objMsg.PhoneSpgate[i])) { return false; } } } return true; }
/// <summary> /// 对外的信息发送接口 /// </summary> /// <param name="strUserID"></param> /// <param name="strPwd"></param> /// <param name="strPhone"></param> /// <param name="strMsg"></param> /// <param name="strSubport"></param> /// <returns></returns> public string SendMessage(string strUserID,string strPwd,string strPhone,string strMsg,string strSubport) { //此处传进来的参数已经经过了空参数与非法参数的检查 if(string.IsNullOrEmpty(strUserID) || string.IsNullOrEmpty(strPwd) || string.IsNullOrEmpty(strPhone) || string.IsNullOrEmpty(strMsg)) { return "-1"; //参数为空 } //验证账号密码、子端口格式 if (!DataVerify.IsIllegalUser(strUserID) || !DataVerify.IsIllegalUser(strPwd)) { return "-2"; //账号或者密码非法 } else if(!string.IsNullOrEmpty(strSubport)) { if (!DataVerify.IsNumber(strSubport) || strSubport.Length > 6 ) { return "-3"; //子端口格式非法 } //strSubport = ""; } //获取用户信息,判断密码是否正确 SmsUserData objUser = new SmsUserData(); DataCache.GetCacheUser(strUserID, strPwd, ref objUser); if(object.Equals(null,objUser)) { //用户名或密码错误 return "-11"; } //判断账号是否被禁用 if (objUser.Status == 1)//账号被禁用,0正常,1禁用 { return "-12"; } //如果余额已经小于等于0 if (objUser.Balance <= 0) { return "-15"; //余额不足 } //判断信息内容是否超长[加上签名后的],也就是说可以发的长度是设置长度减去签名长度 int iMsgLen = 0; strMsg = strMsg + objUser.SignStr.Trim(); iMsgLen = strMsg.Length; if (iMsgLen > objUser.MaxLen) { return "-13"; } //判断是否有非法关键词 if (objUser.IsCheckIllegal == 1) //需要检测非法关键词 { if (IsContainIllegal(strMsg)) { return "-14"; } } string[] strPhoneArray = strPhone.Split(','); if (strPhoneArray.Length > objUser.MaxCount) { return "-16"; //发送号码数太多 } if (strPhoneArray.Length < objUser.MinCount) { return "-17"; //发送号码数太少 } SmsMsgSendStr objMsg = new SmsMsgSendStr(); GetPhoneList(strPhoneArray, objUser, objMsg); //获取通道信息 if(!GetSpgateInfo(objUser, objMsg)) { return "-18"; //有通道未绑定 } //获取信息拆分结果 GetSpliteMsg(objUser, objMsg, strMsg); //计算扣费数 int iTotalCount = ComputeTotalFee(objUser, objMsg);//进行扣费处理,此处难在信息的拆分上[计算一条信息要扣多少条] if (iTotalCount == 0) { return "-19"; //无有效号码 } //验证完毕,扣余额。开始发送,如果余额不足,则不扣,在存储过程中扣费 if(!new SmsUser().UpdateBalance(strUserID,iTotalCount)) { return "-15"; //扣除余额失败,余额不足 } //发送 SendMessage(objUser, objMsg, strSubport,iTotalCount); return "1"; }
/// <summary> /// 获取各号段号码数及计费号码数,及各号段号码列表 /// </summary> /// <param name="strPhoneArray"></param> /// <param name="objUser"></param> /// <param name="objMsg"></param> private void GetPhoneList(string[] strPhoneArray,SmsUserData objUser,SmsMsgSendStr objMsg) { int iCheckLevel = 1; //先获取号段列表 int iFlag = -1; string strPhone = string.Empty; int iType = -1; int iCurrNum = -1; foreach (string strMobile in strPhoneArray ) { iFlag = GetPhoneSectionNum(strMobile, DataCache.pPhoneSection); strPhone = strMobile + ","; iCurrNum++; switch (iFlag) { case -1://有非法字符 switch (iCheckLevel) { case 1: //低 objMsg.PhoneList[4].Append(strPhone); objMsg.PhoneCount[4]++; objMsg.FeePhoneCount[4]++; objMsg.FeeMap[4] = 0; objMsg.MsgIdOffset[4].Append(iCurrNum.ToString() + ","); break; } break; case -2: //长度不符合 //判断长度,结合长度差距与判断等级来确定是否扣费但是不发 break; case 3: objMsg.FeePhoneCount[0]++; iType = objUser.MobileMap == null ? iFlag : (int)objUser.MobileMap; objMsg.FeeMap[0] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum);//根据号段映射来判断扣费增加的号段 break; case 4: objMsg.FeePhoneCount[1]++; iType = objUser.UnicomMap == null ? iFlag : (int)objUser.UnicomMap; objMsg.FeeMap[1] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; case 5: objMsg.FeePhoneCount[2]++; iType = objUser.TelecomMap == null ? iFlag : (int)objUser.TelecomMap; objMsg.FeeMap[2] = iType; AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; case 6: objMsg.FeePhoneCount[3]++; iType = objUser.ChinaPhoneMap == null ? iFlag : (int)objUser.ChinaPhoneMap; objMsg.FeeMap[3] = iType; // AdapterPhones(iType, strPhone, objMsg, iCurrNum); break; default: ///默认扣费不发送 objMsg.PhoneList[4].Append(strPhone); objMsg.PhoneCount[4]++; objMsg.FeePhoneCount[4]++; objMsg.FeeMap[4] = 0; objMsg.MsgIdOffset[4].Append(iCurrNum.ToString() + ","); break; } } }
/// <summary> /// 计算应扣费总额 /// </summary> /// <param name="objUser"></param> /// <param name="objMsg"></param> /// <returns></returns> private int ComputeTotalFee(SmsUserData objUser, SmsMsgSendStr objMsg) { int iTotalCount = 0; int iFeeMap = -1; int iSplitLen = 0; int iMobileSingleFee = 0; for (int i = 0; i < 6;i++ ) { if (objMsg.FeePhoneCount[i] > 0) { switch (i) { case 0: //iFeeMap = objUser.MobileMap == null ? i : (int)objUser.MobileMap; iSplitLen = (int)objUser.MobileLen; break; case 1: //iFeeMap = objUser.UnicomMap == null ? i : (int)objUser.UnicomMap; iSplitLen = (int)objUser.UnicomLen; break; case 2: //iFeeMap = objUser.TelecomMap == null ? i : (int)objUser.TelecomMap; iSplitLen = (int)objUser.TelecomLen; break; case 3: //iFeeMap = objUser.ChinaPhoneMap == null ? i : (int)objUser.ChinaPhoneMap; iSplitLen = (int)objUser.ChinaPhoneLen; break; case 4: //iFeeMap = 0; iSplitLen = (int)objUser.MobileLen; break; case 5: //iFeeMap = 0; iSplitLen = (int)objUser.MobileLen; break; } iFeeMap = objMsg.FeeMap[i]; if (i == 0) { iMobileSingleFee = GetFee(iSplitLen, objMsg, iFeeMap, 0); iTotalCount += iMobileSingleFee * objMsg.FeePhoneCount[i]; } else if (i>3) { if (iMobileSingleFee == 0 ) { iMobileSingleFee = GetFee(iSplitLen, objMsg, iFeeMap, 0); } iTotalCount += iMobileSingleFee * objMsg.FeePhoneCount[i]; } else { iTotalCount += GetFee(iSplitLen, objMsg, iFeeMap, i) * objMsg.FeePhoneCount[i]; } } } return iTotalCount; }