喵提醒

喵提醒帮助与文档


常见开发语言调用API示例

以下假设存在喵码为tDS0Se9的提醒,并且在提醒中附带实时信息“你好吗?”。 示例仅读取返回json的code和msg参数,若需读取更多参数请根据API文档自行完善代码。

[TOC]

PHP
$miao_code = "tDS0Se9";
$text = "你好吗?";

$result = file_get_contents("http://miaotixing.com/trigger?id=" . $miao_code . "&text=" . urlencode($text) . "&type=json");
$jsonObj = json_decode($result);
if ($jsonObj->code === 0) {
    echo "成功";
}
else {
    echo "失败,错误代码:" . $jsonObj->code . ",描述:" . $jsonObj->msg;
}
JavaScript

使用jQuery:

var miao_code = "tDS0Se9";
var text = "你好吗?";
$.ajax({
    type: "GET",
    url: "//miaotixing.com/trigger",
    data: {
        id : miao_code,
        text : text,
        type : "jsonp"
    },
    success: function(data){
        if(data.code == 0){
            console.log("成功");
        }
        else{
            console.log("失败,错误代码:" + data.code + ",描述:" + data.msg);
        }
    },
    dataType: 'jsonp'
});

JavaScript原生:

var miao_code = "tDS0Se9";
var text = "你好吗?";

var script = document.createElement("script");
script.setAttribute("src", "//miaotixing.com/trigger?id=" + miao_code + "&text=" + encodeURI(text) + "&type=jsonp");
document.getElementsByTagName("head")[0].appendChild(script);

function miaotixing_jsonpcallback(data) {
    var result = JSON.stringify(data);
    if(data.code == 0) {
        console.log("成功");
    }
    else {
        console.log("失败,错误代码:" + data.code + ",描述:" + data.msg);
    }
}

如果不需要关注通知是否成功,可以用简单的触发方式:

var miao_code = "tDS0Se9";
var text = "你好吗?";

var img = document.createElement("img");
img.src = "//miaotixing.com/trigger?id=" + miao_code + "&text=" + encodeURI(text);
.NET
//注意,需要添加引用。
System.Web.Extensions
System.Web
System.Runtime.Serialization
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Runtime.Serialization;

string miao_code = "tDS0Se9";
string text = "你好吗?";

System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(now());
WebClient client = new WebClient();
string json = client.DownloadString(string.Format("http://miaotixing.com/trigger?id={0}&text={1}&type=json" , miao_code, HttpUtility.UrlEncode(text)));
JavaScriptSerializer js = new JavaScriptSerializer();
MiaotixingReturn miaotixingReturn = js.Deserialize<MiaotixingReturn>(json);
if (miaotixingReturn.code == 0) {
    Console.WriteLine("成功");
}
else {
    Console.WriteLine(string.Format("失败,错误代码:{0},描述:{1}", miaotixingReturn.code, miaotixingReturn.msg));
}

[DataContract]
public class MiaotixingReturn
{
    [DataMember]
    public int code { get; set; }

    [DataMember]
    public string msg { get; set; }
}
Python
from urllib import request, parse
import time
import json

miao_code = "tDS0Se9"
text = "你好吗?"

page = request.urlopen("http://miaotixing.com/trigger?" + parse.urlencode({"id":miao_code, "text":text, "type":"json"}))
result = page.read()
jsonObj = json.loads(result)
if (jsonObj["code"] == 0):
    print("成功")
else:
    print("失败,错误代码:" + str(jsonObj["code"]) + ",描述:" + jsonObj["msg"])
Java
import org.jsoup.Jsoup;

String miao_code = "tDS0Se9";
String text = "你好吗?";

String result = Jsoup.connect("http://miaotixing.com/trigger?id=" + miao_code + "&text=" + urlencode(text) + "&type=json" ).timeout(5000).get();
JSONObject jsonObj = JSONObject.fromObject(result);
if (jsonObj.getInt("code") == 0) {
    System.out.println("成功");
}
else {
    System.out.println("失败,错误代码:" + String.valueOf(jsonObj.getInt("code")) + ",描述:" + jsonObj.getString("msg"));
}
VC++
#include "afxinet.h"

CInternetSession c;
CHttpFile *p = NULL;
p = (CHttpFile*)c.OpenURL(_T("http://miaotixing.com/trigger?id=tDS0Se9&text=你好吗?"));
Shell
curl "http://miaotixing.com/trigger?id=tDS0Se9&text=""你好吗?" | tr -d "\n" | xxd -plain | sed "s/\(..\)/%\1/g"
按键精灵
miao_code = "tDS0Se9"
text = "你好吗?"

Set objXML=CreateObject("Microsoft.XMLHTTP")
objXML.Open "Get", "http://miaotixing.com/trigger?id=" + miao_code + "&text=" + text, False
objXML.send
按键精灵(手机版)
Import "ShanHai.lua"

Dim miao_code = "tDS0Se9"
Dim text = "你好吗?"

TracePrint URL.Get("http://miaotixing.com/trigger?id=" & miao_code & "&text=" & ShanHai.CharToUrl(text))

小技巧:按键精灵如果希望发出提醒的text参数带换行,可以用%0A表示换行符,比如"text=第一行%0A第二行"。

易语言
miao_code = "tDS0Se9"
text = "你好吗?"

HTTP读文件 ("http://miaotixing.com/trigger?id=" + miao_code + "&text=" + 编码_URL编码(text))
Lua
local miao_code = "tDS0Se9"
local text = "你好吗"

local http = require("socket.http")
local ltn12 = require("ltn12")
local t = {}

local function urlEncode(s)  
    s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)  
    return string.gsub(s, " ", "+")  
end

local r, c, h = require("socket.http").request{
    url = "http://miaotixing.com/trigger?id=" .. miao_code .. "&text=" .. urlEncode(text) .."&type=json",
    sink = ltn12.sink.table(t)
}
--print("return json:" .. table.concat(t))
一键玩

页面列表

ITEM_HTML