开发微信公众平台之前,先去微信官方了解下大概的情况 这里:http://mp.weixin.qq.com/wiki/index.php ;看了之后心里大致有数了,开始设计数据库,尽可能的考虑,未考虑到的,以后再补充。
1、首先是用户部分,根据微信官方的接口结合实际运用,用户部分有3个表:用户表、用户资料表、用户分组表,我设计的如下:
2、用户设计好之后就是文章部分,包括:文章分类表、文章表, 设计如下:
3、有了用户相关的表我们可以保存用户,有了文章模块的表我们可以根据用户输入的信息查询文章进行返回(返回文本、图文、图片、音乐、视频、语音等等),但是实际运用中,我们存在需要指定特定的关键字返回特定的内容的情况,那么就需要专门的特定关键字模块, 包括:关键字表、关键字返回的内容表, 这里的内容表看着像是与上面的文章表有重合,实则不然, 这里是特定关键字指定的回复内容,可以指定返回文本、图文或其他多媒体信息,当返回多媒体信息时内容中存入文件地址, 上面的文章表是标准的通用的文章内容表, 供用户查询多数情况下直接返回图文信息,且图文信息点击链接时就是这篇文章对应的展示地址, 相当于一个微网站, 所以文章和这个关键字的内容表分开设计更加方便管理。 设计如下:
4、消息记录, 把用户发来的消息进行记录,方便后续处理, 比如 根据用户上次发来的事件消息,之后再发同一个关键词时,返回对应菜单下的内容,而不用用户每次发送消息都带对应的菜单选项;客服消息根据记录的信息做个性化的服务 等等。 包括:用户发来的消息记录表、回复给用户的消息记录表 ,有了这些可以完整的还原和用户的对话,这里是记录和用户交流的过程,具体用户发来的消息需要返回什么样的消息,由项目代码中业务决定。 设计如下:
5、自定义菜单,创建和管理微信公众平台中的自定义菜单,设计如下:
6、其他, 具体根据做的实际项目来设计, 比如 用户分析、访问统计; 用户积分; 二维码相关 等等 , 此处先不设计。
以上设计中,有一些是没有设计到数据库的, 比如关键字模块中的回复消息类型、消息记录中的消息类型, 这些固定不变(由腾讯决定)的少量的单选项形式的数据,我们在具体项目中使用其他方法来实现(固定静态、配置文件、缓存等),无需设计数据库。
完整设计如下:(为了方便截图 ,我把各个模块的表拖动覆盖了)
下载脚本,如下:在数据库中创建一个名为微信(设计数据库时自己定义的)的数据库,脚本执行一下就ok,
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 , --备注
);
更多asp.net开发微信公众平台(1)数据库设计。