Home  >  Article  >  WeChat Applet  >  asp.net development of WeChat public platform (1) database design

asp.net development of WeChat public platform (1) database design

高洛峰
高洛峰Original
2017-02-14 11:54:592020browse

Before developing the WeChat public platform, first go to the WeChat official website to learn about the general situation here: http://mp.weixin.qq.com/wiki/index.php; after reading it, you have a rough idea and start designing the database. Consider what you can, and add what you haven’t considered later.

1. First is the user part. According to WeChat’s official interface combined with practical applications, the user part has three tables: user table, user information table, and user grouping table. I designed it as follows:

asp.net development of WeChat public platform (1) database design

2. After the user has designed it, there is the article part, including: article classification table and article table. The design is as follows:

asp.net development of WeChat public platform (1) database design

3. Yes With the user-related table, we can save users. With the table of the article module, we can query articles and return them based on the information entered by the user (return text, graphics, pictures, music, video, voice, etc.), but in actual application, There are situations where we need to specify specific keywords to return specific content, then we need a special specific keyword module, including: keyword table, keyword returned content table, the content table here looks like the above article The tables overlap, but this is not the case. Here is the reply content specified by specific keywords. You can specify to return text, graphics, or other multimedia information. When multimedia information is returned, the content is stored in the file address. The above article table is standard and universal. The article content table is used for user queries. In most cases, graphic information is directly returned. When the graphic information clicks on the link, it is the display address corresponding to this article. It is equivalent to a microsite, so the content table of the article and this keyword is designed separately to make it more convenient. Easy to manage. The design is as follows:

asp.net development of WeChat public platform (1) database design

4. Message recording. Record the messages sent by users to facilitate subsequent processing. For example, based on the last event message sent by the user, send it later. When using the same keyword, the content under the corresponding menu is returned, instead of the user sending a message with the corresponding menu option every time; customer service messages provide personalized services based on the recorded information, etc. Including: a record table of messages sent by users and a record table of messages replied to users. With these, the conversation with the user can be completely restored. Here is the process of recording the communication with the user. Specifically, what kind of messages sent by the user need to be returned? The message is determined by the business in the project code. The design is as follows:

asp.net development of WeChat public platform (1) database design

5. Custom menu, create and manage the custom menu in the WeChat public platform, the design is as follows:

asp.net development of WeChat public platform (1) database design

6. Others are designed based on the actual projects, such as user analysis, access statistics; user points; QR code related, etc., which will not be designed here.

Some of the above designs are not designed into the database, such as the reply message type in the keyword module and the message type in the message record. These are a small number of single options that are fixed (determined by Tencent). For data in the form, we use other methods to implement it in specific projects (fixed static, configuration files, cache, etc.) without designing a database.

The complete design is as follows: (To facilitate screenshots, I dragged the tables of each module to cover them)

asp.net development of WeChat public platform (1) database design

Download the script as follows: Create in the database A database named WeChat (defined by myself when designing the database), the script will be OK once executed,

use  weixin -------微信公众平台
if exists ( select *  from  sysobjects where name = 'tb_User' and xtype='U') 
drop table tb_User
create table  tb_User------------------------------------------------------------用户表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  InId             int              default  0                      NOT NULL , --自有系统的用户ID
  OpenId           varchar(150)     default ''                      NOT NULL , --微信openid
  Group            int              default  0                      NOT NULL , --分组ID
  NickName         varchar(50)      default ''                      NOT NULL , --昵称-微信
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  State            int              default  1                      NOT NULL , --状态-1为正常
  PreFirst         varchar(150)     default ''                      NOT NULL , --预留字段1
);


if exists ( select *  from  sysobjects where name = 'tb_Group' and xtype='U') 
drop table tb_Group
create table  tb_Group-----------------------------------------------------------分组表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  Name             varchar(50)      default ''                      NOT NULL , --名称-本地
  WeiId            int              default  0                      NOT NULL , --对应微信分组ID
  WeiName          varchar(50)      default ''                      NOT NULL , --微信分组名
  Note             varchar(100)     default ''                      NOT NULL , --备注
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  State            int              default  1                      NOT NULL , --状态
);


if exists ( select *  from  sysobjects where name = 'tb_UserData' and xtype='U') 
drop table tb_UserData
create table  tb_UserData--------------------------------------------------------用户资料表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  UserId           int              default  0                      NOT NULL , --用户表主键
  Sex              int              default  0                      NOT NULL , --性别0未知1男2女
  City             varchar(20)      default ''                      NOT NULL , --城市
  Country          varchar(30)      default ''                      NOT NULL , --国家
  Province         varchar(20)      default ''                      NOT NULL , --省份
  Language         varchar(15)      default ''                      NOT NULL , --语言
  HeadImgUrl       varchar(250)     default ''                      NOT NULL , --用户头像
  SubTime          varchar(50)      default ''                      NOT NULL , --最后次关注时间戳
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  State            int              default  1                      NOT NULL , --状态
  PreFirst         varchar(150)     default ''                      NOT NULL , --预留1
);


if exists ( select *  from  sysobjects where name = 'tb_Article' and xtype='U') 
drop table tb_Article
create table  tb_Article---------------------------------------------------------文章表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  SortId           int              default  0                      NOT NULL , --类别ID
  ITop             int              default  0                      NOT NULL , --置顶0不1是
  TopBeginTime     datetime         default  getdate()              NOT NULL , --置顶开始时间
  TopEndTime       datetime         default  getdate()              NOT NULL , --置顶结束时间
  Title            varchar(100)     default ''                      NOT NULL , --标题
  KeyWorld         varchar(150)     default ''                      NOT NULL , --关键字
  Summary          varchar(680)     default ''                      NOT NULL , --简介//680为微信文字上限左右
  Content          ntext            default ''                      NOT NULL , --内容
  Source           varchar(50)      default  '独家原创'                 NOT NULL , --来源
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  PublishTime      datetime         default  getdate()              NOT NULL , --发布时间
  AOrder           int              default  99                     NOT NULL , --排序
  State            int              default  1                      NOT NULL , --状态
  MinImg           varchar(350)     default ''                      NOT NULL , --缩略图
);


if exists ( select *  from  sysobjects where name = 'tb_ArtSort' and xtype='U') 
drop table tb_ArtSort
create table  tb_ArtSort---------------------------------------------------------文章分类表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  Name             varchar(50)      default ''                      NOT NULL , --名称
  ParentId         int              default  0                      NOT NULL , --父级ID
  IndexLevel       int              default  1                      NOT NULL , --当前级别
  SOrder           int              default  99                     NOT NULL , --排序
  State            int              default  1                      NOT NULL , --状态
  Note             varchar(150)     default ''                      NOT NULL , --备注
);


if exists ( select *  from  sysobjects where name = 'tb_KeyWord' and xtype='U') 
drop table tb_KeyWord
create table  tb_KeyWord---------------------------------------------------------关键字表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  Name             varchar(50)      default ''                      NOT NULL , --名称
  Note             varchar(250)     default ''                      NOT NULL , --备注
  State            int              default  1                      NOT NULL , --状态
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  ReType           int              default  1                      NOT NULL , --回复消息类型1为文本
);


if exists ( select *  from  sysobjects where name = 'tb_KeyContent' and xtype='U') 
drop table tb_KeyContent
create table  tb_KeyContent------------------------------------------------------关键字返回内容表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  Title            varchar(150)     default ''                      NOT NULL , --标题
  Content          varchar(700)     default ''                      NOT NULL , --内容
  KeyId            int              default  0                      NOT NULL , --关键字ID
  Type             int              default  1                      NOT NULL , --类型-文本图文等
  MinImg           varchar(250)     default ''                      NOT NULL , --图片
  ITop             int              default  0                      NOT NULL , --置顶
  TopBeginTime     datetime         default  getdate()              NOT NULL , --置顶开始时间
  TopEndTime       datetime         default  getdate()              NOT NULL , --置顶结束时间
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  State            int              default  1                      NOT NULL , --状态
  Href             varchar(250)     default  '#'                    NOT NULL , --图文时点开的链接
);


if exists ( select *  from  sysobjects where name = 'tb_UserMsg' and xtype='U') 
drop table tb_UserMsg
create table  tb_UserMsg---------------------------------------------------------用户消息记录表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  MsgType          int              default  1                      NOT NULL , --消息类型文本、事件
  EventId          int              default  1                      NOT NULL , --事件ID//自定义菜单的ID
  Content          varchar(700)     default ''                      NOT NULL , --消息内容
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  State            int              default  1                      NOT NULL , --状态
  ReState          int              default  0                      NOT NULL , --回复状态
  WeiMsgId         varchar(50)      default ''                      NOT NULL , --微信消息ID
  UserId           int              default  0                      NOT NULL , --用户表主键
);


if exists ( select *  from  sysobjects where name = 'tb_245' and xtype='U') 
drop table tb_245
create table  tb_245-------------------------------------------------------------回复消息表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  UserId           int              default  0                      NOT NULL , --用户表主键
  MsgID            int              default  0                      NOT NULL , --消息表主键
  ReType           int              default  1                      NOT NULL , --回复类型//文本图文
  ReFrom           int              default  1                      NOT NULL , --回复点//1文章2关键词
  ReContentId      varchar(80)      default  '0,'                   NOT NULL , --回复的内容ID串
  CreateTime       datetime         default  getdate()              NOT NULL , --回复记录时间
);


if exists ( select *  from  sysobjects where name = 'tb_PersonalMenu' and xtype='U') 
drop table tb_PersonalMenu
create table  tb_PersonalMenu----------------------------------------------------自定义菜单表
(
  ID               int              primary key identity(1,1)       NOT NULL , --主键-主键
  Name             varchar(50)      default ''                      NOT NULL , --名称
  Type             int              default  1                      NOT NULL , --类型1click2view
  ParentId         int              default  0                      NOT NULL , --父级ID
  IndexLevel       int              default  1                      NOT NULL , --当前级别
  LinkUrl          varchar(350)     default  '#'                    NOT NULL , --链接地址view时用
  CreateTime       datetime         default  getdate()              NOT NULL , --创建时间
  POrder           int              default  99                     NOT NULL , --排序
  State            int              default  1                      NOT NULL , --状态
  Note             varchar(150)     default ''                      NOT NULL , --备注
);

For more asp.net development of WeChat public platform (1) database design related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn