@liuwanwei
2017-11-06T18:40:36.000000Z
字数 5249
阅读 1104
接力助学
协议的请求包分为两种:RESTFul 和非 RESTFul。
RESTFul 接口使用以下四种动词实现数据的基本操作。
注意:下面的所有 URL 地址都省略了 HOST 字段,在 jlzx 项目中,客户端通过下面的域名访问数据:
访问路径是目标对象名字的单数形式。例如,要查询用户创建的收货地址,路径是:
/address
访问路径是目标对象名字的复数形式:
/addresses
访问路径是要删除对象名字的复数形式,再加上对象 Id:
/addresses/1
要修改对象名字的复数形式,再加上对象 Id:
/addresses/1
非 RESTFul 接口只有跟用户注册、登录相关的,包括:
请在具体协议中查看对应的格式。
基本格式为:
{
"status": 0,
"msg": "登录成功",
"object": {
},
"items": [
{
},
],
}
对于登录、注册接口,以及 RESTFul API 中的添加(POST)、修改(PATCH)接口,由于都是对单个对象做操作,所以在执行完毕后,会将相关对象信息放在 额外的 object 字段中,返回,如:
"object": {
"id": 15,
"username": "18037963805",
"password": null,
"revenueEarned": 0,
"revenueLeft": 0,
"balance": 0,
"kactivityId": 0,
"grade": 0,
"created_at": 1477993502,
"updated_at": 1477993502,
"createdAt": "2016-11-01 17:45:02",
"updatedAt": "2016-11-01 17:45:02"
}
对于查询(GET)接口,会返回一个 额外的 items 字段,它是一个数组,包含查询到的数据,如:
"items": [
{
"id": 8,
"serialNumber": "155818646317310",
"kuserId": 15,
"packageId": 1,
"addressId": 0,
"logisticCompany": null,
"logisticNumber": null,
"payMode": 0,
"status": 0,
"createdAt": "2016-11-01 17:46:11",
"updatedAt": "2016-11-01 17:46:11"
}
]
当错误发生时,一般会将错误的编码(整型)和错误提示信息一起返回:
{
"status": -10,
"msg": "已经购买过该套餐"
}
上面的错误发生在重复购买同一套餐时。
请求:
反馈:
{
"status": 0,
"msg": "操作成功",
"object": {
"id": 78
"username": "liuwanwei",
"status": 10,
"access_token" : "rSOiVXEf4wb8oLk5BBXxy2BjZjKIJIkK",
"createdAt": "2016-11-01 17:45:02",
"updatedAt": "2016-11-01 17:45:02"
}
}
注意:
用户信息中的时间跟别处不同,是个 time_t 类型,使用时请注意。这是因为“不可抗力”造成的:由于使用了 yii2-admin,它在处理用户登录时,提供提供的表结构中就使用了 time_t 类型。
请求:
反馈:
{
"status": 0,
"msg": "操作成功",
"object": {
"id": 15,
"username": "18037963805",
"password": null,
"revenueEarned": 0,
"revenueLeft": 0,
"balance": 0,
"kactivityId": 0,
"grade": 0, // 用户等级
"access_token": "15h55D9ZzF6T1UGQqZX9xJtaNsW1r53kn-",
"createdAt": "2016-11-01 17:45:02",
"updatedAt": "2016-11-01 17:45:02"
}
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功"
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功"
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功"
}
请求:
反馈:
跟登录接口反馈信息格式保持一致。
服务器会检查这个手机号是否最近通过批量报单方式报单,检查失败时,会返回参数错误信息。
反馈:
{
"status": 0,
"msg": "操作成功"
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功",
"items": [
{
"id": 9,
"serialNumber": "155819A4B159408",
"kuserId": 15,
"packageId": 1,
"kpackage":{
"id": 1,
"name": "家庭洗护套装",
"content": "美白、洗护、三合一",
"price": 520,
"coverUrl": "http://1.upaiyun.com/0.jpg",
"kactivityId": 1,
"count": 1000,
"type": 0,
"weight": 2,
"recommended": 1,
"operatorId": 6,
"createdAt": "2016-11-01 15:58:09",
"updatedAt": "2016-11-03 17:35:50",
"deleted": 0
},
"addressId": 0,
"address":{
"id": 3,
"kuserId": 15,
"name": "谢烟客",
"mobile": "18037963805",
"address": "金城美邻 2 号楼 1801",
"inUse": 0,
"createdAt": "2016-11-02 11:47:09",
"updatedAt": "2016-11-02 11:47:09",
"deleted": 0
},
"logisticCompany": null,
"logisticNumber": null,
"payMode": 0,
"status": 0,
"createdAt": "2016-11-02 16:32:49",
"updatedAt": "2016-11-02 16:32:49"
}
]
}
请求:
反馈:
{
"status": 0,
"msg": "成功",
"object": {
"id": 9,
"serialNumber": "155819A4B159408",
"kuserId": 15,
"packageId": 1,
"addressId": 0,
"logisticCompany": null,
"logisticNumber": null,
"tokenId":"1234565421789",
"payMode": 0,
"status": 0,
"createdAt": "2016-11-02 16:32:49",
"updatedAt": "2016-11-02 16:32:49"
}
}
请求:
反馈:
{
"status": 0,
"msg": "成功",
"object": {
"id": 9,
"serialNumber": "155819A4B159408",
"kuserId": 15,
"packageId": 1,
"addressId": 0,
"logisticCompany": null,
"logisticNumber": null,
"payMode": 0,
"status": 0,
"createdAt": "2016-11-02 16:32:49",
"updatedAt": "2016-11-02 16:32:49"
}
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功"
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功",
"items": [
{
"id": 3,
"kuserId": 15,
"name": "谢烟客",
"mobile": "18037963805",
"address": "西工区王城大道,金城美邻 2 号楼 1801",
"inUse": 0,
"createdAt": "2016-11-02 11:47:09",
"updatedAt": "2016-11-02 11:47:09",
"deleted": 0
}
]
}
请求:
反馈:
{
"status": 0,
"msg": "成功",
"object": {
"id": 4,
"kuserId": 15,
"name": "谢烟客",
"mobile": "18037963805",
"address": "西工区王城大道,金城美邻 2 号楼 1801",
"inUse": 0,
"createdAt": "2016-11-02 16:57:18",
"updatedAt": "2016-11-02 16:57:18",
"deleted": 0
}
}
请求:
反馈:
{
"status": 0,
"msg": "成功",
"object": {
"id": 4,
"kuserId": 15,
"name": "谢烟客",
"mobile": "18037963805",
"address": "西工区王城大道,金城美邻 2 号楼 1801",
"inUse": 0,
"createdAt": "2016-11-02 16:57:18",
"updatedAt": "2016-11-02 16:57:18",
"deleted": 0
}
}
请求:
反馈:
{
"status": 0,
"msg": "操作成功"
}