Giter Site home page Giter Site logo

realxiaoice's Introduction

realXiaoice

真正唯一可用的微软小冰API

来源为新浪微博

环境

Python 3.5+

依赖

  • tornado
  • requests

使用方法

1. 领养小冰

注册一个新浪微博账号,领养小冰,确保与小冰的私信是正常的

2. 登录微博账号

使用Chrome或者Firefox,建议开启隐身模式,打开 https://m.weibo.cn, 登录你的微博账号

3. 获取headers

打开和小冰的私信页面,按F12打开控制台,切换到Network,并选中XHR,然后和小冰说句话,点开名为send的请求

复制全部Request Headers中除了Content-Length以外所有行,粘贴到headers.txt中 请注意headers.txt的格式,注意大小写,CookieX-XSRF-TOKEN需要大写

4. 安装Python 3与依赖

安装适合自己平台的Python,需要3.5+之后的版本。为了后续兼容性考虑,选择3.6或3.7吧。然后

pip install tornado requests

5. 运行

python ice_server.py

6. systemd

[Unit]
Description=xiaoice API by Benny
After=network.target network-online.target nss-lookup.target

[Service]
User=nobody
Restart=on-failure
Type=simple

WorkingDirectory=/path/to/realXiaoice
ExecStart=/usr/bin/python3 /path/to/realXiaoice/ice_server.py

[Install]
WantedBy=multi-user.target

API

请求格式

接受GET、POST url-encoded-data和POST json,示例如下:

对于文字

# curl http://127.0.0.1:6789/chat?text=hello&type=text
GET http://127.0.0.1:6789/chat?text=hello&type=text

###


POST http://127.0.0.1:6789/chat
Content-Type: application/json

{
  "text": "what",
  "type":"text"
}


###


# curl -d 'text=hi&type=text' http://127.0.0.1:6789/chat
POST http://127.0.0.1:6789/chat
Content-Type: application/x-www-form-urlencoded

text=hi
type=text

###

对于图片(暂时只支持jpg)

# curl http://127.0.0.1:6789/chat?text=/tmp/test.jpg&type=img
GET http://127.0.0.1:6789/chat?text=/tmp/test.jpg&type=img

###


POST http://127.0.0.1:6789/chat
Content-Type: application/json

{
  "text": "/tmp/test.jpg",
  "type":"img"
}


###


# curl -d "text=/tmp/test.jpg&typt=img" http://127.0.0.1:6789/chat
POST http://127.0.0.1:6789/chat
Content-Type: application/x-www-form-urlencoded

text=/tmp/test.jpg
type=img

###

更多详情请参考 api.http

响应格式

成功

HTTP 200

{
    "text": "想我干嘛",
    "debug": ""
}

参数错误

HTTP 400

{
    "text": "",
    "debug": "client wrong reason"
}

服务端错误

HTTP 500

{
    "text": "",
    "debug": "server wrong reason"
}

效果图

附加功能

IP地址访问限制

默认关闭,只允许某几个IP访问可以使用如下方式

python ice_server.py -a=127.0.0.1,1.1.1.1

授权码限制

默认关闭,编辑key.txt一行一个添加授权码,或者运行keygen.py自动生成 开启方式

python ice_server --auth

请求时需要在参数中携带auth,例如:

curl http://127.0.0.1/chat?text=hello&auth=123456

Credits

License

MIT

realxiaoice's People

Contributors

belinchung avatar bennythink avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.