Intelligent Toy API Document

Keywords: PHP JSON encoding

User-related API s

User registration:

Used for App user registration

URL address: / reg
Request mode: POST
Request agreement:

JSON:
{
    "username":username,
    "password":password,
    "nickname":nickname,
    "gender":gender,
    "avatar":avatar.jpg
}

Response data:

JSON:
{
    "code":0,
    "msg":"login was successful",
    "data":{}
}

User login:

Used for App user login

URL address: / login
Request mode: POST
Request agreement:

JSON:
{
    "username":username,
    "password":password
}

Response data:

JSON:
{
    "code":0,
    "msg":"Successful login",
    "data":
    {
        "_id" : "5c8f582f268d7942f44c6703",
        "username" : "DragonFire",
        "gender" : "2",
        "nickname" : "You are really something!",
        "avatar" : "baba.jpg",
        "friend_list" : [],
        "bind_toy" : []
    }
}

User automatic login:

User automatic login when App opens

URL address: / auto_login
Request mode: POST
Request agreement:

JSON:
{
    "_id" : "5c8f582f268d7942f44c6703"
}

Response data:

JSON:
{
    "code":0,
    "msg":"Successful login",
    "data":
    {
        "_id" : "5c8f582f268d7942f44c6703",
        "username" : "DragonFire",
        "gender" : "2",
        "nickname" : "You are really something!",
        "avatar" : "baba.jpg",
        "friend_list" : [],
        "bind_toy" : []
        'chat' : ?  # get_all_redis(user_info_dict['_id'])  'chat' : {'count':1}
    }
}

Content-related API

Access to content resources:

Access to Content Resources on App Home Page

URL address: / content_list
Request mode: POST
Request agreement:

JSON:
{
    
}

Response data:

JSON:
{
    "code":0,
    "msg":"Get a list of content resources",
    "data":
    [
        {
            "_id" : "5c8f58eb268d79173c97bac5",
            "music" : "21b61cc0-9292-4e51-bf58-72be8ee6f962.mp3",
            "cover" : "21b61cc0-9292-4e51-bf58-72be8ee6f962.jpg",
            "title" : "A Pug"
        },
        {
            "_id" : "5c8f58eb268d79173c97bac4",
            "music" : "aa523ebe-95f9-4641-9478-1663cc74c6a6.mp3",
            "cover" : "aa523ebe-95f9-4641-9478-1663cc74c6a6.jpg",
            "title" : "follow Lei Feng's example"
        }
    ]
}

Access to Music Resources

Play content for App/Toy

URL address: / get_music/.mp3
Request method: GET
Request agreement: none
Response data: data flow

Getting Photo Resources

Used for App to Get Picture Resources

URL address: / get_image/.jpg
Request method: GET
Request agreement: none
Response data: data flow

Getting Voice Message Resources

Playing voice messages for App/Toy

URL address: / get_chat/.mp3
Request method: GET
Request agreement: none
Response data: data flow

Obtaining Two-Dimensional Code Picture Resources

Two-Dimensional Code Pictures for App

URL address: / get_qr/.mp3
Request method: GET
Request agreement: none
Response data: data flow

API for Audio Upload

App Recording Voice Upload Interface:

Used for App recording voice message upload

URL address: / app_uploader
Request mode: POST
Request agreement:

JSON:
{
    "to_user":to_user, //Voice Message Receiver
    "user_id":from_user, //Voice message sender
    "reco_file":File, //Voice file
}

Response data:

JSON:
{
    "code":0,
    "msg":"Upload Success",
    "data":
    {
        "filename":"filename",
        "friend_type":"app"
    }
}

Toy Recording Voice Upload Interface:

Uploading Voice Messages for Toy Recording

URL address: / toy_uploader
Request mode: POST
Request agreement:

JSON:
{
    "to_user":to_user, //Voice Message Receiver
    "user_id":from_user, //Voice message sender
    "friend_type":app/toy, //User Type of Voice Receiver
    "reco":File, //Voice file
}

Response data:

JSON:
{
    "code":0,
    "msg":"Upload Success",
    "data":
    {
        "filename":"filename",
        "friend_type":"app"
    }
}

Toy Recording Voice Upload AI Interface:

Uploading Voice Messages for Toy Recording to AI Interface

URL address: / ai_uploader
Request mode: POST
Request agreement:

JSON:
{
    "toy_id":toy_id, //Toy's Id
    "reco":File, //Voice file
}

Response data:

JSON:
//1.ai Response Plays Music
{
    "from_user": "ai",
    "music": music_name
}
//2.ai responds to voice messages
{
    "from_user": "ai", 
    "chat": filename
}
//3.ai responds to the initiative initiation message
{
    "from_user":friend_id,
    "chat":filename,
    "friend_type":app/toy
}

Voice Message Related API

App gets historical information:

Used for App to retrieve historical messages

URL address: / chat_list
Request mode: POST
Request agreement:

JSON:
{
    "chat_id":chat_id, //Chat Window Id
    "to_user":user_id, //App User Id
    "from_user":friend_id, //Receiver Id
}

Response data:

JSON:
{
    "code":0,
    "msg":"Query chat records",
    "data":
    [
        {
            "from_user" : "5c8f582f268d7942f44c6703",
            "message" : "1552898221960.amr.mp3",
            "create_time" : 1552898225.2744157
        },
        {
            "from_user" : "5c8f5853268d7942f44c6705",
            "message" : "ba7462dd-62a5-460c-bfab-bb64edd7c983.wav",
            "create_time" : 1552899004.6702642
        }
    ]
}

Toy receives unread messages:

Used after Toy receives a message reminder

URL address: / recv_msg
Request mode: POST
Request agreement:

JSON:
{
    "from_user":user_id/toy_id, //Sending voice messenger Id
    "to_user":toy_id, //toy_id, which currently receives voice messages
}

Response data:

JSON:
[
    {
        "from_user" : "5c8f582f268d7942f44c6703",
        "message" : "1552898221960.amr.mp3",
        "create_time" : 1552898225.2744157
    },
    {
        "from_user" : "5c8f5853268d7942f44c6705",
        "message" : "ba7462dd-62a5-460c-bfab-bb64edd7c983.wav",
        "create_time" : 1552899004.6702642
    }
]

Hardware Equipment and Two-Dimensional Code Related API

App Scan 2-D Code Verification Interface:

Application of App Scan Toy to Identify Two-Dimensional Codes

URL address: / scan_qr
Request mode: POST
Request agreement:

JSON:
{
    "device_key":device_key, //device_key Obtained by app Scanning Two-Dimensional Code
}

Response data:

JSON:
//1. Two-dimensional code scanning is successful and the device is not bound.
{
    "code":0,
    "msg":"Successful Scanning of Two-Dimensional Code",
    "data":
    {
        "device_key":device_key
    }
}

//2. Two-dimensional code scanning failed, and the barcode scanned was not present in the equipment library.
{
    "code":1,
    "msg":"Please scan the toy two-dimensional code",
    "data":{}
}

//3. Two-dimensional code scanning is successful, but the device has been bound.
{
    "code":2,
    "msg":"Equipment has been bound",
    "data":
    {
        "toy_id":toy_id
    }
}

App Binding Device Interface:

Used to bind App devices and create Toy information

URL address: / bind_toy
Request mode: POST
Request agreement:

JSON:
{
    "toy_name":toy_name, //toy name
    "baby_name":baby_name, //The name of the owner to which toy belongs
    "remark":remark, //App User Address by toy Master
    "user_id":user_id,//Binding Toy's App User Id
    "device_key":device_key, //Device unique encoding device_key
}

Response data:

JSON:
{
    "code":0,
    "msg":"Binding Completion",
    "data":{}
}

App gets the binding Toy information interface:

Used for App to get bound devices and create Toy information

URL address: / toy_list
Request mode: POST
Request agreement:

JSON:
{
    "_id":user_id //App User Id
}

Response data:

JSON:
{
    "code":0,
    "msg":"Obtain Toy list",
    "data":
    [
        {
            "_id" : ObjectId("5bcdaaa6268d794ec8af3fa2"),
            "device_key" : "bc557bcc9570069a494a64eb38698d35",
            "bind_user" : "5bcda858268d796fc8d3e3de",
            "toy_name" : "very",
            "avatar" : "toy.jpg",
            "baby_name" : "Bad shit",
            "gender" : "1",
            "friend_list" : [
                {
                    "friend_nickname" : "Obscene King",
                    "friend_avatar" : "girl.jpg",
                    "friend_remark" : "Dad",
                    "friend_chat" : "5bcdaaa6268d794ec8af3fa1"
                }
            ]
        },
        {
            "_id" : ObjectId("5bcdaa6f268d794ec8af3fa0"),
            "device_key" : "a195ac8014fb069676835a78d300f8a3",
            "bind_user" : "5bcda858268d796fc8d3e3de",
            "toy_name" : "Ball ball",
            "avatar" : "toy.jpg",
            "baby_name" : "Small dung ball",
            "gender" : "1",
            "friend_list" : [
                {
                    "friend_nickname" : "Obscene King",
                    "friend_avatar" : "girl.jpg",
                    "friend_remark" : "Dad",
                    "friend_chat" : "5bcdaa6f268d794ec8af3f9f"
                }
            ]
        }
    ]
}

Device Start Logon Interface:

Used to authenticate identity information after device start-up

URL address: / open_toy
Request mode: POST
Request agreement:

JSON:
{
    "device_key":device_key, //DeviceKey written in the device
}

Response data:

JSON:
//1. The device is bound and started normally.
{
    "code":0,
    "music":"Success.mp3",
    "toy_id":toy_id,
    "name":toy_name
}

//2. Equipment unbound
{
    "code":2,
    "music":"Nolic.mp3"
}

//3. Equipment not authorized
{
    "code":1,
    "music":"Nobind.mp3"
}

API for Friends Address Book

App Gets Friends List Interface:

Used for App to Get Friends Address Book

URL address: / friend_list
Request mode: POST
Request agreement:

JSON:
{
    "_id":user_id, //app User Id
}

Response data:

JSON:
//1. Two-dimensional code scanning is successful and the device is not bound.
{
    "code":0,
    "msg":"Friends Inquiry",
    "data":
    [
        {
            "friend_id" : "5c8f5853268d7942f44c6705",
            "friend_nick" : "Small dung ball",
            "friend_remark" : "round",
            "friend_avatar" : "toy.jpg",
            "friend_chat" : "5c8f5853268d7942f44c6704",
            "friend_type" : "toy"
        }
    ]
}

Add Friend Request Interface:

Used for requesting friends

URL address: / add_req
Request mode: POST
Request agreement:

JSON:
{
    "req_user":req_user_id, //Send friend requester Id
    "add_user":add_user_id, //Requestee Id
    "type":app/toy, //Requesting client type
    "req_info":"I am xxx", //Request content information
    "remark":remark //Requesting Party's Note Name to Requested Party
}

Response data:

JSON:
{
    "code":0,
    "msg":"Successful Added Friends Request",
    "data":{}
}

App Friends Request List Query Interface:

Friend Request for App Query Binding Toy

URL address: / req_list
Request mode: POST
Request agreement:

JSON:
{
    "_id":user_id, //app User Id
}

Response data:

JSON:
{
    "code":0,
    "msg":"Query Friends Request",
    "data":
    [
        {
            "req_user":req_user_id, //Send friend requester Id
            "add_user":add_user_id, //Requestee Id
            "type":app/toy, //Requesting client type
            "req_info":"I am xxx", //Request content information
            "remark":remark //Requesting Party's Note Name to Requested Party
            "avatar":avatar.jpg // The avatar of the requester
            "nickname":"nickname" // The petitioner's nickname
            "status":0 // Request status 0 pending processing 1 consent 2 rejection
            "toy_name":"toy_name" // The nickname of the requested Party
        }
    ]
}

App rejects Friends Request Interface:

Toy for App Refusal Binding is added as a friend

URL address: / ref_req
Request mode: POST
Request agreement:

JSON:
{
    "req_id":req_id //Friends Request Information Id
}

Response data:

JSON:
{
    "code":0,
    "msg":"Refuse to add friends",
    "data":{}
}

App agrees with Friends Request Interface:

For App to agree to bind Toy to be added as a friend

URL address: / acc_req
Request mode: POST
Request agreement:

JSON:
{
    "req_id":req_id, //Friends Request Information Id
    "remark":"friend_remark", //Add a comment name to the requester
}

Response data:

JSON:
{
    "code":0,
    "msg":"Agree to add friends",
    "data":{}
}

Posted by NeoGeo on Sat, 27 Jul 2019 22:53:19 -0700