发送任意内容的短信
在一个桌面会话,加载创建短信演示通道(WIM)的程序包并开始侦听.
In[1]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_34.png)
Needs["DemoChannels`WIM`"]
创建你的 WIM 通道并开始侦听.
In[2]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_35.png)
channel = CreateWIMChannel[]
Out[2]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_38.png)
In[3]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_36.png)
listener = ChannelListen[channel]
Out[3]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_39.png)
给自己发送 WIM,注意到它会在新的对话笔记本中显示你的消息.
In[4]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_37.png)
ChannelSend["WIM", "Hi there."]
Out[4]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_40.png)
Out[5]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_41.png)
将目前笔记版添附在消息中.
In[6]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_38.png)
ChannelSend["WIM", {"Sending a notebook.", InputNotebook[]}]
Out[6]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_42.png)
Out[7]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_43.png)
其他用户可通过引用你的完全合格的通道向你发送 WIM.
In[8]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_39.png)
yourWIM = $WolframID <> ":WIM"
Out[8]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_44.png)
In[9]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_40.png)
ChannelSend[yourWIM, "hello"]
Out[9]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_45.png)
或者你的 WIM 链接.
In[10]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_41.png)
listener["URL"]
Out[10]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_46.png)
In[11]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_42.png)
listener["URL"];
ChannelSend[%, "another message"]
Out[11]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_47.png)
任何人都可以通过创建对以下链接的 HTTP 请求从网页浏览器(或任何其他 HTTP 客户端)向你发送消息.
In[12]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_43.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}]
Out[12]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_48.png)
In[13]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_44.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}];
URLFetch[%]
Out[13]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_49.png)
为回复来自其他用户的信息,在用户信道对通信进行授权.
In[14]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_45.png)
Unprotect[$AllowExternalChannelFunctions];
$AllowExternalChannelFunctions = True;
停止侦听并重置保密设定.
In[15]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_46.png)
RemoveChannelListener[listener]
Out[15]=
![](assets.zh/instant-messaging-with-arbitrary-content/O_50.png)
In[16]:=
![Click for copyable input](assets.zh/instant-messaging-with-arbitrary-content/In_47.png)
$AllowExternalChannelFunctions = False;
Protect[$AllowExternalChannelFunctions];