SmsSendMessage发送短消息新问题

jobe2007 2007-05-08 03:36:44
调用SmsSendMessage发送短消息时,SmsSendMessage返回值为S_OK,但是实际上接收号码没有接收到短消息?

其实我的需求就是:已知接收方号码(可能是多个)和短消息文本内容,然后显示ppc WM5.0上标准的短消息发送界面(并且把号码和内容填到对应的部分,当然用户可以在标准界面下修改短消息)。

1.如下代码问题出现在哪里?
2.那位大侠有其它方法实现我的需求?

HRESULT h;
SMS_HANDLE smsHandle = NULL;


//SMS_ADDRESS smsaSource;
SMS_ADDRESS smsaDestination;

SMS_MESSAGE_ID smsmidMessageID=0;
TEXT_PROVIDER_SPECIFIC_DATA tpsd;

h = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if (FAILED(h))
{
MessageBox( _T( "Open Err" ), _T( "sendsms" ), MB_ICONINFORMATION );
return false;
}


smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL;
_tcsncpy( smsaDestination.ptsAddress, _T( "13146524491" ), SMS_MAX_ADDRESS_LENGTH );

tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS1;
tpsd.psReplaceOption = PSRO_NONE;

LPCTSTR lpszMessage = _T( "1111111" );

h= SmsSendMessage(smsHandle,
NULL,
&smsaDestination,
NULL,
( PBYTE )lpszMessage,
_tcslen( lpszMessage ) * sizeof( TCHAR ),
( PBYTE )&tpsd,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&smsmidMessageID );

if ( SUCCEEDED(h))
{
MessageBox( _T( "ok" ), _T( "sendsms" ), MB_ICONINFORMATION );
}
else
{
MessageBox( _T( "Fail" ), _T( "sendsms" ), MB_ICONINFORMATION );
}

SmsClose( smsHandle );
...全文
1518 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq470129050 2011-02-12
  • 打赏
  • 举报
回复
5555我怎么找不到C#的? 你那能不能做成DLL?
Yibans 2007-05-23
  • 打赏
  • 举报
回复
能否问一下,请问楼主是如何实现发送给普通手机号码的?
我写的发送消息程序只能用0010001测试而已。。。
谢谢告知!!
jobe2007 2007-05-23
  • 打赏
  • 举报
回复
谢谢各位的帮助。问题解决了,结贴了!
Yibans 2007-05-22
  • 打赏
  • 举报
回复
忽然发现上面的代码跟PPC自带的例子极其地相似。。。。。
还有zjj2816_163com() ,贴的一段代码没有帖全。。。里面两个函数其实是自定义的。。。(也是在自带的例子中的。。)

但是还是学到了点。嗯。。。边学习边飘过。。。。
l1w1w1 2007-05-21
  • 打赏
  • 举报
回复
不错,学习一下,呵呵
无聊客 2007-05-18
  • 打赏
  • 举报
回复
因为你的地址类型是:
smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL;
所以要求你的号码需要在前面加国家码"+86",如果是
smsaDestination.smsatAddressType = SMSAT_UNKNOWN;
那应该就不需要加国家码

关于内容,只要是UNICODE的就可以了
小李匪盗 2007-05-15
  • 打赏
  • 举报
回复
int nLen = strlen(aTxt);
lpszMessage = new wchar_t[2*nLen];
int nNum = MultiByteToWideChar(CP_ACP, 0, aTxt,nLen,lpszMessage,2*nLen);
lpszMessage[nNum] = 0;
jobe2007 2007-05-15
  • 打赏
  • 举报
回复
第一次是计算长度,实际上没有做转换。

直接lpszMessage = _T("你好,1234324///abckd!!!!");肯定是可以的,但是短消息内容是动态的,从外部传进来的参数,不可能在代码里面写死。
小李匪盗 2007-05-15
  • 打赏
  • 举报
回复
DWORD dwNum = MultiByteToWideChar( CP_OEMCP, 0, aTxt,-1,NULL,0);
lpszMessage = new wchar_t[dwNum];
MultiByteToWideChar( CP_OEMCP, 0, aTxt,-1,lpszMessage,dwNum);

转这么多次是干嘛?
直接lpszMessage = _T("你好,1234324///abckd!!!!");就可以了
jobe2007 2007-05-15
  • 打赏
  • 举报
回复
我现在把代码贴出来,请大家帮忙看看。

已经用MultiByteToWideChar把窄字符转成宽字符了,可是接收到的字符串仍然是乱码。
????



int CSendSms::SendShortMessage(char* aTxt)
{
SMS_HANDLE smshHandle;
SMS_ADDRESS smsaSource;
SMS_ADDRESS smsaDestination;
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
SMS_MESSAGE_ID smsmidMessageID;

LPTSTR lpszSMSC = NULL;
LPTSTR lpszRecipient = NULL;
LPWSTR lpszMessage = NULL;


// 在这里我已经用MultiByteToWideChar把窄字符转成宽字符了
//lpszMessage = _T("你好,1234324///abckd!!!!");
DWORD dwNum = MultiByteToWideChar( CP_OEMCP, 0, aTxt,-1,NULL,0);
lpszMessage = new wchar_t[dwNum];
MultiByteToWideChar( CP_OEMCP, 0, aTxt,-1,lpszMessage,dwNum);

// try to open an SMS Handle
if(FAILED(SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL)))
{
return 0;
}

// Create the source address
bool bUseDefaultSMSC = true;
if(!bUseDefaultSMSC)
{
smsaSource.smsatAddressType = SMSAT_INTERNATIONAL;
_tcsncpy(smsaSource.ptsAddress, lpszSMSC, SMS_MAX_ADDRESS_LENGTH);
}

lpszRecipient = _T("8613146524491");
// Create the destination address
smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL;
_tcsncpy(smsaDestination.ptsAddress, lpszRecipient, SMS_MAX_ADDRESS_LENGTH);

// Set up provider specific data

bool bSendConfirmation = true;
memset(&tpsd, 0, sizeof(tpsd));
tpsd.dwMessageOptions = bSendConfirmation ? PS_MESSAGE_OPTION_STATUSREPORT : 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, ((bUseDefaultSMSC) ? NULL : &smsaSource),
&smsaDestination, NULL, (PBYTE) lpszMessage,
_tcslen(lpszMessage) * sizeof(TCHAR), (PBYTE) &tpsd,
sizeof(TEXT_PROVIDER_SPECIFIC_DATA), SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE, &smsmidMessageID)))
{
}
else
{
}

// clean up
VERIFY(SUCCEEDED(SmsClose(smshHandle)));

return 1;
}

jobe2007 2007-05-15
  • 打赏
  • 举报
回复
很短啊,类似与“你好,123,add”这样的字符串。
小李匪盗 2007-05-15
  • 打赏
  • 举报
回复
编译成debug版本时,接收到正确短消息;但是用relese版本就出现乱码。
================================================================
你的短信有多长啊?
金笛子 2007-05-15
  • 打赏
  • 举报
回复
SDK5.0 有个很好的sample叫HelloSms的 能够发送短信 可以看看
jobe2007 2007-05-14
  • 打赏
  • 举报
回复
出现了乱码

1.SmsSendMessage发送短消息时,接收到的短消息位乱码。我的开发环境为vs2005+ppc5.0(vc++),编译成debug版本时,接收到正确短消息;但是用relese版本就出现乱码。?????

2.使用cemapi发送短信,是否会出现乱码的情况????
zjj2816_163com 2007-05-10
  • 打赏
  • 举报
回复
可以用cemapi发送短信。
HRESULT SendSMSMessage(const CComPtr<IMAPISession>& spSession, LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszMessage)
{

// now get the SMS message store
CComPtr<IMsgStore> spMsgStore;
HRESULT hr = GetSMSMsgStore(spSession, spMsgStore);
if (FAILED(hr))
{
return hr;
}

CComPtr<IMAPIFolder> spFolder;

hr = GetSMSFolder(spMsgStore, spFolder);
if (FAILED(hr))
{
return hr;
}

CComPtr<IMessage> spMessage;
hr = spFolder->CreateMessage(NULL, 0 ,&spMessage);
if (FAILED(hr))
{
AfxMessageBox(IDS_SMS_FAIL_CREATEMESSAGE);
return hr;
}

// set the recipients
// set up the required fields for a recipient
SPropValue propRecipient[3];
// it is vital we clear the property structure
// as there are fields we do not use but MAPI seems
// to be sentative to them.
ZeroMemory(&propRecipient, sizeof(propRecipient));
// set the recipient type which coul be to, cc, bcc
// but ehre must at least be a to field
propRecipient[0].ulPropTag = PR_RECIPIENT_TYPE;
propRecipient[0].Value.l = MAPI_TO;

// we set the type of address to sms instead of
// smtp
propRecipient[1].ulPropTag = PR_ADDRTYPE;
propRecipient[1].Value.lpszW = _T("SMS");
// we finally set the email address to the
// phone number of the person we are sending the message
// to
propRecipient[2].ulPropTag = PR_EMAIL_ADDRESS;
propRecipient[2].Value.lpszW = (LPWSTR)lpszTo;

// set the addrlist to point to the properties
ADRLIST adrlist;
adrlist.cEntries = 1;
adrlist.aEntries[0].cValues = 3;
adrlist.aEntries[0].rgPropVals = (LPSPropValue)(&propRecipient);

// finally modify the recipients of the message
hr = spMessage->ModifyRecipients(MODRECIP_ADD, &adrlist);

if (FAILED(hr))
{
AfxMessageBox(IDS_SMS_FAILED_ADDRECIPIENTS);
return hr;
}
else
; // added the recipient to the message

// now we set the additional properties for the
// message
SPropValue props[4];

//note how we zero out the contents of the
// structure as MAPI is sensative to the
// contents of other fields we do not use.
ZeroMemory(&props, sizeof(props));

// first set the subject of the message
// as the sms we are going to send
props[0].ulPropTag = PR_SUBJECT;
props[0].Value.lpszW = (LPWSTR)lpszMessage;

// next set the senders email address to
// the phone number of the person we are
// sending the message to
props[1].ulPropTag = PR_SENDER_EMAIL_ADDRESS;
props[1].Value.lpszW = (LPWSTR)lpszFrom;

// finally and most importantly tell mapi
// this is a sms message in need of delivery
props[2].ulPropTag = PR_MSG_STATUS;
props[2].Value.ul = MSGSTATUS_RECTYPE_SMS;

props[3].ulPropTag = PR_MESSAGE_FLAGS;
props[3].Value.ul = MSGFLAG_FROMME | MSGFLAG_UNSENT;

hr = spMessage->SetProps(sizeof(props) / sizeof(props[0]), (LPSPropValue)&props, NULL);
if (FAILED(hr))
{
AfxMessageBox(IDS_SMS_FAIL_SETPROPS);
return hr;
}

// having set all the required fields we can now
// pass the message over to the msgstore transport
// to be delivered.
hr = spMessage->SubmitMessage(0);
if (FAILED(hr))
{
AfxMessageBox(IDS_SMS_FAIL_SUBMITMSG);
return hr;
}

return FALSE;
}

小李匪盗 2007-05-08
  • 打赏
  • 举报
回复
如果是其他地区,那你也要加上其他地区的区号。

有没有直接显示短消息发送标准UI的方法?尝试改变一下dwMessageOptions参数。
jobe2007 2007-05-08
  • 打赏
  • 举报
回复
pknife(小李飞刀):
加上“+86”就OK了。有没有直接用原始号码就可以的(在国内是86,如果是其它地区呢,这样一来很不方便)。

另外,有没有直接显示短消息发送标准UI的方法?
小李匪盗 2007-05-08
  • 打赏
  • 举报
回复
在手机号码前面加上"+86", _T( "+8613146524491" )就可以了
可以实现短信发送,非常好用 public static int SendSMS(string Number, string Message) { int returnValue = 0; IntPtr smsHandle = new IntPtr(0); // Set address structure byte[] smsatAddressType = BitConverter.GetBytes(SMSAT_INTERNATIONAL); byte[] ptsAddress = Encoding.Unicode.GetBytes(Number); byte[] smsAddressTag = new byte[smsatAddressType.Length + ptsAddress.Length]; Array.Copy(smsatAddressType, 0, smsAddressTag, 0, smsatAddressType.Length); Array.Copy(ptsAddress, 0, smsAddressTag, smsatAddressType.Length, ptsAddress.Length); IntPtr smsAddress = AllocHGlobal((IntPtr)smsAddressTag.Length); Marshal.Copy(smsAddressTag, 0, smsAddress, smsAddressTag.Length); // Set provider data structure byte[] dwMessageOptions = BitConverter.GetBytes(PS_MESSAGE_OPTION_NONE); byte[] psMessageClass = BitConverter.GetBytes(PS_MESSAGE_CLASS1); byte[] psReplaceOption = BitConverter.GetBytes(PSRO_NONE); byte[] smsProviderDataTag = new byte[dwMessageOptions.Length + psMessageClass.Length + psReplaceOption.Length]; Array.Copy(dwMessageOptions, 0, smsProviderDataTag, 0, dwMessageOptions.Length); Array.Copy(psMessageClass, 0, smsProviderDataTag, dwMessageOptions.Length, psMessageClass.Length); Array.Copy(psReplaceOption, 0, smsProviderDataTag, dwMessageOptions.Length + psMessageClass.Length, psReplaceOption.Length); IntPtr smsProviderData = AllocHGlobal((IntPtr)smsProviderDataTag.Length); Marshal.Copy(smsProviderDataTag, 0, smsProviderData, smsProviderDataTag.Length); // Set message // Encoding unicode = Encoding.Unicode; // Encoding utf8 = Encoding.ASCII; // byte[] smsMessageTag1 = Encoding.ASCII.GetBytes(Message); // byte[] smsMessageTag = Encoding.Convert(utf8,unicode,smsMessageTag1); byte[] smsMessageTag = Encoding.Unicode.GetBytes(Message); IntPtr smsMessage = AllocHGlobal((IntPtr)smsMessageTag.Length); Marshal.Copy(smsMessageTag, 0, smsMessage, smsMessageTag.Length); // Get handle if (0 != SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, ref smsHandle, 0)) returnValue = -1; // Could not open // Send message if (0 != SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage, smsMessageTag.Length, smsProviderData, smsProviderDataTag.Length, SMSDE_GSM, SMS_OPTION_DELIVERY_NONE, 0)) returnValue = -2; FreeHGlobal(smsMessage); FreeHGlobal(smsProviderData); FreeHGlobal(smsAddress); // Release handle if (0 != SmsClose(smsHandle)) returnValue = -3; // Could not close return returnValue; } }

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧