论坛

创建帖子

接口调用说明:

POST https://lxapi.lexiangla.com/cgi-bin/v1/threads

请求document

{
  "data": {
    "type": "thread", 
    "attributes": {
      "title": "通过API创建帖子", 
      "content": "<p>这是帖子内容,支持富文本</p>"
    }, 
    "relationships": {
      "category": {
        "data": {
          "type": "category", 
          "id": "62a0b1a67fff11e7aa685254009d059e"
        }
      }
    }
  }
}

参数说明:

参数 是否必须 默认值 说明
thread.type 资源对象类型,必须为 thread,表示帖子
thread.title 帖子标题
thread.content 帖子内容
thread.category 关联的资源对象,类型为 category,表示帖子所属分类
category.id 分类ID
created_at 服务器当前时间 帖子的创建时间
updated_at 服务器当前时间 帖子的更新时间
read_count 0 帖子的阅读数/浏览数

SDK封装方法使用示例:

$attributs = [
    'title' => '通过API创建帖子',
    'content' => '<p>这是帖子内容,支持富文本</p>',
    'category_id' => '62a0b1a67fff11e7aa685254009d059e',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postThread(StaffID, $attributs, $options = []);

响应document

201 Created 状态码
{
  "links": {
    "self": {
      "href": "https://lxapi.lexiangla.com/cgi-bin/v1/threads/63c88fb0831c11e888d65254002b6735"
    }
  }, 
  "data": {
    "type": "thread", 
    "id": "63c88fb0831c11e888d65254002b6735", 
    "attributes": {
      "title": "通过API创建帖子", 
      "content": "<p>这是帖子内容,支持富文本</p>", 
      "summary": "这是帖子内容,支持富文本", 
      "updated_at": "2018-07-09 10:04:19", 
      "created_at": "2018-07-09 10:04:19"
    }, 
    "relationships": {
      "owner": {
        "data": {
          "type": "staff", 
          "id": "StaffID"
        }
      }, 
      "category": {
        "data": {
          "type": "category", 
          "id": "c41215f654f711e88ed65254002b6735"
        }
      }
    }
  }, 
  "included": [
    {
      "type": "staff", 
      "id": "StaffID", 
      "attributes": {
        "name": "张三", 
        "english_name": "ThreeZhang",
        "organization":"运营组"
      }
    }, 
    {
      "type": "category", 
      "id": "c41215f654f711e88ed65254002b6735", 
      "attributes": {
        "name": "分类A"
      }
    }
  ]
}

获取帖子列表

接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/threads

参数说明:

支持分页参数和排序:(通用说明?

参数 是否必须 默认值 说明
sort -created_at 排序参数,支持按帖子的created_at,updated_at排序
page 1 当前页数
per_page 20 每页返回的数量

SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('threads', [
    'page'=> 1,
    'per_page' => 3,
]);

响应document

200 Get 状态码
{
    "data": [
        {
            "type": "thread",
            "id": "b4e08256e10111e9a9330a58ac1302c9",
            "attributes": {
                "title": "hhh",
                "read_count": 4,
                "post_count": 2,
                "like_count": 0,
                "created_at": "2019-09-27 16:35:05",
                "updated_at": "2019-09-27 16:37:24"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "v_zuolin"
                    }
                },
                "category": {
                    "data": {
                        "type": "category",
                        "id": "62ad3550bff611e9b0820a58ac13036d"
                    }
                }
            }
        }
    ],
    "links": {
        "first": "https://***.lexiangla.com/cgi-bin/v1/threads?per_page=1&***",
        "last": "https://***.lexiangla.com/cgi-bin/v1/threads?per_page=1&***",
        "prev": null,
        "next": "https://***.lexiangla.com/cgi-bin/v1/threads?per_page=1&***"
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 753,
        "path": "https://***.lexiangla.com/cgi-bin/v1/threads",
        "per_page": 1,
        "to": 1,
        "total": 753
    },
    "included": [
        {
            "type": "staff",
            "id": "dwww",
            "attributes": {
                "name": "dwww",
                "english_name": null,
                "organization": "dwdwe"
            }
        },
        {
            "type": "category",
            "id": "62ad3550bff611e9b0820a58ac13036d",
            "attributes": {
                "name": "fefe"
            }
        }
    ]
}

参数说明

参数 说明
thread.type 资源对象类型,为thread,表示资源为论坛
thread.id 帖子实体ID
thread.title 帖子的标题
thread.created_at 帖子的创建时间
thread.updated_at 帖子的更新时间
thread.read_count 帖子的访问量
thread.post_count 帖子的回复数量
thread.like_count 帖子的收藏数量
relationships.owner 帖子的创建人
relationships.category 帖子所属类型

获取单条帖子

接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}

参数说明:

参数 是否必须 默认值 说明
ThreadID 帖子的ID

SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$response = $Lxapi->getThread('51bb2f84a67c11e8ae1610e7c61c70fc');

响应document

200 状态码

{
    "links":{
        "self":{
            "href":"https://lxapi.lexiangla.com/cgi-bin/v1/threads/51bb2f84a67c11e8ae1610e7c61c70fc"
        }
    },
    "data":{
        "type":"thread",
        "id":"51bb2f84a67c11e8ae1610e7c61c70fc",
        "attributes":{
            "title":"通过API创建帖子",
            "content":"<p>这是一条通过LXAPI创建的帖子</p>",
            "summary":"这是一条通过LXAPI创建的帖子",
            "read_count":100,
            "post_count":0,
            "like_count":0,
            "created_at":"2018-08-22 09:55:00",
            "updated_at":"2018-08-22 09:55:00"
        },
        "relationships":{
            "owner":{
                "data":{
                    "type":"staff",
                    "id":"StaffID"
                }
            },
            "category":{
                "data":{
                    "type":"category",
                    "id":"ba96198e4e6c11e6bd740800278acc25"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"StaffID",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"category",
            "id":"ba96198e4e6c11e6bd740800278acc25",
            "attributes":{
                "name":"产品讨论"
            }
        }
    ]
}

404 状态码

{
    "errors":{
        "detail":"不存在ID为`51bb2f84a67c11e8ae1610e7c61c70ff`的thread资源"
    }
}

删除帖子

接口调用说明:

DELETE https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}

参数说明:

参数 是否必须 默认值 说明
ThreadID 帖子的ID

SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
$response = $Lxapi->deleteThread('StaffID','ef380b7ca67911e89a9f10e7c61c70fc');

响应document

204 No Content 状态码
[]
404 Not Found 状态码
{
    "errors":{
        "detail":"不存在ID为`5e47c14a5a3d11e78a830800278acc25`的thread资源"
    }
}

创建回帖

接口调用说明:

POST https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}/posts

请求document

{
    "data":{
        "type":"post",
        "attributes":{
            "content":"<p>顶</p>"
        }
    }
}

参数说明:

参数 是否必须 默认值 说明
ThreadID 要回复的帖子ID
content 回帖内容

SDK封装方法使用示例:

$attributs = [
  'content' => '<p>顶</p>',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postThreadPost(StaffID, ThreadID, $attributs, $options = []);

响应document

201 Created 状态码
{
    "links":{
        "self":{
            "href":"https://lxapi.lexiangla.com/cgi-bin/v1/threads/63c88fb0831c11e888d65254002b6735/posts/4ad747ce834b11e89a7f5254002b6735"
        }
    },
    "data":{
        "type":"post",
        "id":"4ad747ce834b11e89a7f5254002b6735",
        "attributes":{
            "content":"<p>顶</p>",
            "floor":1,
            "summary":"顶",
            "updated_at":"2018-07-09 15:40:03",
            "created_at":"2018-07-09 15:40:03"
        },
        "relationships":{
            "owner":{
                "data":{
                    "type":"staff",
                    "id":"StaffID"
                }
            },
            "thread":{
                "data":{
                    "type":"thread",
                    "id":"63c88fb0831c11e888d65254002b6735"
                }
            }
        }
    },
    "included":[
        {
            "type":"staff",
            "id":"StaffID",
            "attributes":{
                "name":"张三",
                "english_name":"ThreeZhang",
                "organization":"运营组"
            }
        },
        {
            "type":"thread",
            "id":"63c88fb0831c11e888d65254002b6735",
            "attributes":{
                "title":"通过API创建帖子",
                "summary":"这是帖子内容,支持富文本",
                "created_at":"2018-07-09 10:04:19"
            }
        }
    ]
}

获取回帖

接口调用说明:

Get https://lxapi.lexiangla.com/cgi-bin/v1/threads/{ThreadID}/posts

参数说明:

参数 是否必须 默认值 说明
ThreadID 获得回复的帖子ID

SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->getThreadPost('53ddebb6da1111e9ace50a58ac1303c1');

响应document

200 Get 状态码
{
    "data": [
        {
            "type": "post",
            "id": "ca8bb86ee10111e9ae3b0a58ac1302c9",
            "attributes": {
                "floor": 1,
                "content": "<p style=\"text-align:left;\">hhhh</p>\n<p style=\"text-align:left;\">hhh</p>\n<p>hhh</p>",
                "summary": "hhhhhhhhhh",
                "created_at": "2019-09-27 16:35:42",
                "updated_at": "2019-09-27 16:35:42"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "v_zuolin"
                    }
                }
            }
        },
        {
            "type": "post",
            "id": "07706680e10211e9afab0a58ac1302c9",
            "attributes": {
                "floor": 2,
                "content": "<p style=\"text-align:left;\">hhhhh</p>\n<p style=\"text-align:right;\">hhhh</p>\n<p style=\"text-align:left;\">hhhh</p>",
                "summary": "hhhhhhhhhhhhh...",
                "created_at": "2019-09-27 16:37:24",
                "updated_at": "2019-09-27 16:37:24"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "vikylin"
                    }
                }
            }
        },
        {
            "type": "post",
            "id": "f0a6a572e36311e9bc375254009b5a66",
            "attributes": {
                "floor": 3,
                "content": "<p>fwwfwew</p>",
                "summary": "fwwfwew",
                "created_at": "2019-09-30 17:23:19",
                "updated_at": "2019-09-30 17:23:19"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "vicheng"
                    }
                },
                "reference": {
                    "data": {
                        "type": "post",
                        "id": "ca8bb86ee10111e9ae3b0a58ac1302c9"
                    }
                }
            }
        },
        {
            "type": "post",
            "id": "7f8691d0e36411e9a5b65254009b5a66",
            "attributes": {
                "floor": 4,
                "content": "<p>fawfaw</p>",
                "summary": "fawfaw",
                "created_at": "2019-09-30 17:27:18",
                "updated_at": "2019-09-30 17:27:18"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "vicheng"
                    }
                },
                "reference": {
                    "data": {
                        "type": "post",
                        "id": "07706680e10211e9afab0a58ac1302c9"
                    }
                }
            }
        },
        {
            "type": "post",
            "id": "9a72c2f2e36411e9b9995254009b5a66",
            "attributes": {
                "floor": 5,
                "content": "<p>wafawfwafwwae</p>",
                "summary": "wafawfwafwwae",
                "created_at": "2019-09-30 17:28:03",
                "updated_at": "2019-09-30 17:28:03"
            },
            "relationships": {
                "owner": {
                    "data": {
                        "type": "staff",
                        "id": "vicheng"
                    }
                },
                "reference": {
                    "data": {
                        "type": "post",
                        "id": "07706680e10211e9afab0a58ac1302c9"
                    }
                }
            }
        }
    ],
    "included": [
        {
            "type": "staff",
            "id": "v_zuolin",
            "attributes": {
                "name": "vikylin",
                "english_name": null,
                "organization": "develop"
            }
        },
        {
            "type": "staff",
            "id": "vicheng",
            "attributes": {
                "name": "33358",
                "english_name": null,
                "organization": "develop"
            }
        },
        {
            "type": "post",
            "id": "ca8bb86ee10111e9ae3b0a58ac1302c9",
            "attributes": {
                "floor": 1,
                "summary": "hhhhhhhhhh",
                "created_at": "2019-09-27 16:35:42"
            }
        },
        {
            "type": "post",
            "id": "07706680e10211e9afab0a58ac1302c9",
            "attributes": {
                "floor": 2,
                "summary": "hhhhhhhhhhhhh...",
                "created_at": "2019-09-27 16:37:24"
            }
        }
    ]
}

参数说明

参数 说明
threads.type 资源对象类型,为posts,表示资源为回帖
threads.id 回帖实体ID
threads.floor 回帖楼层
threads.content 回帖内容
threads.summary 回帖概要
threads.created_at 回帖的创建时间
threads.updated_at 回帖的更新时间
threads.owner 回帖的创建人
threads.reference 回帖的回复