GithubHelp home page GithubHelp logo

sharing_land's Introduction

详细设计文档

📚︎1. 概述

1.1 范围

本文档主要是对项目 [闲置土地共享] 的相关需求的详细分析与设计, 但仅对后端服务器给出具体的算法与结构设计, 对小程序方面只给出部分要求与规范以及指导建议。

1.2 包含

  • 🌊按流程的详解步骤
  • 🐬数据库设计与使用
  • 👨‍🔧接口的设计与使用例

1.3 设计结构

本文将以 每个待实现功能 为基本模块进行编写,

详细分析 功能 并给出 解决方案, 解决方案中部分将包含 前端 和 后端 工作

⚙️2. 功能列表

3. 功能详细设计

3.1 账号登录系统

小程序中账号登录将采用微信官方提供的登录相关接口

在本系统中, 将以如下方式实现

sequenceDiagram
小程序->>小程序: wx.login()获取code
小程序->>服务器: wx.request()发送code
服务器->>微信接口服务: GET 登录凭证效验接口<br>appid + appsecret + code
微信接口服务->>服务器: 返回 session_key + openid <br>或 errcode + errmsg
服务器->>服务器: 将获取的openid生成jwt_token返回给用户<br>若openid首次出现将openid存入数据库
服务器->>小程序: 返回登录信息errcode + token
小程序->>小程序: 将token存入storage
小程序->>服务器: 取出token存入header中<br>调用wx.request()发起业务请求
服务器->>服务器: 验证token正确性并解析出openid
服务器->>小程序: 返回业务数据
Loading

说明

  • 小程序:

    在用户进入小程序时, 可展现一个登录界面, 点击登录按钮调用 login函数,

    login函数:

    首先调用 wx.login(), 获取到code字段, 将code 字段通过 /api/user/login请求发送到服务器 服务器的host应存储为一个全局变量以便修改

    返回体中有errcode,(token)或(errmsg)

    errcode -> 0: 告知用户登录成功, 将取得的token存入本地storage, 以待后续业务请求。然后跳转到主界面

    附: wx.setStorage(Object object) | 微信开放文档 (qq.com)

    errcode -> !0: 告知用户登录错误, 显示错误原因

    !!!记住此后的请求 !未! 标明无需Token的 !都! 要在请求头中加Token鉴权!!! 字段就命名为 'Token' 一旦服务器返回HTTP状态码401就需要求用户重新登录

  • 服务器:

    在接受到上述接口传来的js_code后,向微信后台发起请求auth.code2Session, 将数据处理为上述接口所需数据形式返回。

    返回的数据中errcode, errmsg继承微信后台获取到的数据, **token**由jwt工具生成, 有效时间暂定为 7 day。

    同时, 判断获取到的openid(作为用户ID)是否已经在数据库存在,

​ 存在: 更新nickname,avatarurl

​ 不存在:新插入一行用户数据

3.2 闲置土地信息管理

用户所拥有的核心功能是能够发布、删除、修改闲置土地信息

我们拥有闲置土地这一个实体对象,联合用户、评论对象有以下实体关系模型

graph LR;
a1((uid)) --- a[user]
a2((openid)) --- a
a3((nickname)) --- a
a4((avartar_url)) --- a
a --1--- rab{have}
rab --0...*--- b[land]
b --- b1((lno))
b --- b2((description))
b --- b3((image_urls))
b --- b5((create_time))
b --- b6((modify_time))
b --- b7((position))
a --1--- rac{post}
rac --0...*--- c[comment]
c --0...*--- rbc{on}
rbc --1--- b
c --- c1((cno))
c4((content)) --- c
c5((post_time)) --- c
Loading

由此得到数据库结构, 在表结构创建的comment里有各个字段的解释信息

现在我们定义用户 发布土地流程:

sequenceDiagram
小程序->>小程序:要求用户填写符合规范的发布信息
小程序->>服务器:将发布信息解析成各个字段<br>从storage取出token放入请求<br>向服务器发送发布信息请求
服务器->>服务器:将图片存入本地并生成url<br>将各字段存入数据库
服务器->>小程序:返回发布状态
Loading

说明:

  • 小程序:

    用户点击一个发布土地按钮, 进入土地信息填写界面, 该界面应该有

    • 填写土地描述: 填写文本信息的土地详情描述
    • 选择描述图片: 选择图片信息
    • 选择地理位置: 调用地图接口选择地理位置获取经纬度,可以去查一下腾讯地图API的调用使用

    将土地描述存入description,经纬度[$经度,$维度]的格式存入position

    点击提交按钮后

    首先 将图片通过 /api/image/upload上传到服务器,服务器会返回每张图片在服务器调用的url

    然后 将其他信息通过 /api/land/create 上传到服务器

    !注意! 你需要把多个url处理为[url1,url2,url3]列表形式,把地理位置处理成[lng-float,lat-float]的形式,URL必须满足形如http://xxxxxx的形式 所有数据必须以指定格式请求,否则服务器将返回422错误码

  • 服务器:

    本文档写到这里时已经该环节over了,略...

现在提供用户查询自己发布的土地的功能:

sequenceDiagram
小程序->>服务器:发起请求调用接口/api/land/query
服务器->>服务器:根据请求内容更改信息
服务器->>小程序:返回更改状态
Loading

4.API汇总

/api/user/login

/api/upload/image

/api/land/create

5.数据库说明

5.1 USER表

uid openid nickname avatar_url
CREATE TABLE User
(
    uid        INT AUTO_INCREMENT PRIMARY KEY COMMENT '序号',
    openid     VARCHAR(128) NOT NULL UNIQUE COMMENT '小程序开放ID',
    nickname   VARCHAR(128) COMMENT '微信昵称',
    avatar_url VARCHAR(512) COMMENT '微信头像链接'
);

5.2 LAND表

lno description image_urls uid create_time modify_time position
create table Land
(
    lno         int auto_increment primary key comment '序号',
    description varchar(1024) not null comment '描述',
    image_urls  varchar(1024) comment '描述图标链接 以;作为分割符',
    uid         int comment '发布的用户序号',
    position    varchar(64)  not null comment '经纬度 例子 127.2131231;67.1312332',
    create_time datetime     not null comment '创建时间',
    modify_time datetime comment '修改时间',
    foreign key (uid) references User (uid)
)

5.3 COMMENT表

cno uid content lno post_time
create table Comment
(
    cno       int unsigned auto_increment primary key comment '序号',
    uid       int          not null comment '留言的用户序号',
    content   varchar(255) not null comment '留言内容',
    lno       int          not null comment '留言的土地序号',
    post_time datetime     not null comment '留言时间',
    foreign key (uid) references User (uid),
    foreign key (lno) references Land (lno)
)

6.测试数据

token:

eyJ0eXAiOiJqd3QiLCJhbGciOiJIUzI1NiJ9.eyJvcGVuaWQiOiJvR1JMMTRvQ0dpamZsb1BmaXdBRl9DQmlXRnJRIiwiZXhwIjoxNjUyNzUwNTgyfQ.URMmx_YylADa7nFN_ofA407vVj6hWBTe4JiStvHDgOk

sharing_land's People

Contributors

2ndelement avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.