仿照sdk里面的发短信的例程,改写了一段代码,不知道怎么回事,总是发送不成功,请高手帮我看看 问题出在哪?
- SMS_HANDLE smshHandle;
- SMS_ADDRESS smsaSource;
- SMS_ADDRESS smsaDestination;
- TEXT_PROVIDER_SPECIFIC_DATA tpsd;
- SMS_MESSAGE_ID smsmidMessageID;
- BOOL bRetVal=FALSE;
- LPCTSTR lpszRecipient;
- LPCTSTR lpszMessage;
- UpdateData();
- lpszRecipient=m_receiver;
- lpszMessage=m_msg;
- // try to open an SMS Handle
- if(FAILED(SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL)))
- {
- //return bRetVal;
- bRetVal=FALSE;
- }
- // Create the destination address
- smsaSource.smsatAddressType = SMSAT_NATIONAL;
- smsaDestination.smsatAddressType = SMSAT_NATIONAL;
- _tcsncpy(smsaDestination.ptsAddress, lpszRecipient, SMS_MAX_ADDRESS_LENGTH);
- // Set up provider specific data
- memset(&tpsd, 0, sizeof(tpsd));
- tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
- tpsd.psMessageClass = PS_MESSAGE_CLASS1;
- tpsd.psReplaceOption = PSRO_NONE;
- tpsd.dwHeaderDataSize = 0;
- // Send the message, indicating success or failure
- if(SUCCEEDED(SmsSendMessage(smshHandle, NULL,
- &smsaDestination, NULL, (PBYTE) lpszMessage,
- _tcslen(lpszMessage) * sizeof(TCHAR), (PBYTE) &tpsd,
- sizeof(TEXT_PROVIDER_SPECIFIC_DATA), SMSDE_OPTIMAL,
- SMS_OPTION_DELIVERY_NONE, &smsmidMessageID)))
- {
- bRetVal = TRUE;
- AfxMessageBox(_T("Send SMS succussful!"));
- }
- else
- {
- bRetVal = FALSE;
- }
- // clean up
- VERIFY(SUCCEEDED(SmsClose(smshHandle)));
BOOL SendSMS(LPCTSTR lpszRecipient, LPCTSTR lpszMessage)
{
BOOL bRetVal = FALSE;
SMS_HANDLE smshHandle;
SMS_ADDRESS smsaSource;
SMS_ADDRESS smsaDestination;
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
SMS_MESSAGE_ID smsmidMessageID;
// try to open an SMS Handle
if(FAILED(SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL)))
{
return bRetVal;
}
// Create the destination address
smsaSource.smsatAddressType = SMSAT_UNKNOWN;
smsaDestination.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy(smsaDestination.ptsAddress, lpszRecipient, SMS_MAX_ADDRESS_LENGTH);
// Set up provider specific data
memset(&tpsd, 0, sizeof(tpsd));
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS1;
tpsd.psReplaceOption = PSRO_NONE;
tpsd.dwHeaderDataSize = 0;
// Send the message, indicating success or failure
if(SUCCEEDED(SmsSendMessage(smshHandle, NULL,
&smsaDestination, NULL, (PBYTE) lpszMessage,
_tcslen(lpszMessage) * sizeof(TCHAR), (PBYTE) &tpsd,
sizeof(TEXT_PROVIDER_SPECIFIC_DATA), SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE, &smsmidMessageID)))
{
bRetVal = TRUE;
}
else
{
bRetVal = FALSE;
}
// clean up
SmsClose(smshHandle);
return bRetVal;
}
可是 我用了UNKOWN也不行啊???
高手啊 帮帮菜鸟吧
我以前用的是 smsAddrDestination.smsatAddressType = SMSAT_INTERNATIONAL; 发中文字符应该要用这个参数吧,具体得查下msdn文档。
另外短信发不出去的原因有很多的,你需要根据SmsSendMessage返回的错误码去查找原因,每个错误码在msdn上都有明确的错误描述。