📄 demodlg.cpp
字号:
if (!p->m_bAutoAck)
{
switch(ulCommandID)
{
case SGIP_DELIVER:
{
str.Format("接收到Deliver消息\n"
"用户手机号 = %s\n"
"SP号码 = %s\n"
"DCS = 0X%x\n"
"UDLen = %d\n",
sUserNumber,sSPNumber,byMsgCoding,
ulMsgLen);
}
break;
case SGIP_REPORT:
{
str.Format("接收到Report消息\n"
"用户手机号 = %s\n"
"SP号码 = %s\n"
"短消息执行状态 = %d\n",
sUserNumber,sSPNumber,
byState);
}
break;
case SGIP_USERRPT:
{
str.Format("接收到USERRPT消息\n"
"用户手机号 = %s\n"
"SP号码 = %s\n"
"用户状态状态 = %d\n",
sUserNumber,sSPNumber,
byState);
}
break;
default:
str.Format("无效CommandID:%d",ulCommandID);
break;
AfxMessageBox(str);
}
};
::PostMessage(handle, WM_ADDDLVSMNUM, 1, 0);
break;
default:
if (GetErrorString(iRet, 200, errstr) > 0)
AfxMessageBox(errstr);
break;
}
}
// end 2002-10-14 cfk
else
{
iRet = GetDeliverSMExEx(&sm_ID, &DestTON, &DestNPI, DestAddr, &OrgTON,
&OrgNPI, OrgAddr, &PRI, &RP, &UDHI, &PID, &DCS,
TimeStamp, &UDLen, UserData, &StatusReport);
CString str;
char errstr[200];
switch(iRet)
{
case E_SUCCESS:
if (!p->m_bAutoAck)
{
str.Format("接收到Deliver消息\n"
"sm_ID = %d\n"
"源地址 = %s\n"
"目标地址 = %s\n"
"DCS = 0X%x\n"
"PRI = %d\n"
"PID = 0x%x\n"
"UDHI = %d\n"
"UDLen = %d\n"
"TimeStamp = %s\n"
"正文 = %s\n"
"状态报告标志 = %d",
sm_ID, OrgAddr, DestAddr, DCS, PRI, PID,
UDHI, UDLen, TimeStamp,
UserData, StatusReport);
AfxMessageBox(str);
};
::PostMessage(handle, WM_ADDDLVSMNUM, 1, 0);
break;
default:
if (GetErrorString(iRet, 200, errstr) > 0)
AfxMessageBox(errstr);
}
}
}
return 0;
}
void CDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDemoDlg::OnClose()
{
IFExitInterface();
CDialog::OnClose();
}
void CDemoDlg::OnLogin()
{
UpdateData(TRUE);
/* if (!login(m_system_id, m_password))
AfxMessageBox("LOGIN FAILED.");
else AfxMessageBox("login success.");*/
DWORD id;
HANDLE handle;
int num=m_replaynum;
for (int i=0; i< num; i++)
{
handle=CreateThread(NULL, 0, LoginThread, this, 0,&id);
if (handle == NULL) AfxMessageBox("Create Thread failed");
};
}
DWORD WINAPI CDemoDlg::LoginThread(LPVOID lparam)
{
CString systemid;
CString password;
CDemoDlg* p= (CDemoDlg*) lparam;
::EnterCriticalSection(&(p->m_critical));
systemid=p->m_system_id;
password=p->m_password;
::LeaveCriticalSection(&(p->m_critical));
if (!Login(systemid, password))
::MessageBox(NULL, "login failed.", "Login Message",MB_OK|MB_ICONINFORMATION);
else
{
::MessageBox(NULL, "login success.", "Login Message",MB_OK|MB_ICONINFORMATION);
CString strText;
strText.Format("Demo - %s", systemid);
p->SetWindowText(strText);
};
return 0;
}
void CDemoDlg::OnLogout()
{
DWORD id;
HANDLE handle=CreateThread(NULL, 0, LogoutThread, this, 0,&id);
if (handle == NULL) AfxMessageBox("Create Thread failed");
}
DWORD WINAPI CDemoDlg::LogoutThread(LPVOID lparam)
{
if (!Logout()) ::MessageBox(NULL, "LOGOUT FAILED.", "Logout Info",MB_OK|MB_ICONINFORMATION);
else ::MessageBox(NULL, "logout success.", "Logout Info",MB_OK|MB_ICONINFORMATION);
return 0;
}
void CDemoDlg::OnSubmitSM()
{
DWORD id;
UpdateData(TRUE);
HANDLE handle;
int num=m_replaynum;
for(int i=0; i<num; i++)
{
handle=CreateThread(NULL, 0, SubmitThread, this, 0,&id);
if (handle == NULL) AfxMessageBox("Create Thread failed");
};
}
DWORD WINAPI CDemoDlg::SubmitThread(LPVOID lparam)
{
CDemoDlg* p =(CDemoDlg*)lparam;
unsigned char OrgTON=1, OrgNPI=1;
unsigned char DestTON=1, DestNPI=1;
unsigned char PRI, DCS;
char sadd[100];
char dadd[100];
//char schedule[100];
//char expire[100];
CString schedule;
CString expire;
unsigned char bySRR; //状态报告标志
unsigned long default_id=0;
unsigned char UDHI=0;
unsigned long UDLen;
unsigned long SM_ID;
unsigned char FCS;
unsigned char PID;
::EnterCriticalSection(&(p->m_critical));
PID = (unsigned char)p->m_pid;
bySRR = (unsigned char)p->m_iSRR;
switch(p->m_PRI)
{
case 0:
PRI=SM_PRI_DEFAULT;
break;
case 1:
PRI=SM_PRI_PRIOR;
break;
};
DCS = (unsigned char)atol(p->m_DCS);
/* switch(p->m_DCS)
{
case 0:
DCS=SM_DCS_ASC;
break;
case 1:
DCS=SM_DCS_CHINA;
break;
case 2:
DCS=0;
break;
};*/
UDLen=p->m_len;
UDHI = p->m_UDHI;
BOOL IsBinary = p->m_Binary;
int size = p->m_userdata.GetLength();
char * ud =NULL;
ud=new char[size+1];
memset(ud, 0, size+1);
if (ud == NULL)
{
::LeaveCriticalSection(&(p->m_critical));
return -1;
};
//if ((UDHI == 1) && IsBinary) //2000.4.20 zcd change
if (IsBinary)
{
AnalysisString(p->m_userdata, (unsigned char*)ud, size);
UDLen = size;
}
else
strcpy(ud,p->m_userdata);
//strcpy(schedule, p->m_schedule);
//strcpy(expire, p->m_expire);
schedule = p->m_schedule;
expire = p->m_expire;
default_id=p->m_default_id;
strcpy(sadd,p->m_orgaddr);
strcpy(dadd,p->m_destaddr);
::LeaveCriticalSection(&(p->m_critical));
CString str;
/*int iRet = SubmitSM(OrgTON,OrgNPI,sadd,DestTON,DestNPI,dadd,PRI,DCS,
schedule,expire,default_id,0, UDLen, (LPCTSTR)ud,&SM_ID,&FCS);*/
//by ycl 2001.9.26
unsigned char byMsgID[23]; //CMPP的字段,消息ID
unsigned char byPKTotal = 0; //相同Msg_id的消息总条数,从1开始
unsigned char byPKNumber = 0; //相同Msg_id的消息序号,从1开始
unsigned char byMsgLevel = 0; //信息级别
unsigned char byFeeUserType = 0; //计费用户类型字段,0:对目的终端MSISDN计费;1:对源终端MSISDN计费;2:对SP计费;3:表示本字段无效
char sSPID[MAX_SPID_LEN]; //信息内容来源
char sFeeType[MAX_FEE_TYPE_LEN]; //资费类别
char sFeeAddr[MAX_ADDR_LEN]; //被计费用户
char sFeeCode[MAX_FEE_CODE_LEN]; //资费代码
unsigned char byUserNum = 0; //接收消息的用户数量
char sDestAddrs[MAX_ADDRS_LEN]; //手机号码集
memset(byMsgID, 0, 23);
memset(sSPID, 0, MAX_SPID_LEN);
memset(sFeeType, 0, MAX_FEE_TYPE_LEN);
memset(sFeeAddr, 0, MAX_ADDR_LEN);
memset(sFeeCode, 0, MAX_FEE_CODE_LEN);
memset(sDestAddrs, 0, MAX_ADDRS_LEN);
byPKTotal = p->m_byPKTotal;
byPKNumber = p->m_byPKNumber;
byMsgLevel = p->m_byMsgLevel;
byFeeUserType = p->m_byFeeUserType;
memcpy(sSPID, p->m_sSPID, MAX_SPID_LEN);
memcpy(sFeeType, p->m_sFeeType, MAX_FEE_TYPE_LEN);
memcpy(sFeeAddr, p->m_sFeeAddr, MAX_ADDR_LEN);
memcpy(sFeeCode, p->m_sFeeCode, MAX_FEE_CODE_LEN);
byUserNum = p->m_byUsrNum;
memcpy(sDestAddrs, p->m_sDestAddrs, MAX_ADDRS_LEN);
int iRet;
char ServiceSubType[MAX_SERVICE];
memcpy(ServiceSubType, p->m_sServiceType, MAX_SERVICE - 1);
// 2002-09-09 hyt add for sgip
// 增加sgip参数
char sGivenValue[MAX_FEEVALUE_LEN];
memset(sGivenValue, 0, MAX_FEEVALUE_LEN);
strncpy(sGivenValue, p->m_sGivenValue, MAX_FEEVALUE_LEN);
char sReserve[MAX_RESERVE_LEN];
memset(sReserve, 0, MAX_RESERVE_LEN);
strncpy(sReserve, p->m_sReserve, MAX_RESERVE_LEN);
UC byAgentFlag = p->m_byAgentFlag;
UC byMoreMTFlag = p->m_byMoreMTFlag;
UC byMsgType = p->m_byMsgType;
UC byUsrNum = p->m_byUsrNum;
UC byFeeType = atoi(sFeeType);
// end 2002-09-09
// 2004-04-12
UC byAckResult;
//2004-04-12 -end
if(p->m_protocol == 2) //CMPP
{
iRet = SubmitAExEx(OrgTON,OrgNPI,sadd,DestTON,DestNPI,dadd,PRI,0,0,bySRR,0,DCS,PID,
schedule,expire,default_id, UDHI, UDLen, (LPCTSTR)ud, (LPCTSTR)ServiceSubType, \
byMsgID/*new*/, byPKTotal/*new*/, byPKNumber/*new*/, byMsgLevel/*new*/, \
byFeeUserType/*new*/, sSPID/*new*/, \
sFeeType/*new*/, sFeeAddr/*new*/, sFeeCode/*new*/, \
byUserNum/*new*/, sDestAddrs/*new*/, \
&SM_ID,&FCS);
}
//end
// 2002-09-09 hyt add for sgip
else if (3 == p->m_protocol)
{
iRet = SgipSubmitSM(sadd, sFeeAddr, byUsrNum, sDestAddrs, sSPID, \
(LPCTSTR)ServiceSubType, byFeeType, sFeeCode, sGivenValue, byAgentFlag, \
byMoreMTFlag, byMsgLevel, expire, schedule, bySRR, PID, UDHI, DCS, \
byMsgType, UDLen, (LPCTSTR)ud, sReserve,byAckResult);
CString s;
p->UpdateData(true);
p->m_error_code.Format("%d",byAckResult);
p->UpdateData(false);
}
// end 2002-09-09
else
{
//by ycl 2001.7.9
if((p->m_sServiceType).IsEmpty())
iRet = SubmitA(OrgTON,OrgNPI,sadd,DestTON,DestNPI,dadd,PRI,0,0,bySRR,0,DCS,PID,
schedule,expire,default_id, UDHI, UDLen, (LPCTSTR)ud,&SM_ID,&FCS);
else
iRet = SubmitAEx(OrgTON,OrgNPI,sadd,DestTON,DestNPI,dadd,PRI,0,0,bySRR,0,DCS,PID,
schedule,expire,default_id, UDHI, UDLen, (LPCTSTR)ud, (LPCTSTR)ServiceSubType, &SM_ID,&FCS);
//end
}
/*int iRet = VPSubmitSM(sadd, dadd, schedule, expire,
default_id, (LPCTSTR)ud, &SM_ID);*/
if (iRet != E_SUCCESS)
{
char errstr[200];
if (GetErrorString(iRet, 200, errstr) > 0)
::MessageBox(NULL, errstr, "Submit Error Info", MB_OK|MB_ICONINFORMATION);
delete ud;
return 0;
};
str.Format("submit success.\n"
" SM ID :%u,\n"
" FCS :%u.", SM_ID, FCS);
::MessageBox(NULL,str, "Submit Info", MB_OK|MB_ICONINFORMATION);
delete ud;
return 0;
}
void CDemoDlg::OnOK()
{
if (!IsExitDemo())
return;
SaveRegKey();
IFExitInterface();
CDialog::OnOK();
}
void CDemoDlg::OnCancel()
{
//if (!IsExitDemo())
return;
}
BOOL CDemoDlg::IsExitDemo()
{
if (AfxMessageBox("Are you sure to exit?", MB_YESNO) == IDNO)
return FALSE;
else
return TRUE;
}
void CDemoDlg::OnQuerySMDetails()
{
UpdateData(TRUE);
unsigned char OrgTON=0, OrgNPI=0;
char OrgAddr[MAX_ADDR_LEN];
//strcpy(OrgAddr, m_orgaddr);
unsigned char DestTON=0, DestNPI=0;
char DestAddr[MAX_ADDR_LEN];
unsigned char PRI, DCS;
char Schedule[MAX_TIMESTAMP_LEN];
char Expire[MAX_TIMESTAMP_LEN];
char Final[MAX_TIMESTAMP_LEN];
unsigned char SM_Status;
unsigned char Error_Code;
char* UserData = NULL;
if (m_len > 0) UserData = new char[m_len];
if (UserData == NULL) return;
int iRet;
CString str;
iRet = QuerySMDetail(m_sm_id, &OrgTON, &OrgNPI, OrgAddr, &DestTON, &DestNPI, DestAddr,
&PRI, &DCS, Schedule, Expire, Final, &SM_Status, &Error_Code, m_len, UserData);
if (iRet != E_SUCCESS)
{
char errstr[200];
if (GetErrorString(iRet, 200, errstr) > 0)
AfxMessageBox(errstr);
if (UserData != NULL) delete UserData;
return;
};
m_userdata.Format("%s",UserData);
m_destaddr.Format("%s",DestAddr);
m_orgaddr.Format("%s",OrgAddr);
m_destaddr.Format("%s",DestAddr);
m_PRI=PRI;
m_DCS.Format("%d", DCS);
/*switch(DCS)
{
case SM_DCS_ASC:
m_DCS=0;
break;
case SM_DCS_CHINA:
m_DCS=1;
break;
case 0:
m_DCS=2;
break;
default:
ASSERT(false);
if (UserData != NULL) delete UserData;
return;
};*/
m_schedule.Format("%s", Schedule);
m_expire.Format("%s",Expire);
m_final.Format("%s", Final);
char sStatusStr[255];
GetSMStatusString(SM_Status, 255, sStatusStr);
m_status.Format("%d %s", SM_Status, sStatusStr);
/*
switch(SM_Status)
{
case WAITING_FOR_DELIVER:
m_status.Format("%s", "WAITING_FOR_DELIVER");
break;
case DELIVER_SUCCESS:
m_status.Format("%s", "DELIVER_SUCCESS");
break;
case DELIVER_FAIL:
m_status.Format("%s", "DELIVER_FAIL");
break;
case SM_RES_WAIT_DELIVER_FOR_ERROR:
m_status.Format("%s", "因提交失败而等待");
break;
case SM_RES_WAIT_DELIVER_FOR_NORMAL:
m_status.Format("%s", "因定时短讯而等待");
break;
case SM_RES_WORK:
m_status.Format("%s", "工作态");
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -