领域模型
微信云开发
云函数
登陆
wx.cloud.callFunction({ name: 'login', data: {} } return { is_new_register: true, user: { _id: "10001", _openid: "oOPyL5fGUU01L-THxvrYFRI9Tq6c", name: "小马哥", avatar: "https://wx.qlogo.cn/mmopen/vi_32/qWf1krg/132" } }
发送消息
wx.cloud.callFunction({ name: 'sendMsg', data: { _id: '雪花算法', user_id: '10001', // 发送人user_id group_id: 'groupId', // group_id与receiver_id至少传一个,都传时以group_id为准 receiver_id: '1239197665867206656', // 接收人user_id avatar: 'cloud://test-b51be.7465-test-b51be-1301504934/timg.jpg', name: '小马哥', msg_type: 'text', // text,image text_content: '小马哥发送的消息' } } return { _id: "100010002001", groupId: "groupId" }
消息已读
wx.cloud.callFunction({ name: 'msgReaded', data: { user_id: '10001', group_id: 'groupId', // group_id与receiver_id至少传一个,都传时以group_id为准 msg_id: '100010002001' // 已读最新消息的id } } return {}
下单
// 接单时调用 wx.cloud.callFunction({ name: 'placeOrder', data: { user_id: '10002', requirement_id: '需求id' } } return { id: "order_id" }
接受订单
// 需求发布者接受申请 wx.cloud.callFunction({ name: 'acceptOrder', data: { user_id: '10001', // 需求发布者id order_id: 'orderId' } } return {}
数据库示例
chatgroups: { "_id": "1583740868254290081", "user_id_1": "10001", "unread_1": 2, "last_msg_1": "我再考虑一下", "user_id_2": "10002", "unread_2": 0, "last_msg_2": "您考虑的如何了" } chatroom: { "_id": "1583740869258595063", "user_id": "10001", "name": "小马哥", "group_id": "1583740868254290081", "avatar": "https://wx.qlogo.cn/mmopen/vi_32/6rW8JKW0ZbSz4tguEUgDKc7PgC1g3feg0YCiadr5ybOWwhqAEe33QyyRF18Azd6Nd49anpU9d3LmIVrgqWf1krg/132", "text_content": "我再考虑一下", "msg_type": "text", "send_time": { "$date": "2020-03-09T08:01:08.254Z" } } users: { "_id": "10001", "openid": "oOPyL5fGUU01L-THxvrYFRI9Tq6c", "avatar": "https://wx.qlogo.cn/mmopen/vi_32/6rW8JKW0ZbSz4tguEUgDKc7PgC1g3feg0YCiadr5ybOWwhqAEe33QyyRF18Azd6Nd49anpU9d3LmIVrgqWf1krg/132", "name": "小马哥", "sex": "男", "birthday": "1964-10", "mobile": "1800000001", "email": "mht@qq.com", "ability": "企业管理,充钱教学", "location": { "_id": 10201, "name": "静安区" }, "stars": 5, "certificate": "MBA", "self_description": "你如今遇到的全部问题,充钱都能解决", "educations": [{ "college": "清华大学", "major": "土木工程", "degree": "学士", "begin": "2008", "end": "2012" }], "comments": [{ "comment_by": 10002, "stars": 1, "remark": "只会骗氪", "createTime": "2020-03-09T01:24:51.254Z" }], "create_time": { "$date": "2020-03-09T01:24:51.254Z" }, "modify_time": { "$date": "2020-03-09T01:24:51.254Z" } } favorites: { "_id": "1583740869258495067", "user_id": "10002", "requirement_id": "1583750869268195888", "person_id": 10001, "tyoe": "" // requirement,person "create_time": { "$date": "2020-03-09T01:24:51.254Z" } } requirementTickets: { "_id": "1583740869258495066", "state": "PROCESSED", "user_id": "10001", "name": "三室两厅装修设计图", "reward": 6000, "location": { "_id": 10201, "name": "静安区" }, "description": "xxxx", "create_time": { "$date": "2020-03-09T01:24:51.254Z" }, "modify_time": { "$date": "2020-03-09T01:24:51.254Z" } } orders: { "_id": "1583740869258495068", "user_id": "10002", "state": "ACCEPTED", "img_url": "https://wx.qlogo.cn/mmopen/vi_32/6rW8JKW0ZbSz4tguEUgDKc7PgC1g3feg0YCiadr5ybOWwhqAEe33QyyRF18Azd6Nd49anpU9d3LmIVrgqWf1krg/132", "name": "三室两厅装修设计图", "amount": 6000, "requirement_id": "1583740869258495066", "create_time": { "$date": "2020-03-09T01:24:51.254Z" }, "modify_time": { "$date": "2020-03-09T01:24:51.254Z" } }
后端接口设计(后续实现)
认证方式
http headers中添加以下属性:javascript
"ACCESS_TOKEN": "xbj:dsruvhgngr==" // token由登陆接口获取java
REST接口
接口参数中红色字体表示必填
接口名 | 微信一键登陆 |
---|---|
url | POST://{host}/login_wx |
request body | { "code": "xbj:sdsxcdf==", "avatar": "https://xcx.qq.com/ajde", "name": "张三", "sex": "male" } |
response body | { "id": 10001, "token":"xbj:dsruvhgngr==", "openId": "xxx", "avatar": "xxx", "name":"张三" } |
http status | 200 - 成功 201 - 新注册用户 400 - 缺少必填参数 |
接口名 | 编辑用户信息 |
---|---|
url | PUT://{host}/users/{id} |
request body | { "name": "张三", "avatar": "https://xcx.qq.com/ajde", "sex": "male", "birthday":"1999-10-10", "ability":"外卖运营平台", "mobile":18000000001, "email":"100001@qq.com", "location": {"id": 10201} } |
http status | 200 - 成功 400 - 缺少必填参数 401 - 登陆认证失败 403 - 禁止访问 404 - 用户不存在 |
接口名 | 编辑自我介绍 |
---|---|
url | PUT://{host}/users/{id}/self-description |
request body | { "selfDescription":"xxxxxxxxx" } |
http status | 200 - 成功 401 - 认证失败 403 - 禁止访问 404 - 用户不存在 |
接口名 | 编辑自我介绍 |
---|---|
url | PUT://{host}/users/{id}/educations |
request body | [{ "college": "清华大学", "major": "土木工程", "degree": "硕士学位", "begin": "2008-09", "end": "2012-06" }] |
http status | 200 - 成功 401 - 认证失败 403 - 禁止访问 404 - 用户不存在 |
接口名 | 编辑技能证书 |
---|---|
url | PUT://{host}/users/{id}/certificate |
request body | { "certificate":"xxxxxxxxx" } |
http status | 200 - 成功 401 - 认证失败 403 - 禁止访问 404 - 用户不存在 |
接口名 | 用户信息 |
---|---|
url | GET://{host}/users/{id} |
request params | optional=educations&optional=comments |
response body | { "id": 10001, "openId": "mht-321", "name": "小马哥", "sex": "male", "birthday": "1990-09-16", "mobile": 18666888999, "email": "xmg666@qq.com", "ability": "忽悠,充钱", "location": { "id": 10201, "name": "静安区" }, "stars": 1, "certificate": "MBA", "selfDescription": "来,我来教你充值!", "educations": [{ "id": 1, "userId": 10001, "college": "清华大学", "major": "土木工程", "degree": "学士", "begin": "2008", "end": "2012" }], "comments": [{ "id": 1, "user_id": 10001, "comment_by": 10002, "stars": 1, "remark": "只会骗氪", "createTime": "2020-03-09 01:24:51" }] } |
http status | 200 - 成功 401 - 认证失败 404 - 用户不存在 |
接口名 | 个人接单 |
---|---|
url | GET://{host}/users/{id}/orders |
request params | optional=requirement_details |
response body | [{ "id":"10002", "state":"ACCEPTED", "img_url": "https://wx.qlogo.cn/mmopen/vi_32/rg/132", "name":"三室两厅装修设计图", "amount":"6000", "requirement_id": 10086 }] |
http status | 200 - 成功 401 - 认证失败 403 - 禁止访问 404 - 用户不存在 |
接口名 | 个人收藏 |
---|---|
url | GET://{host}/users/{id}/favorites |
response body | [{ "id":"10002", "userId":"10001", "state":"PUBLISHED", "name":"三室两厅装修设计图", "amount":"6000", "description":"xxxx" }] |
http status | 200 - 成功 401 - 认证失败 403 - 禁止访问 404 - 用户不存在 |