其他分享
首页 > 其他分享> > Messaging模块管理设备通讯功能,可用于短信、彩信、邮件发送等。通过plus.messaging可获取设备通讯管理对象。另外也可以直接通过html中的href直接快速发送短信、拨打电话、发送邮件

Messaging模块管理设备通讯功能,可用于短信、彩信、邮件发送等。通过plus.messaging可获取设备通讯管理对象。另外也可以直接通过html中的href直接快速发送短信、拨打电话、发送邮件

作者:互联网

常量:

方法:

对象:

回调方法:

权限:

5+功能模块(permissions)

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#ffffff">{</span>
<span style="color:#87ceeb">// ...</span>
<span style="color:#ffa0a0">"permissions"</span><span style="color:#ffffff">:{</span>
	<span style="color:#87ceeb">// ...</span>
	<span style="color:#ffa0a0">"Messaging"</span><span style="color:#ffffff">:</span> <span style="color:#ffffff">{</span>
		<span style="color:#ffa0a0">"description"</span><span style="color:#ffffff">:</span> <span style="color:#ffa0a0">"短信彩信邮件消息"</span>
	<span style="color:#ffffff">}</span>
<span style="color:#ffffff">}</span>
<span style="color:#ffffff">}</span>
			</code></span></span>

TYPE_SMS

简单短信类型常量

<span style="background-color:#333333"><span style="color:#474747"><code><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_SMS</span><span style="color:#ffffff">;</span>
				</code></span></span>

说明:

Number 类型

消息类型常量,Number类型,固定值为1,用于创建并发送短信。

平台支持

TYPE_MMS

彩信类型常量

<span style="background-color:#333333"><span style="color:#474747"><code><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_MMS</span><span style="color:#ffffff">;</span>
				</code></span></span>

说明:

Number 类型

消息类型常量,Number类型,固定值为2,用于创建并发送多媒体短信(彩信)。

平台支持

TYPE_EMAIL

邮件类型常量

<span style="background-color:#333333"><span style="color:#474747"><code><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_EMAIL</span><span style="color:#ffffff">;</span>
				</code></span></span>

说明:

Number 类型

消息类型常量,Number类型,固定值为3,用于创建并发送邮件。

平台支持

createMessage

创建消息对象

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#98fb98">Message</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">type</span><span style="color:#ffffff">);</span>
				</code></span></span>

说明:

创建指定类型的消息,消息类型可取plus.messaging.TYPE_SMS、plus.messaging.TYPE_MMS、plus.messaging.TYPE_EMAIL。

参数:

返回值:

Message : Message对象

平台支持:

示例:

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
	<span style="color:#f0e68c"><strong><head></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
	<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Messaging Example</span><span style="color:#f0e68c"><strong></title></strong></span>
	<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// H5 plus事件处理</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
<span style="color:#ffffff">}</span>
<span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">window</span><span style="color:#ffffff">.</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
	plusReady</span><span style="color:#ffffff">();</span>
<span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span><span style="color:#ffffff">{</span><span style="color:#ffffff">
	document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>

<span style="color:#87ceeb">//短信</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> smsTest</span><span style="color:#ffffff">(){</span>
	<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_SMS</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">to </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'18611497504'</span><span style="color:#ffffff">,</span> <span style="color:#ffa0a0">'15811140520'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">body </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'This is HTML5 Plus example test message'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>
	<span style="color:#f0e68c"><strong></script></strong></span>
	<span style="color:#f0e68c"><strong></head></strong></span>
	<span style="color:#f0e68c"><strong><body></strong></span>
		<span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"button"</span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">smsTest</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">SMS</span><span style="color:#f0e68c"><strong></button></strong></span>
	<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
				</code></span></span>

uni-app使用plus注意事项

sendMessage

发送消息

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">msg</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> successCB</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> errorCB</span><span style="color:#ffffff">);</span>
				</code></span></span>

说明:

发送消息,发送成功回调successCB函数,发送失败回调errorCB函数。

参数:

返回值:

void : 无

平台支持:

示例:

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
	<span style="color:#f0e68c"><strong><head></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
	<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Messaging Example</span><span style="color:#f0e68c"><strong></title></strong></span>
	<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// H5 plus事件处理</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
<span style="color:#ffffff">}</span>
<span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">window</span><span style="color:#ffffff">.</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
	plusReady</span><span style="color:#ffffff">();</span>
<span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span><span style="color:#ffffff">{</span><span style="color:#ffffff">
	document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>

<span style="color:#87ceeb">// 发送邮件</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> mailTest</span><span style="color:#ffffff">(){</span>
	<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_EMAIL</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">to </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'test@163.com'</span><span style="color:#ffffff">,</span> <span style="color:#ffa0a0">'test@173.com'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">cc </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'test@163.com'</span><span style="color:#ffffff">,</span> <span style="color:#ffa0a0">'test@173.com'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">bcc </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'test@163.com'</span><span style="color:#ffffff">,</span> <span style="color:#ffa0a0">'test@173.com'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">subject </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'测试邮件'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">body </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'This is Pandora example test message'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>function</strong></span> <span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
		alert</span><span style="color:#ffffff">(</span> <span style="color:#ffa0a0">"Send success!"</span> <span style="color:#ffffff">);</span>
	<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span> <span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span><span style="color:#ffffff">
		alert</span><span style="color:#ffffff">(</span> <span style="color:#ffa0a0">"Send failed!"</span> <span style="color:#ffffff">);</span>
	<span style="color:#ffffff">}</span> <span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>
	<span style="color:#f0e68c"><strong></script></strong></span>
	<span style="color:#f0e68c"><strong></head></strong></span>
	<span style="color:#f0e68c"><strong><body></strong></span>
		<span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"button"</span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">mailTest</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">Send Mail</span><span style="color:#f0e68c"><strong></button></strong></span>
	<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
				</code></span></span>

uni-app使用plus注意事项

Message

消息对象

属性:

方法:

to

收件人信息

说明:

Array[String] 类型 可选属性

字符串数组类型,输入的地址收件人信息必须符合消息类型格式。

cc

抄送人信息

说明:

Array[String] 类型 可选属性

字符串数组类型,仅发送邮件时有效,输入的地址收件人信息必须符合消息类型格式。

bcc

暗送人信息

说明:

Array[String] 类型 可选属性

字符串数组类型,仅发送邮件时有效,输入的地址收件人信息必须符合消息类型格式。

from

发件人信息

说明:

String 类型 可选属性

仅在监听接收到的信息时有效。

subject

发送消息主题

说明:

String 类型 可选属性

字符串类型,仅发送邮件时有效。

body

发送消息内容

说明:

String 类型 可选属性

字符串类型,要发送的消息体内容,其格式必须与bodyType指定的一致。

bodyType

发送消息内容类型

说明:

BodyType 类型 可选属性

要发送消息体内容的类型,可取值"text"表示文本内容,"html"表示为html页面,默认值为"text"。

平台支持:

示例:

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
	<span style="color:#f0e68c"><strong><head></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
	<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Messaging Example</span><span style="color:#f0e68c"><strong></title></strong></span>
	<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// H5 plus事件处理</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
<span style="color:#ffffff">}</span>
<span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">window</span><span style="color:#ffffff">.</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
	plusReady</span><span style="color:#ffffff">();</span>
<span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span><span style="color:#ffffff">{</span><span style="color:#ffffff">
	document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>

<span style="color:#87ceeb">// send mail</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> mailTest</span><span style="color:#ffffff">(){</span>
	<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_SMS</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">to </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'service@dcloud.io'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">bodyType </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">"text/html"</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">body </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'<html><body>hello world!</body></html>'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>
	<span style="color:#f0e68c"><strong></script></strong></span>
	<span style="color:#f0e68c"><strong></head></strong></span>
	<span style="color:#f0e68c"><strong><body></strong></span>
		<span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"button"</span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">mailTest</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">Mail</span><span style="color:#f0e68c"><strong></button></strong></span>
	<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
						</code></span></span>

uni-app使用plus注意事项

silent

是否采用静默方式发送消息

说明:

Boolean 类型 可选属性

布尔类型,可取值为true或false,true表示静默方式发送,不弹出界面;false表示非静默方式发送。默认采用非静默方式。

平台支持:

示例:

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
	<span style="color:#f0e68c"><strong><head></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>></strong></span>
	<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Messaging Example</span><span style="color:#f0e68c"><strong></title></strong></span>
	<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// H5 plus事件处理</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
<span style="color:#ffffff">}</span>
<span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">window</span><span style="color:#ffffff">.</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
	plusReady</span><span style="color:#ffffff">();</span>
<span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span><span style="color:#ffffff">{</span><span style="color:#ffffff">
	document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>

<span style="color:#87ceeb">// send SMS</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> smsTest</span><span style="color:#ffffff">(){</span>
	<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_SMS</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">to </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'10086'</span><span style="color:#ffffff">,</span> <span style="color:#ffa0a0">'10001'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">body </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'CXYE'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">silent </span><span style="color:#ffffff">=</span> <span style="color:#f0e68c"><strong>true</strong></span><span style="color:#ffffff">;</span> <span style="color:#87ceeb">// 设置为使用静默方式发送</span><span style="color:#ffffff">
	plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>
	<span style="color:#f0e68c"><strong></script></strong></span>
	<span style="color:#f0e68c"><strong></head></strong></span>
	<span style="color:#f0e68c"><strong><body></strong></span>
		<span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"button"</span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">smsTest</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">Silent SMS</span><span style="color:#f0e68c"><strong></button></strong></span>
	<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
						</code></span></span>

uni-app使用plus注意事项

addAttachment

添加附件

<span style="background-color:#333333"><span style="color:#474747"><code><span style="color:#ffffff">
msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addAttachment</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> url </span><span style="color:#ffffff">);</span>
						</code></span></span>

说明:

向消息中添加附件,仅邮件类型消息支持,其它类型消息不支持。

参数:

返回值:

void : 无

示例:

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
<span style="color:#f0e68c"><strong><head></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>/></strong></span>
	<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"initial-scale=1.0, maximum-scale=1.0, user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
	<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Messaging Example</span><span style="color:#f0e68c"><strong></title></strong></span>
	<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// H5 plus事件处理</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">(){</span>
<span style="color:#ffffff">}</span>
<span style="color:#f0e68c"><strong>if</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">window</span><span style="color:#ffffff">.</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
	plusReady</span><span style="color:#ffffff">();</span>
<span style="color:#ffffff">}</span><span style="color:#f0e68c"><strong>else</strong></span><span style="color:#ffffff">{</span><span style="color:#ffffff">
	document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> plusReady</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>

<span style="color:#87ceeb">// send mail</span>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> mailTest</span><span style="color:#ffffff">(){</span>
	<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff">plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">TYPE_MAIL</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">to </span><span style="color:#ffffff">=</span> <span style="color:#ffffff">[</span><span style="color:#ffa0a0">'service@dcloud.io'</span><span style="color:#ffffff">];</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">body </span><span style="color:#ffffff">=</span> <span style="color:#ffa0a0">'This is an example mail'</span><span style="color:#ffffff">;</span><span style="color:#ffffff">
	msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addAttachment</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"_www/a.doc"</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
	plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">messaging</span><span style="color:#ffffff">.</span><span style="color:#ffffff">sendMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">}</span>
	<span style="color:#f0e68c"><strong></script></strong></span>
	<span style="color:#f0e68c"><strong></head></strong></span>
	<span style="color:#f0e68c"><strong><body></strong></span>
		<span style="color:#f0e68c"><strong><button</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"button"</span> <span style="color:#bdb76b"><strong>onclick</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"</span><span style="color:#ffffff">mailTest</span><span style="color:#ffffff">()</span><span style="color:#ffa0a0">"</span><span style="color:#f0e68c"><strong>></strong></span><span style="color:#ffffff">Mail with Attachment</span><span style="color:#f0e68c"><strong></button></strong></span>
	<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
						</code></span></span>

uni-app使用plus注意事项

BodyType

消息体内容类型

说明:

用于设定消息的消息体内容。

MessageSendSuccessCallback

消息发送成功的回调函数

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onSuccess</span><span style="color:#ffffff">()</span> <span style="color:#ffffff">{</span>
	<span style="color:#87ceeb">// Send message success code.</span>
<span style="color:#ffffff">}</span>
				</code></span></span>

参数:

返回值:

void : 无

MessageErrorCallback

消息发送失败的回调函数

<span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> one rror</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> error </span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
	<span style="color:#87ceeb">// Error code.</span>
<span style="color:#ffffff">}</span>
				</code></span></span>

参数:

返回值:

void : 无

标签:短信,发送,类型,plus,msg,messaging,TYPE,邮件
来源: https://blog.csdn.net/qq_40575646/article/details/122824854