NAV
shell ruby python javascript go

JSPP 开放 API

欢迎使用JSPP 开放 API!

机器人API

调用频率限制

每个人每分钟最多发送20条消息,如果超过20条,会限流10分钟。

获取Webhook

在您的桌面端->群组详情或好友详情->机器人接入->复制出Webhook地址,格式如下:

https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN

获取到Webhook地址后,用户可以向这个地址发起HTTP POST 请求,即可实现给该群发送消息。

image

image

消息类型及数据格式

文本类型

require 'net/http'
require 'json'
require 'uri'

uri = URI('https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN')
http = Net::HTTP.new(uri.host)
req = Net::HTTP::Post.new(uri.to_s, 'Content-Type' => 'application/json')
req.body = { text: { content: "这是一条测试消息"}, msgtype: "text"}.to_json
res = http.request(req)
puts res.body
url = 'https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN'
d = {"text":{"content": "这是一条测试消息"}, "msgtype": "text"}
r = requests.post(url, data=d)
print r
curl https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN \
-H 'Content-Type: application/json' \
-d '{"text":{"content": "这是一条测试消息"}, "msgtype": "text"}'
const axios = require(axios);

axios.post(
  "https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN",
  {"text":{"content": "这是一条测试消息"}, "msgtype": "text"}
).then((response) => {
  console.log(response);
});

package main

import (
        "bytes"
        "encoding/json"
        "fmt"
        "io"
        "net/http"
)

const (
        TEXT = "text"
)

type JsppRobotClient struct {
        Url string
}

type JsppRobotMessage struct {
        Msgtype string               `json:"msgtype"`
        Text    JsppRobotTextMessage `json:"text"`
}

type JsppRobotTextMessage struct {
        Content string `json:"content"`
}

type JsppRobotResponse struct {
        Res   int64  `json:"res"`
        Msg   string `json:"msg"`
        Trace string `json:"trace"`
}

func NewJsppRobotClient(url string) (client *JsppRobotClient, err error) {
        d := new(JsppRobotClient)
        d.Url = url

        return d, nil
}

func (d *JsppRobotClient) SendTextMessage(message string) error {
        if message == "" {
                return fmt.Errorf("message is empty")
        }

        jsppRobotMessage := JsppRobotMessage{
                Msgtype: TEXT,
                Text: JsppRobotTextMessage{
                        Content: message,
                },
        }

        jsppRobotMessageJson, err := json.Marshal(&jsppRobotMessage)

        if err != nil {
                return err
        }

        client := &http.Client{}
        request, err := http.NewRequest("POST", d.Url, bytes.NewBuffer(jsppRobotMessageJson))
        if err != nil {
                return err
        }
        request.Header.Add("Content-Type", "application/json")
        resp, err := client.Do(request)

        if err != nil {
                return err
        }
        defer resp.Body.Close()

        if resp.StatusCode != http.StatusOK {
                return fmt.Errorf("request failed StatusCode=%d", resp.StatusCode)
        }
        body, err := io.ReadAll(resp.Body)
        if err != nil {
                return err
        }

        jsppRobotResp := &JsppRobotResponse{}
        err = json.Unmarshal(body, &jsppRobotResp)
        if err != nil {
                return err
        }

        if jsppRobotResp.Res != http.StatusOK {
                return fmt.Errorf("request failed StatusCode=%d, jsppRobot talk error: %v", resp.StatusCode, jsppRobotResp)
        }

        return nil
}

func main() {
        c, err := NewJsppRobotClient("https://devoapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN")
        if err != nil {
                fmt.Printf("%+v\n", err)
                return
        }
        resp := c.SendTextMessage("这是一条测试消息")
        fmt.Printf("%+v\n", resp)
}

请求JSON参数

{
    "at": {
        "atMobiles":[
            "+86180xxxxxx"
        ],
        "atUserIds":[
            123
        ],
        "isAtAll": false
    },
    "text": {
        "content":"这是一条测试消息"
    },
    "msgtype":"text"
}

返回JSON结果

{
  "res":200,
  "trace": "xoEosLOSR"
}

HTTP 请求

POST https://oapi.jspp.com/oapi/v1/robot/send?access_token=YOUR_ACCESS_TOKEN

请求参数

参数 参数类型 是否必填 说明
msgtype String 文本消息类型,此时固定为:text。
content String 消息内容。
atMobiles Array 被@人的手机号。
atUserIds Array 被@人的用户ID号。
isAtAll Boolean 是否@所有人。

错误码

错误码 说明
400 参数错误
401 未授权
429 请求次数过多
500 服务不可用