跳转至
For the complete DHIS2 documentation index, see llms.txt.

短信

短消息服务(SMS)

本节介绍用于发送和接收短文本的 SMS Web API 消息。

出站短信服务

Web API 支持使用 POST 方法发送外发 SMS。短信可以 发送到单个或多个目的地。一个或多个网关需要 在使用服务之前进行配置。如果出现以下情况,将不会发送短信 没有配置网关。它需要一组接收者和 JSON 格式的消息文本,如下所示。

/ api / sms / outbound
{
  "message":"Sms Text",
  "recipients": [
    "004712341234",
    "004712341235"
  ]
}

Note

Recipients list will be partitioned if the size exceeds MAX_ALLOWED_RECIPIENTS limit of 200.

Web API 也支持查询参数版本,但 参数化 API 只能用于发送短信到单个 目的地。

/ api / sms / outbound?message = text&recipient = 004712341234

可以使用GET资源提取出站邮件。

GET / api / sms / outbound
GET / api / sms / outbound?filter = status:eq:SENT
GET / api / sms / outbound?filter = status:eq:SENT&fields = *

可以使用DELETE资源删除出站邮件。

删除/ api / sms / outbound / {uid}
删除/ api / sms / outbound?ids = uid1,uid2

网关响应码

网关可以使用以下响应代码进行响应。

curl -d @keys.json "play.dhis2.org/demo/api/33/i18n" -X POST
  -H "Content-Type: application/json" -u admin:district

| 结果将如下所示: | json { "access_denied":"Access denied", "uploading_data_notification":"Uploading locally stored data to the server" } | SMS | |---|---|---| | 短消息服务(SMS) { #webapi_sms } | 本节介绍用于发送和接收短文本的 SMS Web API 消息。 | Outbound SMS service | | Web API 支持使用 POST 方法发送外发 SMS。短信可以 发送到单个或多个目的地。一个或多个网关需要 在使用服务之前进行配置。如果出现以下情况,将不会发送短信 没有配置网关。它需要一组接收者和 JSON 格式的消息文本,如下所示。 | / api / sms / outbound | json { "message":"Sms Text", "recipients": [ "004712341234", "004712341235" ] } | | > Note

Recipients list will be partitioned if the size exceeds MAX_ALLOWED_RECIPIENTS limit of 200. | Web API 也支持查询参数版本,但 参数化 API 只能用于发送短信到单个 目的地。 | / api / sms / outbound?message = text&recipient = 004712341234 | | 可以使用GET资源提取出站邮件。 | GET / api / sms / outbound GET / api / sms / outbound?filter = status:eq:SENT GET / api / sms / outbound?filter = status:eq:SENT&fields = * | 可以使用DELETE资源删除出站邮件。 | | 删除/ api / sms / outbound / {uid} 删除/ api / sms / outbound?ids = uid1,uid2 | Gateway response codes | 网关可以使用以下响应代码进行响应。 | | Table: Gateway response codes | Response code | Response Message | | Detail Description | RESULT_CODE_0 | success | | Message has been sent successfully | RESULT_CODE_1 | scheduled | | Message has been scheduled successfully | RESULT_CODE_22 | internal fatal error | | Internal fatal error | RESULT_CODE_23 | authentication failure | | Authentication credentials are incorrect | 本节介绍用于发送和接收短文本的 SMS Web API 消息。 | data validation failed | | Parameters provided in request are incorrect | RESULT_CODE_25 | insufficient credits | | Credit is not enough to send message | RESULT_CODE_26 | 向应用项目接口提交了多条信息,但并非所有信息的状态都相同 | | Upstream credits not available | RESULT_CODE_27 | exceeded your daily quota | | You have exceeded your daily quota | RESULT_CODE_40 | temporarily unavailable | | Service is temporarily down | RESULT_CODE_201 | maximum batch size exceeded | | Maximum batch size exceeded | RESULT_CODE_200 | success | | The request was successfully completed | RESULT_CODE_202 | accepted | | The message(s) will be processed | RESULT_CODE_207 | multi-status | | 向应用项目接口提交了多条信息,但并非所有信息的状态都相同 | RESULT_CODE_400 | bad request | | Validation failure (such as missing/invalid parameters or headers) | RESULT_CODE_401 | unauthorized |

入站短信服务

Web API 支持使用 POST 收集传入的 SMS 消息 方法。路由到 DHIS2 Web API 的传入消息可以是 使用此 API 接收。 API 收集入站 SMS 消息和 根据短信内容(SMS 命令)。下面给出了 JSON 格式的示例负载。文本, 发起者、接收日期和发送日期是强制性参数。这 其余是可选的,但系统将使用这些默认值 参数。

/ api / sms / inbound
{
  "text": "sample text",
  "originator": "004712341234",
  "gatewayid": "unknown",
  "receiveddate": "2016-05-01",
  "sentdate":"2016-05-01",
  "smsencoding": "1",
  "smsstatus":"1"
}

可以使用GET resourcef获取入站消息

GET / api / sms / inbound
GET / api / sms / inbound?fields = *&filter = smsstatus = INCOMING

可以使用DELETE资源删除入站邮件

删除/ api / sms / inbound / {uid}
删除/ api / sms / inbound?ids = uid1,uid2

导入所有未解析的消息

POST /api/sms/入站/导入

用法

默认值 类型 描述
技术性更强、对开发人员更友好的消息(目前尚未使用)。 RESULT_CODE_503
service unavailable Inbound SMS service
Web API 支持使用 POST 收集传入的 SMS 消息
方法。路由到 DHIS2 Web API 的传入消息可以是
使用此 API 接收。 API 收集入站 SMS 消息和
根据短信内容(SMS
命令)。下面给出了 JSON 格式的示例负载。文本,
发起者、接收日期和发送日期是强制性参数。这
其余是可选的,但系统将使用这些默认值
参数。 ```json
{
"text": "sample text",
"originator": "004712341234",
"gatewayid": "unknown",
"receiveddate": "2016-05-01",
"sentdate":"2016-05-01",
"smsencoding": "1",
"smsstatus":"1"
}
```
可以使用GET resourcef获取入站消息 日期 可以使用DELETE资源删除入站邮件

网关服务管理

Web API 公开资源,这些资源提供了一种配置和 更新短信网关配置。

可以使用 GET 检索配置的不同网关的列表 方法。

Table: User query parameters

还可以使用特定网关类型检索配置 获取方法。

类型

可以使用 POST 添加新的网关配置。 POST api 需要类型请求参数,目前它的值可以有一个 http,bulksms,clickatell,smpp。第一个添加的网关将设置为默认值。一次只能默认一个网关。默认网关只能通过其 api 更改。如果删除了默认网关,则列表中的下一个网关将自动变为默认网关。

POST / api / 33 / gateways

可以通过提供如下所述的uid和网关配置来更新配置

This is mandatory parameter which carries the actual text message.

可以使用 DELETE 删除特定网关类型的配置 方法。

删除/ api / 33 / gateways / {uid}

可以检索和更新默认网关。

gateway

可以使用PUT方法设置默认网关。

This is an optional parameter which gives gateway id. If not present default text "UNKNOWN" will be stored

网关配置

Web API 允许您创建和更新网关配置。对于每个 网关类型 JSON 有效负载中有不同的参数。 下面给出了每个网关的示例 JSON 有效负载。 POST 用于 create 和 PUT 以更新配置。标头参数可用于 GenericHttpGateway 将一个或多个参数作为 http 标头发送的情况。

Clickatell{ #clickatell }

{
  "type" : "clickatell",
  "name" : "clickatell",
  "username": "clickatelluser",
  "authToken": "XXXXXXXXXXXXXXXXXXXX",
  "urlTemplate": "https://platform.clickatell.com/messages"
}

散装

{
  "type": "bulksms",
  "name": "bulkSMS",
  "username": "bulkuser",
  "password": "abc123"
}

SMPP网关

{
  "type": "smpp",
  "name": "smpp gateway2",
  "systemId": "smppclient1",
  "host": "localhost",
  "systemType": "cp",
  "numberPlanIndicator": "UNKNOWN",
  "typeOfNumber": "UNKNOWN",
  "bindType": "BIND_TX",
  "port": 2775,
  "password":"password",
  "compressed": false
}

通用HTTP

{
  "type": "http",
  "name": "Generic",
  "configurationTemplate": "username=${username}&password=${password}&to=${recipients}&countrycode=880&message=${text$}&messageid=0",
  "useGet": false,
  "sendUrlParameters":false,
  "contentType": "APPLICATION_JSON",
  "urlTemplate":"https://samplegateway.com/messages",
  "parameters": [
    {
      "header": true,
      "encode": false,
      "key": "username",
      "value": "user_uio",
      "confidential": true
    },
    {
      "header": true,
      "encode": false,
      "key": "password",
      "value": "123abcxyz",
      "confidential": true
    },
    {
      "header": false,
      "encode": false,
      "key": "deliveryReport",
      "value": "yes",
      "confidential": false
    }
  ],
  "isDefault": false
}

在通用的http网关中,可以添加任意数量的参数。

可以通过提供如下所述的uid和网关配置来更新配置

默认值 类型 描述
名称 可以使用PUT方法设置默认网关。
PUT /api/33/gateways/default/{uid} Web API 允许您创建和更新网关配置。对于每个
网关类型 JSON 有效负载中有不同的参数。
下面给出了每个网关的示例 JSON 有效负载。 POST 用于
create 和 PUT 以更新配置。标头参数可用于
GenericHttpGateway 将一个或多个参数作为 http 标头发送的情况。
Clickatell Boolean Bulksms
```json
{
"type": "bulksms",
"name": "bulkSMS",
"username": "bulkuser",
"password": "abc123"
}
| 串 |json
{
"type": "smpp",
"name": "smpp gateway2",
"systemId": "smppclient1",
"host": "localhost",
"systemType": "cp",
"numberPlanIndicator": "UNKNOWN",
"typeOfNumber": "UNKNOWN",
"bindType": "BIND_TX",
"port": 2775,
"password":"password",
"compressed": false
}
```
Generic HTTP 在通用的http网关中,可以添加任意数量的参数。
Table: Generic SMS gateway parameters Boolean 类型
描述 Boolean
产生价值终点 { #webapi_generate_values }
价值 Boolean
Http POST nethod will be used by default. In order to change it and Http GET, user can set useGet flag to true. Boolean
Content type specify what type of data is being sent. Supported types are APPLICATION_JSON, APPLICATION_XML, FORM_URL_ENCODED, TEXT_PLAIN Boolean

如果配置保存成功则返回 HTTP.OK 否则 Error

短信命令

SMS 命令用于通过 SMS 收集数据。这些命令 属于特定的解析器类型。每个解析器都有不同的功能。

可以使用GET检索命令列表。

encode

可以使用GET检索一个特定的命令。

If parameter needs to be encoded

可以使用PUT更新一个特定的命令。

可以使用POST创建命令。

POST / api / smsCommands

可以使用DELETE删除一个特定命令。

删除/ api / smsCommands / uid

短信命令类型

类型 用法
sendUrlParameters 用于汇总数据收集。
If this flag is checked then urlTemplate can be appended with query parameters. This is usefull if gateway API only support HTTP GET. Sample urlTemplate looks like this "urlTemplate":"https://samplegateway.com/messages?apiKey={apiKey}&to={recipients},content={text},deliveryreport={dp}" 发送警报消息。
未注册_解析器 用于疾病监测病例报告。
可以使用GET检索命令列表。 用于跟踪器实体注册。
可以使用GET检索一个特定的命令。 程序阶段的数据收集。 (根据phoneNumner确定TEI)
可以使用PUT更新一个特定的命令。 单个事件的注册。这用于事件程序。

Android的SMS命令类型

当互联网不可用时,Android应用程序可以使用这些命令类型通过SMS提交数据。 SMS由Android应用程序组成。

类型 用法
AGGREGATE_DATASET 用于汇总数据收集。
注册 用于跟踪器实体注册。
用于汇总数据收集。 跟踪器程序的事件注册。
发送警报消息。 活动节目的活动注册。
关系 建立关系。
删除 删除事件。