collegeshare-api
产品原型
原型设计
- collegeshare
usecases
api
本文档是校园共享平台collegeshare数据服务接口文档(JXAPIS),供产品和技术开发团队进行产品开发参考使用。
主要服务为三个,分别为:大咖有约(type_id:1),才艺互教(type_id:2),帮过考试(type_id:3)
作者:见校技术团队
版本:v1.0
创建时间:2016.6.29
说明
1.1 Methods
- GET - 获取资源列表
- POST - 创建资源
- PUT - 更新资源
- DELETE - 删除资源
1.2. Status Codes
- 200 - Success. Request completed.
- 201 - Success. New resource created.
- 204 - Success. No content to return. Only the status code returns.
- 400 - Bad Request. The request could not be parsed.
- 401 - Unauthorized. User is not logged in, cannot access resource.
- 404 - Not Found. resource doesn’t exist.
- 422 - Unprocessable Entity. The request could not be parsed due to validation errors.
- 429 - Rate limit exceeded, try again later.
- 500 - Server error
- 503 - Service Unavailable.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
1.3. Request Parameters
多数请求所必须的参数已经被写入到 HTTP HEADER 。请参考 HTTP HEADER 部分。
所请求返回数据包含列表,需向服务器提交以下两个参数:
- offset - integer - 非必填,default = 0
- limit - integer - 非必填, default = 10
1.4. Response Envelope
全部接口的请求返回遵循统一的返回格式,包含“result”、“data”、“cursor”、“success”、“errors”等部分。查看下表,了解个部分具体说明:
- result - 包括两种状态:“ok”和“not_ok”,不可为空。
- data - 返回具体的数据,可以为空。 默认为空Object,存在数据时不一定为Object,有可能会是Array
- cursor - 返回所包含数据,可以为空。默认为空Object,结构固定
- success - 成功返回信息,可以为空。默认为空字符”“,结构固定
- errors - 错误返回信息,可以为空。默认空Array,结构固定
样例:
{
"result": "ok"
"data":[
{
"id": 12306,
"title": "这是一个文章标题",
"summary": "这是一个文章的摘要"
},
{
"id": 12306,
"title": "这是一个文章标题",
"summary": "这是一个文章的摘要"
},
]
"cursor":{
"total": 100,
"offset": 10,
"limit": 10
}
"success": "成功操作",
"errors": [
{
"field": "username",
"message": "Bad Authentication data"
},
{
"field": "password",
"message": "Bad Authentication data"
},
]
}
result
返回“result”仅仅包含两个结果:“ok”和“not_ok”。返回结果和状态码无关,仅仅表明了接口是否按请求方的预期完成。 比如,客户端请求修改某用户的个人信息,客户端提交的信息在服务器验证后有两项信息不符合验证条件,因此整个操作失败。 此时,http返回的状态码为“422”,result为“not_ok”。
cursor
返回“cursor”包括:total current per_page。
- total - 全部条数
- offset - 当前所在位置
- limit - 每页条数
success
如果接口操作成功,如果有成功的提示信息,在“success”部分输出。
errors
当客户端向接口的请求失败,“errors”用来返回具体错误信息。“errors”包含了一个数组,每一个数组包括了一个具体的错误对象。 每一个具体的错误对象都包含了“错误信息”(message)和“错误字段”(field)。如果错误信息没有针对一个具体的错误字段, 错误字段的赋值为空。
1.5. Authentification
- 1.5.1. App Key and App Secret
所有调用JXAPIS接口服务的客户端都被看作一个应用(App),每个授权应用都被分配给一个 app_key 和一个 app_secret。 在发送所有服务请求前,客户端需要将 app_key 和 app_secret 连接并生成一个MD5字符串,被包含在 HTTP HEADER ,作为一个通用参数 供服务器进行验证。如果 signature 认证失败,服务器返回 422 错误。 - 1.5.2. Access Token
用户进行登录请求时,需要提供登录手机号/昵称和密码进行登录。如果服务器端认证成功,返回给客户端一个 access_token, 在之后的请求中, 客户端都需要将 access_token 包含在 HTTP HEADER 中,用于标识用户的登录身份。如果用户登录失败或访问登录用户受控内容, 状态码返回 402。
1.6. HTTP Header
- app_key - Integer
- app_secret - String
- access_token - String
- device - String - 包括:“iphone“, “ipad”, “android”, “pc”, “h5”, “unknown”
- identifier - String
- app_version - String
- user_unique_key - String(凡是私有数据皆将user_guid等用户信息加密并调用)
账户
注册{post:/account/signup/phone}
请求参数
- phone - 必填
- username - 必填
- password - 必填
- captcha_id - 选填
- captcha_word - 选填
- 其中webapp验证码必填,iphone,android,ipad验证码不填
Request
##Headers
Content-Type: application/json
##Body
{
"username": "cindy",
"email": "13064538038",
"password": "l2220167",
"captcah_id": 12,
"captcha_word": "45CWTS"
}
Response 201
##Headers
Content-Type: application/json
##Body
{
"result": "ok",
"data":{},
"cursor":{},
"success": "用户创建成功!",
"errors": []
}
登录{post:/account/login/phone}
请求参数
- client_id - 必填 - app_key
- client_secret - 必填 - app_secret
- username - 必填 - 手机号码
- password - 必填
- grant_type - 必填(默认值:grant_type = “password”)
- captcha_id - 选填
- captcha_word - 选填
说明:- 对以网页为基础的应用,验证码必填,对“iphone”、“ipad”、“android”应用,验证码选填。
- 对以网页为基础的应用,登录错误失败5次,下一次就需要输入验证码。
request
##Headers:
Content-Type: application/json
##body
{
"client_id":23435123232,
"client_secret":"0186114ea30bc5b5178301f206eb0bbc",
"login": "13065469273",
"password": "l2220167",
"captcha_id": 13,
"captcha_word": "AWTUES",
"grant_type": "password"
}
Response 200
##Headers
Content-Type: application/json
##Body
{
"result": "ok",
"data":{
"access_token":"0186114ea30bc5b5178301f206eb0bbc",
"user_unique_key":"9986114ea30bc5e5178301f206eb0bab",
"expiration": 23435123232
},
"cursor":{},
"success": "",
"errors": []
}
自动登录{post:/account/sslogin}
请求参数
-
encrypted_code - 登陆验证密串
- 说明:该密串生成规则:用户GUID+10位秒级时间戳(python,int(time.time())) ,使用CI的 encode方法加密生成,密钥暂时未确定
Request
Headers:
Content-Type: application/json
Body:
{
"encrypted_code":"JBBNKL232AKJSALSA3495690JDSKAJSASDASBMNDMN4545ASNDMBASDA65656S6565656534343434DASDASDASD",
}
Response 200
Headers:
Content-Type: application/json
Body
{
"result": "ok",
"data":{
"access_token": "941df22661ee682774e4b7e4bb5261c669579c38",
"user_unique_key": "c2syn3k6tQThYLF3kNfzFS8OqZukIB1",
"expiration": "1439618283",
"user_guid": 1999912
},
"cursor":{},
"success": "",
"errors": []
}
微信登陆{post:/account/login/wechat}
如果用户不能以微信账号登录,result = “not_ok”。返回 errors,包括如下情况:
- wechat_uid 在系统中不存在,需要创建新账号,field = “reg”
请求参数
- wechat_access_token - 必填
- wechat_openid - 必填
- wechat_expired_in - 必填 ,秒级时间戳
- wechat_refresh_token - 可选
返回数据
access_token
如果用户登录成功,返回 access_token 字符串;否则返回空-
user_unique_key
- 如果用户登录成功,返回 user_unique_key 字符串;否则返回空
-
expiration
- 如果用户登录成功,返回 expiration;否则返回空
Request
Header:
Content-Type: application/json
Body:
{
"wechat_access_token": "0186114ea30bc5b5178301f206eb0bbc",
"wechat_openid": 2323123234,
"wechat_expired_in": "7200",
}
Response 200
Header:
Content-Type: application/json
Body
{
"result": "ok",
"data":{
"access_token":"0186114ea30bc5b5178301f206eb0bbc",
"user_unique_key": "9986114ea30bc5e5178301f206eb0bab",
"expiration": 2323123234,
"if_email_update_reminded":TRUE
},
"cursor":{},
"success": "",
"errors": []
}
Response 406
Headers:
Content-Type: application/json
如果该微信未授权过,则会出现如下错误
{
"result": "no_ok",
"data": {},
"cursor": {},
"success": "",
"errors": [
{
"field": "reg",
"message": "您是第一次授权,请先创建账号"
}
]
}
发送忘记密码确认邮件或短信{post:/account/forgot_psw}
验证重置密码请求{post:/account/forgot_password/verification}
重置密码{post:/account/forgot_password/reset}
验证短信{put:/account/verification/phone}
重新发送短信{post:/account/verification/email/resend/{user_unique_key}}
退出系统{delete:/account/logout}
请求参数
- device_token - 选填
Request
Headers:
Content-Type: application/json
Body:
{
"device_token": "0186114ea30bc5b5178301f206eb0bbc",
}
Response 200
Headers:
Content-Type: application/json
{
"result": "ok",
"data":{},
"cursor":{},
"success": "",
"errors": []
}
用户
用户属性(分为默认属性,设置属性(public),设置属性(private))
-
默认属性
- user_guid - int
user_name - string
- user_guid - int
-
设置属性(public)
- username - String - 同户名
- avatar - String - 头像(尺寸限制)
- signature - String - 用户签名
- is_auth - int(1为认证,0为未认证)
- score - float - 得分
- level - Int - 等级(名震江湖)
- rank - Int- 排名
- university_id - int - 高校id
- number_of_feeds - int - ta发起的
-
设置属性(private)
- student-ID - int
- priviledge - object - 用户权限属性,具体见usecase
- ci_to_next_level - Float - 距离下一个等级所需要的分数
- wealth_index - float - 财富值
- mobile - String - 用户手机号码
- participate - int - 用户参与服务id
获取用户id{get:/users/username/{username}}
请求参数
- username - 必填
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data": {
"user_guid": "184984"
},
"cursor": {},
"success": "",
"errors": []
}
获取用户公开信息{get:/users/{user_guid}}
请求参数
- avtatar - 必填(点其他不可浏览)
Request
Headers:
Content-Type: application/json
Body:
{
"fields":"avatar
"avatar_size":["50_50"]
}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data":[
{
"username":"zhangchiliang",
"avatar":"http://103.59.128.147/20004/avatar.jpg",
"signature":"i am yours",
"number_of_posts":233,
"score":12.34,
"rank":2309,
"level":名震江湖
}
],
"cursor":{},
"success": "",
"errors": []
}
热门用户列表{get:/users/list/hot}
请求参数
- total - 必填 - 请求数量
- fields - 选填
Request
Headers:
Content-Type: application/json
{
Body:
"total":20,
"fields":"avatar;signature;number_of_(待填)"
}
Response
Headers:
Content-Type: application/json
Body
{
"result": "ok",
"data":[
{
"username":"zhangchiliang",
"last_post_time_updated":34123234342424,
"avatar":"http://103.59.128.147/23223232/avatar.jpg"
},
{
"username":"mengcong",
"last_post_time_updated":34123234342424,
"avatar":"http://103.59.128.147/23223232/avatar.jpg"
}
],
"cursor":{
"total": 2
},
"success": "",
"errors": []
}
用户收藏服务id列表{get:/user/list/{user_unique_key}/bookmarks}
请求参数
- orderby - 选填
time_bookmarked (默认)
time_published - fields - 选填
- limit - 选填
- offset - 选填
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data":[
[
{
"service_guid":192024,
"title":"这是服务标题",
"type_id":1
"time_published":1306836623,
"time_created":1306836623,
"time_updated":1306836623,
"time_bookmarked":13606836623,
},
{
"post_guid":192024,
"title":"这是服务标题",
"type_id":2
"time_created":1306836623,
"time_updated":1306836623,
"time_bookmarked":13606836623,
}
]
],
"cursor":{
"total":2,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
社会化媒体账号(暂不填)
用户签名{put:/users/{user_unique_key}/signature}
请求参数
- new_signature - 必填
Request
Header:
Content-Type: application/json
Body:
{
"new_signature":"我的新签名"
}
Response 200
{
"result": "ok",
"data":{},
"cursor":{},
"success": "",
"errors": []
}
用户头像修改{put:/users/{user_unique_key}/avatar}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data":{
"url":"http://103.59.128.147:5000/332/343.jpg"
},
"cursor":{},
"success": "",
"errors": []
}
用户头像上传{post:/users/{user_unique_key}/avatar}
请求参数
- avatar - 必填 - octet-stream(不确定webapp和android的图像区别)
Request
Headers
Content-Type: multipart/form-data
Body
{
"avatar":"二进制乱码"
}
Response 200
Headers:
Content-Type: application/json
Body
{
"result": "ok",
"data":{
"url":"http://103.59.128.147:5000/332/343.jpg"
},
"cursor":{},
"success": "",
"errors": []
}
消息列表{get:/users/{user_unique_key}/letters}
请求参数
- username - 必填
Response 200
Headers:
Content-Type: application/json
Body
{
"result": "ok",
"data":[
{
"user_guid":1234,
"username":"zhangchiliang",
"avatar": "/user/zhangchiliang/avatar1232_30_30.jpg"
"time_letter_last_updated":3432344553
"letter_last_updated":"吉他一次能教几首歌呢"
},
{
"user_guid":1234,
"username":"mcong",
"avatar": "/user/mcong/avatar1232_30_30.jpg"
"time_letter_last_updated":3432342355
"letter_last_updated":"小提琴一次能教几首歌呢"}
]
"cursor":{},
"success": "",
"errors": []
}
服务
获取大咖有约最新列表{post:/service/bigshot/list}
请求参数
- sorting_type - 必填(default:综合排序,还有见过最多,评分最高,价格最低,分别为Integer{1,2,3,4})
返回数据
- relevance - Float-(相关度,排序标准)
- type_id - Int-(可能无用,暂时保留)
- service_guid - Int
- title - String
- time_published - Int
- summary - String
- authors - String
- authors_avatar
- authors_identity - String
- times_wish - Int
- times_meet - Int
- status - boolean - (待解决,已关闭的服务是否出现)
Request
Headers:
Content-Type: application/json
Body:
{
"sorting_type":1
}
Response 200
Headers:
Content-Type: application/json
Body:
{
{
"result": "ok",
"data":[
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
],
"cursor":{
"total":400,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
}
获取才艺互教最新列表{post:/service/talent/list}
请求参数
- sorting_type - 必填(default:综合排序,同上)
返回数据
- relevance - Float-(相关度,排序标准)
- type_id - Int-(可能无用,暂时保留)
- service_guid - Int
- title - String
- time_published - Int
- summary - String
- authors - String
- authors_avatar
- authors_identity - String
- times_wish - Int
- times_meet - Int
- status - boolean - (待解决,已关闭的服务是否出现)
Request
Headers:
Content-Type: application/json
Body:
{
"sorting_type":1
}
Response 200
Headers:
Content-Type: application/json
Body:
{
{
"result": "ok",
"data":[
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
],
"cursor":{
"total":400,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
}
获取帮过考试最新列表{post:/service/examination/list}
请求参数
- sorting_type - 必填(default:综合排序,同上)
返回数据
- relevance - Float-(相关度,排序标准)
- type_id - Int-(可能无用,暂时保留)
- service_guid - Int
- title - String
- time_published - Int
- summary - String
- authors - String
- authors_avatar
- authors_identity - String
- times_wish - Int
- times_meet - Int
- status - boolean - (待解决,已关闭的服务是否出现)
Request
Headers:
Content-Type: application/json
Body:
{
"sorting_type":1
}
Response 200
Headers:
Content-Type: application/json
Body:
{
{
"result": "ok",
"data":[
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
],
"cursor":{
"total":400,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
}
搜索(检索因子未定){post:/service/search}
请求参数
- keyword - 必填
- university_id - 必填(默认为university_auth)
- orderby - 选填 - 包括:相关度(relevance),发布时间(time_published),默认按照“相关度”排序
- limit - integer 选填 default:10
- offset - integer 选填 default:0
说明:keyword在被传输到API前,需要做encode处理
返回数据(此处response有问题,待修改)
- relevance - Float-(相关度,排序标准)
- type_id - Int-(可能无用,暂时保留)
- service_guid - Int
- title - String
- time_published - Int
- author - String
- author_avatar
- author_identity - String
- times_wish
- times_meet
- status - boolean-(两种,进行中和已关闭,暂时不设置返回,)
Request
Headers:
Content-Type: application/json
Body:
{
"keyword":"产品经理实习"
}
Response 200
Headers:
Content-Type: application/json
Body:
{
{
"result": "ok",
"data":[
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
{
"relevance":90.1,
"service_guid":3422,
"time_published":1306836623,
"title":"大学如何积累含金量高的实习",
"author":
{
"author_guid":23,
"author":"习近平",
"author_avatar":"http://103.59.128.147:5000/xijp/avatar.jpg"
"author_identity":"一个走上仕途的清华忧郁男人"
}
"times_wish":54
"times_meet":69
},
],
"cursor":{
"total":400,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
}
获取服务详情{get:/service/{service_guid}}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data":{
"post_guid":198613,
"title":"如何积累含金量高的实习",
"status":"processing",
"time_wish":50
"time_meet":69
"service_money":50
"meet_place":"线上"
"meet_time":"周日十点"
"time_created":1395159177,
"time_updated":31395159177,
"time_published":1395629311,
"if_current_user_bookmarked":FALSE,
"service_recommend_guid":9304,
"main":"这里是服务的主要内容,作者的牛(zhuang)逼历史,等等",
"author":
{
"guid": "233657",
"username": "常宁",
"user_identity": "中国传媒大学博士",
"avatar": null,
"user_university":"东北大学"
"user_desc":"大家好,我是习近平"
},
"number_of_bookmarks":12,(次数有必要?)
"number_of_comments":34,
},
"cursor":{},
"success": "",
"errors": []
}
想见{post:/service/wish}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result":"ok",
"data":{},
"cursor":{},
"success": "",
"errors": []
}
取消想见{delete:/service/wish}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result":"ok",
"data":{},
"cursor":{},
"success": "",
"errors": []
}
社交媒体分享{post:/service/{service_guid}/shares}
请求参数
- social_media - 必填
- sina_weibo
- tencent_weibo
- evernote
Request
Headers:
Content-Type: application/json
Body:
{
"social_media":"sina_weibo"
}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok"
"data":{}
"cursor":{}
"success": "",
"errors": []
}
学员评价
获取服务列表{get:/comments/list/{service_guid}}
服务创建评价(评论对话有必要?){post:/comments}
服务删除评价{delete:/comments}
我要共享
发现(后台定向推送?推送几条?){get:/discover/list}
Response 200
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data":[
[
{
"service_guid":192024,
"title":"院士面对面",
"type_id":1
"time_published":1306836623,
"time_created":1306836623,
"time_updated":1306836623,
"status":"published"
},
{
"service_guid":192025,
"title":"本专业的秘密",
"type_id":2
"time_published":1306836623,
"time_created":1306836623,
"time_updated":1306836623,
"status":"published"
}
]
],
"cursor":{
"total":2,
"offset":0,
"limit":10
},
"success": "",
"errors": []
}
支付
通用
短信
信模版代码
- 10001 “【见校敬上】您的验证码是{code}。如非本人操作,请忽略本短信”,
请求参数
- mobile - String 必填 手机号,暂时只支持国内手机号,允许带+86前缀或不带+86前缀的手机格式。
Request
Headers:
Content-Type: application/json
Response 201
Headers:
Content-Type: application/json
Body:
{
"result": "ok",
"data": {},
"cursor": {},
"success": "",
"errors": []
}