文档管理中心
API参考快应用API系统能力发送短信

发送短信

接口声明

在manifest.json文件的 features属性中增加如下配置。

收起
自动换行
深色代码主题
复制
  1. {"name": "system.sms"}

导入模块

在调用接口页面的<script>部分增加如下配置。

收起
自动换行
深色代码主题
复制
  1. import sms from '@system.sms'

收起
自动换行
深色代码主题
复制
  1. var sms = require("@system.sms")

使用限制

展开

限制条件

说明

适用终端

手机、平板

适用区域

全球

接口定义

展开

接口

描述

message.send(OBJECT)

发送短信接口,每次调用会给用户弹框提示确认,短信内容不能超过70个字符。

message.send(OBJECT)

描述

发送短信接口,每次调用会给用户弹框提示确认,短信内容不能超过70个字符。

OBJECT参数

展开

参数

类型

是否必填

说明

address

string

短信要发送的目标号码(只支持数字、空格、首字符为“+”)。

content

string

短信内容(不能超过70个字符)。

success

function

成功回调。

fail

function

失败回调。

complete

function

执行结束后的回调。

fail返回错误码:

展开

参数名

说明

200

发送失败。

201

用户拒绝,获取发送短信权限失败。

202

参数为空或者参数错误。

示例代码

收起
自动换行
深色代码主题
复制
  1. message.send({
  2. address:'10086',
  3. content:'这是短信内容',
  4. success: function () {
  5. console.log('handling success')
  6. },
  7. fail: function (data, code) {
  8. console.log('handling fail, code = ${code}')
  9. }
  10. })

Demo

收起
自动换行
深色代码主题
复制
  1. <template>
  2. <!-- Only one root node is allowed in template. -->
  3. <div class="container">
  4. <div class="case-title">
  5. <text class="title">Recipient</text>
  6. </div>
  7. <div class="mlr-container">
  8. <input onchange="phoneChange" class="input-big" placeholder="please input address" />
  9. </div>
  10. <div class="case-title">
  11. <text class="title">Message</text>
  12. </div>
  13. <div class="mlr-container">
  14. <textarea onchange="contentChange" class="textarea" placeholder="please input content"></textarea>
  15. </div>
  16. <div class="mlr-container mt-btn">
  17. <input onclick="send" type="button" value="Send message" class="btn-blue" />
  18. </div>
  19. </div>
  20. </template>
  21. <style lang="sass">
  22. .container {
  23. flex-direction: column;
  24. padding-bottom: 50px;
  25. }
  26. .case-title {
  27. margin-left: 32px;
  28. margin-right: 32px;
  29. margin-bottom: 20px;
  30. margin-top: 40px;
  31. flex-direction: column;
  32. }
  33. .title {
  34. color: rgba(0, 0, 0, 0.6);
  35. font-size: 28px;
  36. font-weight: 500;
  37. }
  38. .mlr-container {
  39. margin-right: 32px;
  40. margin-left: 32px;
  41. }
  42. .input-big {
  43. width: 100%;
  44. background-color: #fff;
  45. height: 100px;
  46. border-radius: 50px;
  47. padding-left: 30px;
  48. font-size: 32px;
  49. }
  50. .textarea {
  51. width: 100%;
  52. height: 300px;
  53. background-color: #fff;
  54. padding: 20px 30px;
  55. font-size: 32px;
  56. border-radius: 16px;
  57. }
  58. .btn-blue {
  59. background-color: #0faeff;
  60. width: 100%;
  61. height: 80px;
  62. border-radius: 40px;
  63. color: #fff;
  64. font-size: 32px;
  65. font-weight: 500;
  66. }
  67. </style>
  68. <script>
  69. import prompt from '@system.prompt';
  70. import message from '@system.sms';
  71. module.exports = {
  72. public: {
  73. phone: "",
  74. content: "",
  75. },
  76. onInit: function () {
  77. this.$page.setTitleBar({ text: 'message'});
  78. },
  79. phoneChange({ value }) {
  80. this.phone = value;
  81. },
  82. contentChange({ value }) {
  83. this.content = value;
  84. },
  85. send() {
  86. if (!this.phone || !this.content) {
  87. prompt.showToast({
  88. message: 'please input address or content',
  89. duration: 2000,
  90. gravity: 'bottom'
  91. });
  92. return;
  93. }
  94. message.send({
  95. address: this.phone,
  96. content: this.content,
  97. success: function () {
  98. prompt.showToast({
  99. message: 'success',
  100. duration: 2000,
  101. gravity: 'bottom'
  102. });
  103. },
  104. fail: function (data, code) {
  105. prompt.showToast({
  106. message: 'fail',
  107. duration: 2000,
  108. gravity: 'bottom'
  109. });
  110. }
  111. })
  112. }
  113. }
  114. </script>

效果图如下:

版本更新说明

展开

版本

发布日期

描述

1010

2018-04-20

第一次正式发布。

在 API参考 中进行搜索
请输入您想要搜索的关键词