curl -X POST -H "Content-Type: application/json" -H "X-Apemesh-Key: <用户AppKey>" -d
'{
"serviceID": <id>,
"actionName": <name>,
"input": { ... }
}'
https://api.apemesh.com:3049/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action{
"output": { ... }
}<?php
// 这里展示的是发送短信验证码API的input JSON对象的构建方法
// 其他API的input JSON对象参数的构建方法请参照各自的API文档
$postData = array(
'serviceID' => 'urn:cdif-io:serviceID:短信服务',
'actionName' => '发送验证码',
'input' => array('phoneNum' => '13910001000', 'templateID' => '<模板ID>', 'content' => array('345756'))
);
$context = stream_context_create(array(
'http' => array(
'header' => "X-Apemesh-Key: <用户appKey>\r\n".
"Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($postData),
'ignore_errors' => true
)
));
// Send the request
$response = file_get_contents('https://api.apemesh.com:3049/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action', FALSE, $context);
// Check for errors
if ($response === FALSE || json_decode($response, TRUE)['topic'] == 'device error') {
var_dump($http_response_header);
die(json_decode($response,TRUE)['fault']['reason']);
}
// Decode the response
$responseData = json_decode($response, TRUE);
// Print the date from the response
print_r($responseData['output']);
?>{
"output": { ... }
}private void makeRequest() throws Exception
{
String url="https://api.apemesh.com:3049/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action";
URL object=new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
con.setRequestProperty("X-Apemesh-Key", "<用户appKey>");
con.setRequestMethod("POST");
// 这里展示的是发送短信验证码API的input JSON对象的构建方法
// 其他API的input JSON对象参数的构建方法请参照各自的API文档
JSONObject requestData = new JSONObject();
requestData.put("serviceID","urn:cdif-io:serviceID:短信服务");
requestData.put("actionName","发送验证码");
JSONObject input = new JSONObject();
input.put("phoneNum", "13910001000");
input.put("templateID", "<模板ID>");
JSONArray content = new JSONArray();
content.put("123456");
input.put("content", content);
requestData.put("input", input);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(requestData.toString());
wr.flush();
//display what returns the POST request
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if (HttpResult == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println("" + sb.toString());
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getErrorStream(), "utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
JSONObject result = new JSONObject(sb.toString());
JSONObject fault = result.getJSONObject("fault");
String reason = fault.getString("reason");
System.out.println(reason);
}
}{
"output": { ... }
}#!/usr/local/bin/python
# coding: utf-8
import urllib2
import json
# 这里展示的是发送短信验证码API的input JSON对象的构建方法
# 其他API的input JSON对象参数的构建方法请参照各自的API文档
inputData = json.dumps({
"serviceID":"urn:cdif-io:serviceID:短信服务",
"actionName":"发送验证码",
"input": {
"phoneNum":"13910001000",
"templateID":"<模板ID>",
"content":["211315"]
}
})
headers = {'Content-type': 'application/json', 'X-Apemesh-Key': '<用户appKey>'}
url = "https://api.apemesh.com:3049/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action"
try:
req = urllib2.Request(url, inputData, headers)
f = urllib2.urlopen(req)
response = json.loads(f.read())
print response['output']['result']
except urllib2.HTTPError, e:
err = json.loads(e.read())
print err['fault']['reason']{
"output": { ... }
}var https=require('https');
// 这里展示的是发送短信验证码API的input JSON对象的构建方法
// 其他API的input JSON对象参数的构建方法请参照各自的API文档
var body = {
"serviceID":"urn:cdif-io:serviceID:短信服务",
"actionName":"发送验证码",
"input": {
"phoneNum":"13910000000",
"templateID":"<模板ID>",
"content":["211315"]
}
};
var bodyString = JSON.stringify(body);
var options = {
host: 'api.apemesh.com',
port: 3049,
path: '/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(bodyString),
'X-Apemesh-Key': '<用户appKey>'
}
};
var req = https.request(options,function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var resultObject = JSON.parse(responseString);
if (resultObject.topic === 'device error') {
return console.log(resultObject.fault.reason);
}
return console.log(resultObject.output.result);
});
req.on('error', function(e) {
// TODO: handle request error
console.log(e);
});
});
req.write(bodyString);
req.end();{
"output": { ... }
}package main
import (
"bytes"
"io/ioutil"
"net/http"
"encoding/json"
"fmt"
)
// 这里展示的是发送短信验证码API的input JSON对象的构建方法
// 其他API的input JSON对象参数的构建方法请参照各自的API文档
type RequestData struct {
ServiceID string `json:"serviceID"`
ActionName string `json:"actionName"`
InputData Input `json:"input"`
}
type Input struct {
PhoneNum string `json:"phoneNum"`
TemplateID string `json:"templateID"`
Content ContentData `json:"content"`
}
type ContentData []string
func main() {
var url = "https://api.apemesh.com:3049/devices/f5dc73f9-b739-5ee2-add7-e499da04c6ec/invoke-action"
var data = RequestData {
ServiceID: "urn:cdif-io:serviceID:短信服务",
ActionName: "发送验证码",
InputData: Input{"1391000000", "<模板ID>", []string{"123135"}},
}
body, err := json.Marshal(data)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", url, bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("X-Apemesh-Key", "<用户appKey>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, _ := ioutil.ReadAll(resp.Body)
// 以下展示的是发送短信验证码API返回结果的output JSON对象的构建方法
// 其他API的返回结果output JSON对象的构建方法请参照各自的API文档
if (resp.StatusCode == 500) {
type FaultInfo struct {
Reason string `json:"reason"`
Info string `json:"info"`
}
type ErrorInfo struct {
Topic string `json:"topic"`
Message string `json:"message"`
Fault FaultInfo `json:"fault"`
}
var errorInfo = ErrorInfo{}
json.Unmarshal(responseBody, &errorInfo)
fmt.Println(errorInfo.Fault.Reason)
} else {
type OutputData struct {
Result string `json:"result"`
SmsID string `json:"smsID"`
}
type ReturnData struct {
Output OutputData `json:"output"`
}
var result = ReturnData{}
json.Unmarshal(responseBody, &result)
fmt.Println(result.Output.SmsID)
}
}{
"output": { ... }
}| SERVICEID | API Name | Unit price | Package | ||
|---|---|---|---|---|---|
| Package price(RMB) | Call number(times) | Operation | |||