1402 lines
33 KiB
C++
1402 lines
33 KiB
C++
// Sms.cpp : CSms 的实现
|
||
|
||
#include "stdafx.h"
|
||
#include "Sms.h"
|
||
|
||
#include "..\public\LuTool.h"
|
||
#include "..\public\SendPub.h"
|
||
#include "..\public\sendpub.cpp" //如果在工程中加入,会找不到CW2A
|
||
#include "..\public\StringSort\StringSort.h"
|
||
#include "..\public\SAStatusLog\SAStatusLog.cpp" //如果在工程中加入,会找不到CW2A
|
||
#include "..\public\CMarkup\Markup.h"
|
||
#include "..\public\AutoCoInitializeEx\AutoCoInitializeEx.h"
|
||
// CSms
|
||
|
||
|
||
|
||
STDMETHODIMP CSms::CheckPasswd(BSTR User, BSTR Passwd, BSTR Encrypt, LONG Purview, LONG* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
//取得User ,Passwd
|
||
char szUser[64]={0};
|
||
char szPasswd[128]={0};
|
||
char szPasswd2[128]={0};
|
||
char szEncrypt[128]={0};
|
||
strcpy( szUser , CW2A(User) );
|
||
strcpy( szPasswd , CW2A(Passwd) );
|
||
strcpy( szEncrypt , CW2A(Encrypt) );
|
||
|
||
if (strlen(szUser) <= 0 || strlen(szPasswd)<=0) //用户名或密码为空,认证不通过
|
||
{
|
||
*pRet = 0;
|
||
return S_OK;
|
||
}
|
||
|
||
CDes des;
|
||
long lLen=sizeof(Passwd);
|
||
des.Encrypt( szPasswd , strlen(szPasswd) , szPasswd2 , lLen , szUser , 8 );
|
||
if ( !strcmp( szPasswd2 , szEncrypt ) )
|
||
{
|
||
*pRet = 1;
|
||
}
|
||
else
|
||
{
|
||
*pRet = 0;
|
||
}
|
||
if ( !(Purview&PURVIEW_LOGIN) )
|
||
{
|
||
*pRet = -1;
|
||
}
|
||
/*
|
||
if ( !(Purview&PURVIEW_SENDP) )
|
||
{
|
||
*pRet = -2;
|
||
}
|
||
*/
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::CheckPasswd2(LONG CorpID, BSTR User, BSTR Passwd, BSTR TimeStamp, BSTR Encrypt, LONG Purview, LONG* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
|
||
//取得User ,Passwd
|
||
char szUser[64] = { 0 };
|
||
char szPasswd[128] = { 0 };
|
||
char szPasswd2[128] = { 0 };
|
||
char szEncrypt[128] = { 0 };
|
||
TCHAR szPasswdU2[128] = { 0 };
|
||
strcpy(szUser, CW2A(User));
|
||
strcpy(szPasswd, CW2A(Passwd));
|
||
strcpy(szEncrypt, CW2A(Encrypt));
|
||
|
||
if (strlen(szUser) <= 0 || strlen(szPasswd) <= 0) //用户名或密码为空,认证不通过
|
||
{
|
||
*pRet = 0;
|
||
return S_OK;
|
||
}
|
||
|
||
CDes des;
|
||
|
||
long lOut = sizeof(szPasswd2);
|
||
des.Decrypt(szEncrypt, (long)strlen(szEncrypt), szPasswd2, lOut, szUser, 8);
|
||
_tcscpy(szPasswdU2, CA2W(szPasswd2));
|
||
|
||
CString strCorpID;
|
||
strCorpID.Format(_T("%d"), CorpID);
|
||
CString strPasswd2 = szPasswdU2;
|
||
CString strTimeStamp = TimeStamp;
|
||
|
||
CString strMd5 = Passwd;
|
||
strMd5.MakeUpper();
|
||
|
||
CString strMd52 = CSendPub::GetMD5(strCorpID + strPasswd2 + strTimeStamp, false);
|
||
strMd52.MakeUpper();
|
||
|
||
if (strMd5 == strMd52)
|
||
{
|
||
*pRet = 1;
|
||
}
|
||
else
|
||
{
|
||
*pRet = 0;
|
||
}
|
||
|
||
|
||
if (!(Purview&PURVIEW_LOGIN))
|
||
{
|
||
*pRet = -1;
|
||
}
|
||
/*
|
||
if (!(Purview&PURVIEW_SENDP))
|
||
{
|
||
*pRet = -2;
|
||
}
|
||
*/
|
||
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::GetPasswd(BSTR User, BSTR Passwd, BSTR* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
//取得User ,Passwd
|
||
char szUser[64]={0};
|
||
char szPasswd[128]={0};
|
||
char szPasswd2[128]={0};
|
||
char szEncrypt[128]={0};
|
||
strcpy( szUser , CW2A(User) );
|
||
strcpy( szPasswd , CW2A(Passwd) );
|
||
|
||
CDes des;
|
||
long lLen=sizeof(szPasswd2);
|
||
des.Encrypt(szPasswd , strlen(szPasswd) , szPasswd2 , lLen , szUser , 8 );
|
||
|
||
*pRet = ::SysAllocString(CA2W(szPasswd2));
|
||
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::DePasswd(BSTR User, BSTR Passwd, BSTR* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
*pRet = ::SysAllocString(CA2W("ERROR"));
|
||
/*
|
||
//取得User ,Passwd
|
||
char szUser[64]={0};
|
||
char szPasswd[128]={0};
|
||
char szPasswd2[128]={0};
|
||
char szEncrypt[128]={0};
|
||
strcpy( szUser , CW2A(User) );
|
||
strcpy( szPasswd , CW2A(Passwd) );
|
||
|
||
CDes des;
|
||
long lLen=sizeof(szPasswd2);
|
||
des.Decrypt(szPasswd , strlen(szPasswd) , szPasswd2 , lLen , szUser , 8 );
|
||
|
||
*pRet = ::SysAllocString(CA2W(szPasswd2));
|
||
*/
|
||
return S_OK;
|
||
}
|
||
|
||
void CSms::GetCurrentPath(TCHAR *pPath)
|
||
{
|
||
::GetModuleFileName(AfxGetInstanceHandle(), pPath, 512);
|
||
int j = lstrlen(pPath);
|
||
for (; j>0; j--)
|
||
{
|
||
if (pPath[j] == '\\')
|
||
break;
|
||
}
|
||
pPath[j + 1] = 0;
|
||
}
|
||
|
||
|
||
|
||
STDMETHODIMP CSms::EncSPMS(BSTR Key, BSTR Src, BSTR* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
/*
|
||
//取得User ,Passwd
|
||
char szKey[512]={0};
|
||
char szSrc[512]={0};
|
||
char szRet[512]={0};
|
||
strcpy( szKey , CW2A(Key) );
|
||
strcpy( szSrc , CW2A(Src) );
|
||
|
||
CDES des;
|
||
if ( !des.EncSPMS(szKey,szSrc,szRet) )
|
||
{
|
||
strcpy( szRet , "ERROR" );
|
||
}
|
||
|
||
*pRet = ::SysAllocString(CA2W(szRet));
|
||
*/
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::GetPurview(LONG PurviewType, LONG* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
long lPurview=0;
|
||
|
||
if ( PurviewType == PURVIEWTYPE_INPUT ) //资料录入员
|
||
{
|
||
lPurview = lPurview|PURVIEW_LOGIN|PURVIEW_GADDRESS_SEE|PURVIEW_GADDRESS_MODIFY|PURVIEW_GADDRESS_ADD;
|
||
}
|
||
if ( PurviewType == PURVIEWTYPE_USERS ) //一般员工
|
||
{
|
||
lPurview = lPurview|PURVIEW_LOGIN|PURVIEW_SENDG|PURVIEW_RECVP|PURVIEW_GADDRESS_SEE;
|
||
}
|
||
if ( PurviewType == PURVIEWTYPE_KF ) //客户服务员
|
||
{
|
||
lPurview = lPurview|PURVIEW_LOGIN|PURVIEW_SENDG|PURVIEW_SENDP|PURVIEW_RECVP|PURVIEW_RECVG|PURVIEW_GADDRESS_SEE|PURVIEW_PADDRESS;
|
||
}
|
||
if ( PurviewType == PURVIEWTYPE_ADMIN ) //管理员
|
||
{
|
||
lPurview = -1;
|
||
}
|
||
*pRet = lPurview;
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::HasSWTPre(LONG lSDK, LONG* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
if ( lSDK & SDK_SWT )
|
||
*pRet = 1;
|
||
else
|
||
*pRet = 0;
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::isHasPurview(LONG Purview, LONG AllPurview, LONG* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
if ( AllPurview & Purview )
|
||
*pRet = 1;
|
||
else
|
||
*pRet = 0;
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::SendSms(IDispatch* pAdoConnect, LONG lCorpID, LONG lUserID, LONG lLongSms, LONG lFD, BSTR Timer, BSTR IP, BSTR AddNum, BSTR Recver, BSTR Mobiles, BSTR Msg, LONG* pSendCount)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
//AutoCoInitializeEx AutoCoInit(true); //自动初始化与结束Com环境
|
||
|
||
*pSendCount = 0;
|
||
m_strSendRet=_T("-10,发送异常!");
|
||
|
||
DWORD lSendAllTime = GetTickCount();
|
||
|
||
//m_strSendRet.Format(_T("AdoConnect:%x,CorpID:%d,UserID,%d,longSms,%d,Timer,%s\\nIP=%s\\nMobiles=%s\\nMsg=%s"),pAdoConnect,lCorpID,lUserID,lLongSms,Timer,IP,Mobiles,Msg);
|
||
//return S_OK;
|
||
try
|
||
{
|
||
if (!pAdoConnect)
|
||
{
|
||
m_strSendRet=_T("-11,参数异常!");
|
||
return S_OK;
|
||
}
|
||
//CComQIPtr<_ConnectionPtr> pAdo = pAdoConnect;
|
||
_ConnectionPtr pAdo = pAdoConnect;
|
||
//pAdoConnect->QueryInterface(
|
||
//CAdoConnection adoConnection((_ConnectionPtr)pAdo);
|
||
//CAdoConnection adoc2;
|
||
/*
|
||
if ( !m_AdoConnection.IsOpen() )
|
||
{
|
||
m_AdoConnection.SetConnection(pAdoConnect);
|
||
}
|
||
CString strConnectionString = m_AdoConnection.GetConnectionString();
|
||
if (strConnectionString.GetLength() <= 6)
|
||
{
|
||
m_strSendRet = _T("-15,系统异常1!");
|
||
return S_OK;
|
||
}
|
||
*/
|
||
|
||
TCHAR szName[512] = { 0 };
|
||
GetCurrentPath(szName);
|
||
SC_Setup setup = { 0 };
|
||
CFile file;
|
||
CString strFileName;
|
||
//重复读配置文件,正常的如果有问题就读备份的
|
||
for (int j = 0; j<3; j++)
|
||
{
|
||
strFileName.Format(_T("%s..\\%s"), szName, _T("SmsCenterW.dat"));
|
||
switch (j)
|
||
{
|
||
case 1:
|
||
strFileName.Format(_T("%s..\\%s"), szName, _T("SmsCenterW_b1.dat"));
|
||
break;
|
||
case 2:
|
||
strFileName.Format(_T("%s%s"), szName, _T("SmsCenterW.dat"));
|
||
break;
|
||
}
|
||
if (file.Open(strFileName, CFile::modeRead|CFile::shareDenyNone) )
|
||
{
|
||
if (file.GetLength() > 50)
|
||
break;
|
||
else
|
||
file.Close();
|
||
}
|
||
}
|
||
if (j >= 3)
|
||
{
|
||
//m_strSendRet = _T("-21,打开配置文件异常!");
|
||
//m_strSendRet.Format(_T("-21,打开配置文件异常!%s"),strFileName);
|
||
//return S_OK;
|
||
//读取配置文件不成功,使用原传过来连接
|
||
if (!m_AdoConnection.IsOpen())
|
||
{
|
||
m_AdoConnection.SetConnection(pAdoConnect);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
file.Read(&setup, sizeof(setup));
|
||
file.Close();
|
||
|
||
CString DBServer = setup.szDBName;
|
||
CString DBName = _T("corpsms");
|
||
CString DBUser = setup.szDBUser;
|
||
CString DBProvider = setup.szProvider;
|
||
|
||
//解数据库密码
|
||
char szSrc[64] = { 0 };
|
||
char szUser[64] = { 0 };
|
||
char szTag[64] = { 0 };
|
||
TCHAR szNewPasswd[64] = { 0 };
|
||
long lOut = sizeof(szTag);
|
||
strcpy(szSrc, CW2A(setup.szDBPasswd));
|
||
strcpy(szUser, CW2A(setup.szDBUser));
|
||
CDes des;
|
||
des.Decrypt(szSrc, strlen(szSrc), szTag, lOut, szUser, 8);
|
||
_tcscpy(szNewPasswd, CA2W(szTag));
|
||
CString DBPasswd = szNewPasswd;
|
||
if (!m_AdoConnection.ConnectSQLServer2(DBServer, DBName, DBUser, DBPasswd, DBProvider))
|
||
{
|
||
m_strSendRet = _T("-16,系统异常2,连接数据库失败!");
|
||
return S_OK;
|
||
}
|
||
}
|
||
//m_AdoConnection.SetCursorLocation(adUseServer); //设置为本地游标类型
|
||
|
||
CAdoRecordSet AdoRS;
|
||
CAdoRecordSet AdoRS2;
|
||
AdoRS.SetCursorLocation(adUseClient);//adUseNone adUseServer
|
||
AdoRS.SetCursorLocation(adUseClient);
|
||
AdoRS.SetAdoConnection(&m_AdoConnection);
|
||
AdoRS2.SetAdoConnection(&m_AdoConnection);
|
||
|
||
AdoRS.SetCursorLocation(adUseClient);
|
||
AdoRS2.SetCursorLocation(adUseClient);
|
||
CString str;
|
||
CString strErrMsg;
|
||
CString strMsgID;
|
||
|
||
CString strMsg = Msg;
|
||
CString strIP = IP;
|
||
CString strRecver = Recver;
|
||
CString strAddNum = AddNum;
|
||
BOOL bSDK=false;
|
||
if ( strRecver==CString(_T("WebSDK")) || strRecver == CString(_T("WebSDK2")))
|
||
bSDK = true;
|
||
|
||
if (strMsg.GetLength()<=0 || strMsg.GetLength()>900)
|
||
{
|
||
m_strSendRet=_T("-12,短信内容长度不符合要求!");
|
||
return S_OK;
|
||
}
|
||
//替换签名字符,防止多签名
|
||
|
||
/*
|
||
strMsg.Replace(_T("["), _T("(")); //后面会自动加上括号,现去掉。
|
||
strMsg.Replace(_T("]"), _T(")"));
|
||
strMsg.Replace(_T("【"), _T("(")); //后面会自动加上括号,现去掉。
|
||
strMsg.Replace(_T("】"), _T(")"));
|
||
*/
|
||
|
||
BOOL bEnableXY=false; //是否启用信易发送
|
||
|
||
BOOL bAtTime=false;
|
||
COleDateTime tTimer;
|
||
CString strTimer = Timer;
|
||
strTimer.Replace(_T("/") , _T("-"));
|
||
try
|
||
{
|
||
tTimer.ParseDateTime(strTimer);
|
||
}
|
||
catch(...)
|
||
{
|
||
}
|
||
|
||
CString strSelect;
|
||
//取通道
|
||
TCHAR szSmsTD[32]={0};
|
||
//取签名
|
||
CString strCM;
|
||
long lFStep=1; //默认为1级
|
||
long lSmsFStep = 99; //审核起点
|
||
strSelect.Format(_T("select * from corp with(nolock) where corpid=%d") , lCorpID );
|
||
if ( AdoRS.Open(strSelect) && !AdoRS.IsEOF() )
|
||
{
|
||
AdoRS.GetCollect(_T("cm") , strCM );
|
||
AdoRS.GetCollect(_T("FStep"),lFStep);
|
||
AdoRS.GetCollect(_T("FiltStep"), lSmsFStep);
|
||
AdoRS.GetCollect( _T("SMSTD") , szSmsTD ); _tcscat(szSmsTD,_T("000000")); //取得短信通道
|
||
DWORD dwCorpSDK=0;
|
||
AdoRS.GetCollect(_T("SDK") , dwCorpSDK ); //SDK
|
||
if ( dwCorpSDK & SDK_XY ) //是否有信易权限
|
||
{
|
||
bEnableXY = true;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
long lCorpID2 = 0;
|
||
strSelect.Format(_T("select * from users with(nolock) where userid=%d") , lUserID );
|
||
if ( AdoRS.Open(strSelect) && !AdoRS.IsEOF() )
|
||
{
|
||
AdoRS.GetCollect(_T("CorpID") , lCorpID2 );
|
||
if ( lCorpID2 != lCorpID )
|
||
{
|
||
m_strSendRet=_T("-13,企业ID与用户ID不对应,发送停止!");
|
||
return S_OK;
|
||
}
|
||
CString strCM2;
|
||
AdoRS.GetCollect(_T("cm2") , strCM2 );
|
||
if ( strCM2.GetLength()>0 )
|
||
strCM = strCM2;
|
||
}
|
||
|
||
|
||
if (strCM==CString(_T("+"))) //签名为+号时,可以自由签名,但只能发送已报备签名
|
||
{
|
||
//查找签名
|
||
CString strGetCM;
|
||
long lMsgLen = strMsg.GetLength();
|
||
if (lMsgLen > 1 && strMsg.Left(1) == CString(_T("【"))) //短信内容长度大于1,并且以【开头。
|
||
{
|
||
for (int i = 1; i < lMsgLen && i < 20; i++)
|
||
{
|
||
if (strMsg.Mid(i, 1) == CString(_T("】")))
|
||
{
|
||
strGetCM = strMsg.Mid(1, i - 1);
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
if (strGetCM.GetLength() >= 2)
|
||
{
|
||
strSelect.Format(_T("select * from SignName with(nolock) where corpid=%d and SignName='%s' and status=1"), lCorpID, SqlStr(strGetCM));
|
||
if (AdoRS.Open(strSelect) && AdoRS.IsEOF())
|
||
{
|
||
m_strSendRet = _T("-17,签名未报备或签名未审核通过!");
|
||
return S_OK;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_strSendRet = _T("-17,签名未报备或签名未审核通过!");
|
||
return S_OK;
|
||
}
|
||
strCM=CString( _T("")); //+号签名置为空。
|
||
}
|
||
|
||
|
||
//是否需要审核
|
||
BOOL bFilt=false;
|
||
strSelect.Format(_T("select * from filt where FStep>=%d and CHARINDEX(word,'%s')>0") , lFStep,SqlStr(strMsg) );
|
||
if ( AdoRS.Open(strSelect) && !AdoRS.IsEOF() )
|
||
{
|
||
bFilt = 1;
|
||
|
||
//m_strSendRet=_T("-101,发送内容异常,发送停止!");
|
||
//return S_OK;
|
||
}
|
||
if (!bFilt) //不需要审核的,缩减空格后再判断关键字
|
||
{
|
||
long lSrcLen = strMsg.GetLength();
|
||
CString strNoSpace = strMsg;
|
||
strNoSpace.Replace(_T(" "), _T(""));
|
||
strNoSpace.Replace(_T(" "), _T(""));
|
||
long lNoSpaceLen = strNoSpace.GetLength();
|
||
if (lFStep<3 && (lSrcLen - lNoSpaceLen >4) ) //超过2个空格,需要审核了
|
||
{
|
||
bFilt = 1;
|
||
}
|
||
if (!bFilt && (lSrcLen - lNoSpaceLen >2 )) //不需要审核的,缩减空格后再判断关键字
|
||
{
|
||
strSelect.Format(_T("select * from filt where FStep>=%d and CHARINDEX(word,'%s')>0"), lFStep, SqlStr(strNoSpace));
|
||
if (AdoRS.Open(strSelect) && !AdoRS.IsEOF())
|
||
{
|
||
bFilt = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
//判断手机号码个数是否超量
|
||
CString strMobiles = Mobiles;
|
||
long lMobiles = strMobiles.GetLength() / 12;
|
||
if (!bSDK && (lMobiles >= lSmsFStep || lMobiles>=10) )
|
||
{
|
||
bFilt = 1;
|
||
}
|
||
if ( bSDK && strRecver == CString(_T("WebSDK")) && lMobiles>58) //如果是SDK1,当数量大于50个时,也是需要审核的。
|
||
{
|
||
bFilt = 1;
|
||
}
|
||
if (strRecver == CString(_T("WebF")))
|
||
{
|
||
bFilt = 1;
|
||
}
|
||
if ( lSmsFStep == 5185 || lSmsFStep == 51850 ) //发送级别518,这个是特殊的免审核标志
|
||
{
|
||
bFilt = 0;
|
||
}
|
||
|
||
#ifdef SMSCENTER_DGSB //东莞社保
|
||
bFilt = 0;
|
||
#endif
|
||
|
||
//判断是否为号段发送,需要审核
|
||
/*
|
||
if ( true )
|
||
{
|
||
CString strMobiles = Mobiles;
|
||
strMobiles+=CString(_T(",")); //最后加多一条空记录
|
||
long lLen = strMobiles.GetLength();
|
||
TCHAR szMobile[32]={0};
|
||
long lMobileLen=0;
|
||
CStringSort sort;
|
||
for ( int i=0 ; i<lLen ; i++ )
|
||
{
|
||
TCHAR c = strMobiles.GetAt(i);
|
||
if ( c=='\r' || c=='\n' || c=='\t'
|
||
|| c==';' || c==';'
|
||
|| c==',' || c==','
|
||
|| c=='.' || c=='。'
|
||
|| c==':' || c==':'
|
||
|| c==' ' || c==' '
|
||
|| i == lLen-1)
|
||
{
|
||
if ( lMobileLen>=9 && lMobileLen<=18 ) //正常的号码长度
|
||
{
|
||
TCHAR szBuf[32]={0};
|
||
_tcscpy(szBuf , szMobile);
|
||
CSendPub::ExMobileGZM(szBuf);
|
||
if ( CSendPub::isNumSup2(szBuf) )
|
||
{
|
||
sort.Add(szBuf,true);
|
||
lMobileLen = 0; //断行过后,重新开始
|
||
memset(szMobile , 0 , sizeof(szMobile));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lMobileLen = 0; //断行过后,重新开始
|
||
memset(szMobile , 0 , sizeof(szMobile));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ( c>='0' && c<='9' && lMobileLen<19 )
|
||
{
|
||
szMobile[lMobileLen] = c;
|
||
lMobileLen ++;
|
||
}
|
||
}
|
||
}
|
||
//拦截规则:
|
||
//连接号码超10条
|
||
//9位号段超30条
|
||
//8位号段超300条
|
||
long lLX1=10;
|
||
long lLX2=30;
|
||
long lLX3=300;
|
||
|
||
BOOL bLX = false;
|
||
long lMobileCount2=sort.GetCount();
|
||
LONGLONG lLXOldMobile1=0;
|
||
LONGLONG lLXOldMobile2=0;
|
||
LONGLONG lLXOldMobile3=0;
|
||
long lLXCount1=0;
|
||
long lLXCount2=0;
|
||
long lLXCount3=0;
|
||
for ( int i=0 ; i<lMobileCount2 ; i++ )
|
||
{
|
||
CString strMobile = sort.GetAt(i);
|
||
|
||
//判断连接号码
|
||
if ( (LONGLONG)(_ttof(strMobile)) != lLXOldMobile1+1 )
|
||
{
|
||
lLXCount1 = 0;
|
||
lLXOldMobile1 = (LONGLONG)(_ttof(strMobile));
|
||
}
|
||
else
|
||
{
|
||
lLXOldMobile1 = lLXOldMobile1+1;
|
||
lLXCount1 += 1;
|
||
if ( lLXCount1 >= lLX1 )
|
||
{
|
||
bLX = true;
|
||
break;
|
||
}
|
||
}
|
||
//判断前9位号码
|
||
if ( (LONGLONG)(_ttol(strMobile)/1000000000) != lLXOldMobile2 )
|
||
{
|
||
lLXCount2 = 0;
|
||
lLXOldMobile2 = (long)(_ttol(strMobile)/1000000000);
|
||
}
|
||
else
|
||
{
|
||
lLXCount2 += 1;
|
||
if ( lLXCount2 >= lLX2 )
|
||
{
|
||
bLX = true;
|
||
break;
|
||
}
|
||
}
|
||
//判断前8位号码
|
||
if ( (LONGLONG)(_ttol(strMobile)/100000000) != lLXOldMobile3 )
|
||
{
|
||
lLXCount3 = 0;
|
||
lLXOldMobile3 = (long)(_ttol(strMobile)/100000000);
|
||
}
|
||
else
|
||
{
|
||
lLXCount3 += 1;
|
||
if ( lLXCount3 >= lLX3 )
|
||
{
|
||
bLX = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if ( bLX )
|
||
{
|
||
bFilt = 1;
|
||
|
||
m_strSendRet=_T("-101,不能按号段进行发送,发送停止!");
|
||
return S_OK;
|
||
}
|
||
}
|
||
*/
|
||
//先将内容分段
|
||
//计算分段
|
||
CStringArray saMsg;
|
||
//判断是否需要分段发送
|
||
TCHAR szSrcMsg[2048]={0};
|
||
_tcscpy(szSrcMsg , strMsg);
|
||
|
||
long lMsgAll=0;
|
||
long lMsgIndex = 1;
|
||
BOOL bGetMsg2;
|
||
TCHAR szSendMsg1[512]={0};
|
||
TCHAR szSendMsg2[512]={0};
|
||
long lMaxSendLen = MSG_MAXSENDLEN;
|
||
|
||
long lZDCMLen = 0;
|
||
#if defined(SMSCENTER_NX) && !defined(SMSCENTER_GDDX) //农信自带签名6个字
|
||
lZDCMLen = 6;
|
||
#endif
|
||
#if defined(SMSCENTER_NX) && defined(SMSCENTER_DGSB) //社保局的签名字数是7个字
|
||
lZDCMLen = 6; //签名是【东莞人社】
|
||
#endif
|
||
ANS_GetTD2Data td={0};
|
||
if ( CSendPub::GetTDPro(&AdoRS,szSmsTD,td,MOBILE_TYPE_CMCC)) //取此企业所设置的通道属性,看是否要缩减字数
|
||
{
|
||
if ( td.lContentLen>10 && td.lContentLen<70 )
|
||
lZDCMLen = MSG_MAXSENDLEN-td.lContentLen;
|
||
}
|
||
lMaxSendLen = lMaxSendLen-lZDCMLen;
|
||
|
||
long lSignLen = 0;
|
||
#ifdef UNICODE
|
||
lSignLen = _tcslen(strCM);
|
||
#else
|
||
lSignLen = MultiByteToWideChar( CP_ACP,NULL,userPro.szCM,_tcslen(userPro.szCM), NULL,0);
|
||
#endif
|
||
if ( lSignLen>0 )
|
||
lSignLen = lSignLen+2; //加上括号
|
||
long lMsgLen =0;
|
||
#ifdef UNICODE
|
||
lMsgLen = _tcslen(szSrcMsg);
|
||
#else
|
||
lMsgLen = MultiByteToWideChar( CP_ACP,NULL,szSrcMsg,_tcslen(szSrcMsg), NULL,0);
|
||
#endif
|
||
//判断是否以长短信方式发送
|
||
BOOL bLongSms=false;
|
||
if ( lLongSms>0 )
|
||
bLongSms = true;
|
||
//判断是否以分段方式发送
|
||
BOOL bFD=false;
|
||
/*
|
||
if ( lFD>0 && !bLongSms) //不是长短信才能分段
|
||
bFD = true;
|
||
*/
|
||
//暂时不启用分段功能。lFD这个字段用于签名前置
|
||
|
||
BOOL bSignFront = false;
|
||
if (lFD > 0)
|
||
bSignFront = true;
|
||
|
||
long lRand=0; //随机数,长短信有用
|
||
if ( lMsgLen+lSignLen<=lMaxSendLen ) //字数还不足一条,即使是长短信方式与是普通短信
|
||
{
|
||
bLongSms = false;
|
||
bFD = false;
|
||
}
|
||
if ( bLongSms && lSignLen>0) //以长短信方式发送,最后加签名
|
||
{
|
||
/*
|
||
if (bSignFront) //签名前置
|
||
{
|
||
CString strSignTemp;
|
||
strSignTemp.Format(_T("[%s]%s"), strCM, szSrcMsg);
|
||
_tcscpy(szSrcMsg, strSignTemp);
|
||
}
|
||
else
|
||
{
|
||
_tcscat(szSrcMsg, _T("["));
|
||
_tcscat(szSrcMsg, strCM);
|
||
_tcscat(szSrcMsg, _T("]"));
|
||
}
|
||
*/
|
||
//统一前置签名
|
||
CString strSignTemp;
|
||
strSignTemp.Format(_T("【%s】%s"), strCM, szSrcMsg);
|
||
_tcscpy(szSrcMsg, strSignTemp);
|
||
}
|
||
if ( !bLongSms ) //如果不是长短信,第条都要签名,所以每条短信减签名字数
|
||
{
|
||
lMaxSendLen = lMaxSendLen-lSignLen;
|
||
if ( bFD )
|
||
lMaxSendLen = lMaxSendLen-4; //分段标识
|
||
}
|
||
else
|
||
{
|
||
lMaxSendLen = MSG_MAXSENDLEN-3;
|
||
}
|
||
while ( true )
|
||
{
|
||
memset( szSendMsg2 , 0 , sizeof(szSendMsg2) );
|
||
//if ( isChinese( szSrcMsg,_tcslen(szSrcMsg) ) )
|
||
//{
|
||
bGetMsg2 = GetSpiltUnicodeMsg( szSrcMsg , szSendMsg1 , lMsgIndex , lMaxSendLen ,lMsgAll);
|
||
//}
|
||
//else
|
||
//{
|
||
// bGetMsg2 = GetSpiltAsciiMsg( szSrcMsg , szSendMsg2 , lMsgIndex , MSG_MAXSENDLEN*2+MSG_MAXSENDLEN*2/7 ,lMsgAll);
|
||
//}
|
||
if ( bGetMsg2 )
|
||
{
|
||
if ( !bLongSms && lSignLen>0 ) //不是长短信,需要加签名
|
||
{
|
||
/*
|
||
if (bSignFront) //签名前置
|
||
{
|
||
CString strSignTemp;
|
||
strSignTemp.Format(_T("[%s]%s"), strCM, szSendMsg1);
|
||
_tcscpy(szSendMsg1, strSignTemp);
|
||
}
|
||
else
|
||
{
|
||
_tcscat(szSendMsg1, _T("["));
|
||
_tcscat(szSendMsg1, strCM);
|
||
_tcscat(szSendMsg1, _T("]"));
|
||
}
|
||
*/
|
||
//统一前置签名
|
||
CString strSignTemp;
|
||
strSignTemp.Format(_T("【%s】%s"), strCM, szSendMsg1);
|
||
_tcscpy(szSendMsg1, strSignTemp);
|
||
}
|
||
saMsg.Add(szSendMsg1);
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
lMsgIndex ++;
|
||
}
|
||
|
||
if ( lZDCMLen >0 ) //有自带签名
|
||
{
|
||
if ( bLongSms && saMsg.GetSize()>0)
|
||
{
|
||
strSelect = saMsg.GetAt(saMsg.GetSize()-1); //最后一条内容
|
||
|
||
#ifdef UNICODE
|
||
lMsgLen = _tcslen(strSelect);
|
||
#else
|
||
lMsgLen = MultiByteToWideChar( CP_ACP,NULL,strSelect,_tcslen(strSelect), NULL,0);
|
||
#endif
|
||
|
||
if ( lMsgLen>lMaxSendLen-lZDCMLen )
|
||
{
|
||
saMsg.Add(CString(_T(" "))); //加多一条内容用于签名
|
||
}
|
||
}
|
||
}
|
||
|
||
lMsgAll = saMsg.GetSize();
|
||
if ( lMsgAll<=0 || lMsgAll>=15 )
|
||
{
|
||
m_strSendRet.Format(_T("-14,短信内容长度不符合要求,%d条!"),lMsgAll);
|
||
return S_OK;
|
||
}
|
||
/*
|
||
//以下启用信易发送
|
||
CSqlPool XYSqlPool; //用于信易判断号码是否开通
|
||
TCHAR buf[MAX_PATH+1];
|
||
DWORD res = GetModuleFileName(AfxGetInstanceHandle(), buf, MAX_PATH);
|
||
int j=lstrlen(buf);
|
||
int iXCount=0;
|
||
for ( ; j>0 ; j-- )
|
||
{
|
||
if (buf[j]=='\\' )
|
||
{
|
||
iXCount ++;
|
||
if ( iXCount>=2)
|
||
break;
|
||
}
|
||
}
|
||
if ( j>0 )
|
||
buf[j+1]=0;
|
||
_tcscat( buf , _T("XYSerup.xml") );
|
||
|
||
CMarkup xml;
|
||
if ( xml.Load(buf) )
|
||
{
|
||
CString strEnable,strSQLServer,strSQLDB,strSQLUser,strSQLPasswd,strSQLMaxConnection;
|
||
if ( xml.FindElem(_T("/Setup/Enable")) )
|
||
strEnable = xml.GetData();
|
||
if ( xml.FindElem(_T("/Setup/XYServer/DBServer")) )
|
||
strSQLServer = xml.GetData();
|
||
if ( xml.FindElem(_T("/Setup/XYServer/DBName")) )
|
||
strSQLDB=xml.GetData();
|
||
if ( xml.FindElem(_T("/Setup/XYServer/DBUser")) )
|
||
strSQLUser=xml.GetData();
|
||
if ( xml.FindElem(_T("/Setup/XYServer/DBPasswd")) )
|
||
strSQLPasswd=xml.GetData();
|
||
if ( xml.FindElem(_T("/Setup/XYServer/MaxConnection")) )
|
||
strSQLMaxConnection=xml.GetData();
|
||
BOOL bEnable = _ttol(strEnable);
|
||
long lSqlCount=_ttol(strSQLMaxConnection);
|
||
if ( lSqlCount<1 || lSqlCount>20 )
|
||
lSqlCount=5;
|
||
XYSqlPool.SetTimeOut(5,5);//设置超时时间,极短。
|
||
if (bEnable && XYSqlPool.Init(lSqlCount,strSQLServer,strSQLUser,strSQLPasswd,strSQLDB))
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
bEnableXY=false;
|
||
}
|
||
|
||
}
|
||
*/
|
||
|
||
//InitRand(); //初始化随机数,防止重复
|
||
|
||
long lMaxSendCount=50; //每次最多发送50条
|
||
|
||
//long lZDSmsCount=lMsgAll * lMaxSendCount; //计算应该扣费条数
|
||
long lSendCount = lMaxSendCount * lMsgAll;
|
||
ANS_SendData2 * pSmsData = new ANS_SendData2[lSendCount];
|
||
memset(pSmsData , 0 , sizeof(ANS_SendData2)*lSendCount);
|
||
|
||
//用于记录最后一条的位置
|
||
long * pSmsIDIndex = new long[lMaxSendCount];
|
||
memset(pSmsIDIndex , 0,sizeof(long)*lMaxSendCount);
|
||
|
||
//取手机号码
|
||
/*CString*/ strMobiles = Mobiles;
|
||
strMobiles+=CString(_T(",")); //最后加多一条空记录
|
||
long lLen = strMobiles.GetLength();
|
||
TCHAR szMobile[32]={0};
|
||
long lMobileLen=0;
|
||
long lMobileAllCount=0;
|
||
long lMobileCount=0;
|
||
long lMobileIndex=0;
|
||
long lMsgIDCount=0;
|
||
BOOL bSendBreak=false;
|
||
for ( int i=0 ; i<lLen ; i++ )
|
||
{
|
||
TCHAR c = strMobiles.GetAt(i);
|
||
if ( c=='\r' || c=='\n' || c=='\t'
|
||
|| c==';' || c==';'
|
||
|| c==',' || c==','
|
||
|| c=='.' || c=='。'
|
||
|| c==':' || c==':'
|
||
|| c==' ' || c==' '
|
||
|| i == lLen-1)
|
||
{
|
||
if ( lMobileLen>=9 && lMobileLen<=18 ) //正常的号码长度
|
||
{
|
||
TCHAR szBuf[32]={0};
|
||
_tcscpy(szBuf , szMobile);
|
||
CSendPub::ExMobileGZM(szBuf);
|
||
if ( CSendPub::isNumSup2(szBuf) )
|
||
{
|
||
pSmsData[lMobileIndex].lCorpID = lCorpID;
|
||
pSmsData[lMobileIndex].lUserID = lUserID;
|
||
if ( bFilt ) //需要审核的短信
|
||
pSmsData[lMobileIndex].lStatus = SEND_STATUS_SUB_FILT;
|
||
_tcsncpy( pSmsData[lMobileIndex].szSendNum , strAddNum ,10); //扩展号
|
||
_tcscpy( pSmsData[lMobileIndex].szMobile , szBuf );
|
||
_tcscpy( pSmsData[lMobileIndex].szName , strRecver );
|
||
if ( tTimer.GetStatus() == COleDateTime::valid ) //定时时间
|
||
{
|
||
tTimer.GetAsSystemTime(pSmsData[lMobileIndex].tTimer );
|
||
}
|
||
|
||
lRand = rand()%254;
|
||
if ( lRand<0 )
|
||
lRand=-lRand;
|
||
for ( int h=1 ; h<=lMsgAll ; h++ )
|
||
{
|
||
if ( h>1 )
|
||
{
|
||
pSmsData[lMobileIndex] = pSmsData[lMobileIndex-1]; //多条内容的情况,除短信内容外复制前一个数组的其它数据
|
||
}
|
||
if ( bLongSms )
|
||
{
|
||
_stprintf( pSmsData[lMobileIndex].szMsg , _T("长信%02X%X%X:%s") , lRand,lMsgAll,h,saMsg.GetAt(h-1));
|
||
}
|
||
else
|
||
{
|
||
if ( bFD )
|
||
_stprintf( pSmsData[lMobileIndex].szMsg , _T("%X/%X:%s") , h,lMsgAll,saMsg.GetAt(h-1));
|
||
else
|
||
_tcscpy(pSmsData[lMobileIndex].szMsg , saMsg.GetAt(h-1) );
|
||
|
||
}
|
||
pSmsData[lMobileIndex].tOvrTime.wSecond = lRand;
|
||
pSmsData[lMobileIndex].tOvrTime.wDayOfWeek =(WORD)(h*100+lMsgAll);
|
||
|
||
lMobileIndex ++;
|
||
if ( lMobileIndex >= lSendCount )
|
||
break;
|
||
}
|
||
pSmsIDIndex[lMobileCount] = lMobileIndex-1; //记录每条短信最后的位置
|
||
|
||
lMobileCount ++;
|
||
lMobileAllCount ++;
|
||
}
|
||
}
|
||
lMobileLen = 0; //断行过后,重新开始
|
||
memset(szMobile , 0 , sizeof(szMobile));
|
||
if ( lMobileCount>=lMaxSendCount || i== lLen-1 ) //每次发50条
|
||
{
|
||
//开始发送短信
|
||
CSendPub::SendPub_Mms Sms={0};
|
||
|
||
Sms.lCorpID = lCorpID;
|
||
Sms.lUserID = lUserID;
|
||
if ( tTimer.GetStatus() == COleDateTime::valid ) //定时时间
|
||
{
|
||
tTimer.GetAsSystemTime(Sms.tTimer );
|
||
}
|
||
_tcscpy(Sms.szIP , strIP);
|
||
Sms.lPriority = 0; //由SubmitMms计算优先级
|
||
if ( Sms.lPriority>10 )
|
||
{
|
||
if ( bSDK )
|
||
Sms.lSendCount = 2000+Sms.lPriority*500; //接口发送的,5000起点
|
||
else
|
||
Sms.lSendCount = 10000+Sms.lPriority*500; //接口发送的,5000起点
|
||
}
|
||
|
||
//Sms.lPriority = 0; //由SubmitMms计算优先级
|
||
Sms.lSendCount = lMobileAllCount; //总短信发送量,用于计算发送条数
|
||
//Sms.tTimer = pSendData->tTimer;
|
||
Sms.bFirstCheckYE = true; //预先检查余额,余额不足时不发送
|
||
if ( bSDK )
|
||
Sms.bWebReq = true;
|
||
|
||
/*
|
||
Sms.XY.bEnableXY = false;
|
||
if ( bEnableXY)
|
||
{
|
||
Sms.XY.bEnableXY = true;
|
||
Sms.XY.pSQLPool = &XYSqlPool;
|
||
}
|
||
*/
|
||
|
||
long lRet = CSendPub::SubmitSms(Sms, pSmsData,lMobileIndex,strErrMsg,&AdoRS,&AdoRS2);
|
||
|
||
if ( lRet>0 )
|
||
{
|
||
*pSendCount = *pSendCount + lRet;
|
||
if ( bSDK )
|
||
{
|
||
//以下为取最后一条短信的ID
|
||
for ( int i=0 ; i<lMobileCount ; i++ )
|
||
{
|
||
if ( pSmsIDIndex[i]>=0 && pSmsIDIndex[i]<lMobileIndex )
|
||
{
|
||
long lSmsID = pSmsData[pSmsIDIndex[i]].lSendID;
|
||
str.Format(_T("%d") , lSmsID);
|
||
if ( strMsgID.GetLength()>0 )
|
||
strMsgID=strMsgID+CString(_T(","))+str;
|
||
else
|
||
strMsgID = str;
|
||
|
||
lMsgIDCount ++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bSendBreak = true; //发送中断
|
||
break;
|
||
}
|
||
|
||
lMobileCount = 0;
|
||
lMobileIndex = 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ( c>='0' && c<='9' && lMobileLen<19 )
|
||
{
|
||
szMobile[lMobileLen] = c;
|
||
lMobileLen ++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if ( bSendBreak )
|
||
{
|
||
if ( bSDK )
|
||
m_strSendRet.Format(_T("%d,%s:%s"),lMsgIDCount,strMsgID,strErrMsg);
|
||
else
|
||
m_strSendRet.Format(_T("发送短信完成,共提交%d条。\\n异常信息:%s") , *pSendCount,strErrMsg);
|
||
}
|
||
else
|
||
{
|
||
if ( bSDK )
|
||
m_strSendRet.Format(_T("%d,%s"),lMsgIDCount,strMsgID);
|
||
else
|
||
m_strSendRet.Format(_T("发送短信完成,共提交%d条。") , *pSendCount);
|
||
}
|
||
|
||
AdoRS.Close();
|
||
AdoRS2.Close();
|
||
|
||
#ifndef SMSCENTER_DGSB
|
||
if (strRecver != CString(_T("WebSDK")) && strRecver != CString(_T("WebSDK2")) && strRecver != CString(_T("WebF")) && strRecver != CString(_T("Web3")))
|
||
{
|
||
//每调用一个请求,至少要等40秒
|
||
while (GetTickCount() - lSendAllTime < 1 * 1000)
|
||
{
|
||
Sleep(100);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
delete pSmsData;
|
||
delete pSmsIDIndex;
|
||
return S_OK;
|
||
}
|
||
catch(...)
|
||
{
|
||
*pSendCount = -2;
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::get_SendRet(BSTR* pVal)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
*pVal = ::SysAllocString(m_strSendRet);
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::put_SendRet(BSTR newVal)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
// TODO: 在此添加实现代码
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::SendSms_Excel(IDispatch* pAdoConnect, LONG lCorpID, LONG lUserID, LONG lLongSms,LONG lFD, BSTR Timer2, BSTR IP, BSTR ExcelFileName, LONG* lSendCount)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
*lSendCount = 0;
|
||
try
|
||
{
|
||
CAdoConnection adoConnection;
|
||
CAdoRecordSet AdoRS;
|
||
|
||
if ( !adoConnection.ConnectExcel(ExcelFileName) )
|
||
{
|
||
m_strSendRet.Format(_T("连接Excel文件失败,%s"),ExcelFileName);
|
||
return S_OK;
|
||
}
|
||
AdoRS.SetAdoConnection(&adoConnection);
|
||
CString str;
|
||
str = _T("select * from [Sheet1$]");
|
||
AdoRS.Open(str);
|
||
while(!AdoRS.IsEOF() )
|
||
{
|
||
|
||
|
||
AdoRS.MoveNext();
|
||
}
|
||
}
|
||
catch(...)
|
||
{
|
||
*lSendCount = -2;
|
||
return S_OK;
|
||
}
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
STDMETHODIMP CSms::CorpSmsHttpReq(BSTR pReq, BSTR pIPAddr, BSTR pReqVer, BSTR* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
CString REQHEAD1=_T("MOBSETGATEWAY001");
|
||
CString REQHEAD2=_T("MOBSETGATEWAY002");
|
||
CString SMS_PIPE=_T("\\\\.\\PIPE\\SMSPIPE");
|
||
if ( CString(pReqVer) == CString(_T("W")) )
|
||
SMS_PIPE=_T("\\\\.\\PIPE\\SMSPIPEW");
|
||
|
||
|
||
long lLen = SysStringLen(pReq)*2+2048;
|
||
TCHAR * szReq = new TCHAR[lLen];
|
||
char * szReq2= new char[lLen];
|
||
memset(szReq,0,lLen);
|
||
memset(szReq2,0,lLen);
|
||
_tcscpy(szReq , pReq);//取得请求头
|
||
|
||
TCHAR szReqHead[128]={0};
|
||
CString strRet;
|
||
//strcpy( szRet , "ERROR" );
|
||
strRet.Format(_T("ERROR:Len=%d"),lLen-32);
|
||
|
||
long lSendCount=0; //取需要发送的字节数
|
||
long lReqVer=1;
|
||
if ( !_tcsncmp(szReq,REQHEAD1,_tcslen(REQHEAD1)) ) //判断是否正常的头
|
||
{
|
||
_tcscpy(szReqHead,REQHEAD1);
|
||
lReqVer = 1; //第一版
|
||
lSendCount = HexToAsciiA(szReq+_tcslen(szReqHead),szReq2);
|
||
}
|
||
else
|
||
if ( !_tcsncmp(szReq,REQHEAD2,_tcslen(REQHEAD2)) ) //判断是否正常的头
|
||
{
|
||
_tcscpy(szReqHead,REQHEAD2);
|
||
lReqVer = 2; //第二版
|
||
|
||
TCHAR szTemp[64]={0};
|
||
_tcsncpy(szTemp,szReq+_tcslen(szReqHead),10);
|
||
long lSendCount2 = _ttol(szTemp)/2;
|
||
lSendCount = HexToAsciiA(szReq+_tcslen(szReqHead)+10,szReq2);
|
||
if ( lSendCount2 != lSendCount )
|
||
memset(szReqHead,0,sizeof(szReqHead));
|
||
}
|
||
if ( _tcslen(szReqHead)>2 )
|
||
{
|
||
|
||
//连接管道
|
||
if (WaitNamedPipe(SMS_PIPE, 2000))
|
||
//if ( true )
|
||
{
|
||
HANDLE hPipe=CreateFile(SMS_PIPE,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
||
if(hPipe!=INVALID_HANDLE_VALUE)
|
||
{
|
||
//DWORD dwMode=PIPE_TYPE_BYTE|PIPE_NOWAIT;
|
||
//SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL); //设成非阻赛模式
|
||
//将消息发送出去
|
||
tagPipeSend PipeSend={0};
|
||
_tcscpy(PipeSend.szIP , pIPAddr);
|
||
PipeSend.lDataLen = lSendCount;
|
||
DWORD dwWrite=0;
|
||
WriteFile(hPipe, &PipeSend, sizeof(PipeSend), &dwWrite, NULL);
|
||
|
||
//发送数据
|
||
long lWrite=0;
|
||
DWORD dwTime2 = ::GetTickCount();
|
||
while ( true )
|
||
{
|
||
WriteFile(hPipe,szReq2+lWrite,lSendCount-lWrite,&dwWrite,NULL);
|
||
lWrite=lWrite+dwWrite;
|
||
if ( lWrite>=lSendCount )
|
||
break;
|
||
Sleep(20);
|
||
if ( ::GetTickCount() - dwTime2 > 50000 ) //30秒接收不到数据,返回超时
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
//WriteFile(hPipe, szReq2, lSendCount, &dwWrite, NULL);
|
||
|
||
//读取返回信息
|
||
memset(&PipeSend,0,sizeof(PipeSend));
|
||
long lRecvAllLen=0;
|
||
long lRecvLen=0;
|
||
BYTE * pData=NULL;
|
||
DWORD dwTime = ::GetTickCount();
|
||
DWORD dwRead=0;
|
||
while ( true )
|
||
{
|
||
dwRead=0;
|
||
if ( lRecvAllLen==0 ) //读总长度
|
||
{
|
||
if ( ReadFile(hPipe,((char*)&PipeSend)+lRecvLen,sizeof(PipeSend)-lRecvLen,&dwRead,NULL)) //取得数据的长度
|
||
{
|
||
lRecvLen = lRecvLen + dwRead;
|
||
if ( lRecvLen == sizeof(PipeSend) )
|
||
{
|
||
lRecvAllLen = PipeSend.lDataLen;
|
||
if ( lRecvAllLen<=0 ) //接收到的数据有误
|
||
{
|
||
strRet += CString(_T("ERR:RecvRetError"));
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if ( pData )
|
||
delete pData;
|
||
pData = new BYTE[lRecvAllLen+2048];
|
||
memset(pData,0,lRecvAllLen+2048);
|
||
}
|
||
lRecvLen = 0;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ( ReadFile(hPipe,pData+lRecvLen,lRecvAllLen-lRecvLen,&dwRead,NULL)) //取得数据的长度
|
||
{
|
||
lRecvLen = lRecvLen + dwRead;
|
||
if ( lRecvLen == lRecvAllLen )
|
||
{
|
||
//发送返回数据
|
||
long lRetSize=_tcslen(szReqHead)+lRecvAllLen+32;
|
||
TCHAR * pRetH=new TCHAR[lRetSize*2];memset(pRetH,0,sizeof(TCHAR)*lRetSize*2);
|
||
TCHAR * pRetH2=pRetH;
|
||
_tcscpy(pRetH2,szReqHead);pRetH2=pRetH2+_tcslen(szReqHead);
|
||
|
||
AsciiToHexW((char*)pData,pRetH2,lRecvAllLen);
|
||
#ifdef _DEBUG
|
||
CString strFileName;
|
||
strFileName.Format(_T("d:\\Http_Ret_%d.txt"),GetTickCount());
|
||
CFile file(strFileName , CFile::modeCreate|CFile::modeReadWrite);
|
||
file.Write(CW2A(pRetH) , strlen(CW2A(pRetH)));
|
||
file.Close();
|
||
#endif
|
||
*pRet = ::SysAllocString(pRetH);
|
||
|
||
if ( pData )
|
||
delete pData;
|
||
delete pRetH;
|
||
delete szReq;
|
||
delete szReq2;
|
||
return S_OK;
|
||
|
||
}
|
||
}
|
||
}
|
||
Sleep(50);
|
||
//if ( ::GetTickCount() - dwTime >35000 ) //35秒内接收不到数据,超时
|
||
if ( ::GetTickCount() - dwTime >35000 ) //35秒内接收不到数据,超时
|
||
{
|
||
strRet = strRet + _T("ERR:TimeOut");
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
if ( pData )
|
||
delete pData;
|
||
}
|
||
else
|
||
{
|
||
DWORD dw=::GetLastError();
|
||
strRet.Format(_T("ERR:Pipe02,%d"),dw);
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
strRet = _T("ERR:Pipe01");
|
||
}
|
||
}
|
||
|
||
|
||
*pRet = ::SysAllocString(strRet);
|
||
delete szReq;
|
||
delete szReq2;
|
||
|
||
return S_OK;
|
||
}
|
||
|
||
|
||
|
||
|
||
STDMETHODIMP CSms::CheckPasswd3(LONG CorpID, BSTR User, BSTR Passwd, BSTR TimeStamp, BSTR Encrypt, LONG Purview, BSTR* pRet)
|
||
{
|
||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||
|
||
CString strRet;
|
||
|
||
|
||
//取得User ,Passwd
|
||
char szUser[64] = { 0 };
|
||
char szPasswd[128] = { 0 };
|
||
char szPasswd2[128] = { 0 };
|
||
char szEncrypt[128] = { 0 };
|
||
TCHAR szPasswdU2[128] = { 0 };
|
||
strcpy(szUser, CW2A(User));
|
||
strcpy(szPasswd, CW2A(Passwd));
|
||
strcpy(szEncrypt, CW2A(Encrypt));
|
||
|
||
CDes des;
|
||
long lOut = sizeof(szPasswd2);
|
||
des.Decrypt(szEncrypt, (long)strlen(szEncrypt), szPasswd2, lOut, szUser, 8);
|
||
_tcscpy(szPasswdU2, CA2W(szPasswd2));
|
||
|
||
CString strCorpID;
|
||
strCorpID.Format(_T("%d"), CorpID);
|
||
CString strPasswd2 = szPasswdU2;
|
||
CString strTimeStamp = TimeStamp;
|
||
|
||
CString strMd5 = Passwd;
|
||
strMd5.MakeUpper();
|
||
|
||
CString strMd52 = CSendPub::GetMD5(strCorpID + strPasswd2 + strTimeStamp, false);
|
||
strMd52.MakeUpper();
|
||
|
||
strRet = strMd52;
|
||
|
||
if (strMd5 == strMd52)
|
||
{
|
||
strRet = CString(_T("1"));
|
||
}
|
||
else
|
||
{
|
||
strRet = CString(_T("0"));
|
||
}
|
||
|
||
if (!(Purview&PURVIEW_LOGIN))
|
||
{
|
||
strRet = CString(_T("-1"));
|
||
|
||
}
|
||
if (!(Purview&PURVIEW_SENDP))
|
||
{
|
||
strRet = CString(_T("-1"));
|
||
}
|
||
|
||
*pRet = ::SysAllocString(strRet);
|
||
return S_OK;
|
||
}
|