如现在实现这样的功能,公众号下面有一个按钮,'点我绑定'。绑定页面显示当前用户的openId和微信昵称,并检测当前微信用户有没有绑定,没有则显示绑定form,如果已经绑定则提示已经绑定的userId,同时展示解绑按钮。为简单起见,这里前端部署和后端部署放在一块,没有做前后端分离部署。
一、准备工作:
1、开启natapp映射,
2、后面需要根据authcode获取openId,所以需要开启认证:在微信公众号后台
微信公众平台找到权限
如我:
授权回调域名配置规范为全域名并且不带http,这样我就可以访问该域名下的所有页面。
3、数据库
微信-绑定账号记录表:
这个表记录用户的绑定操作,在绑定页面, 将openId与用户输入的userId记录。解绑则删除该条记录。
二、后台:
application.properties:
server.port = 8080
app.id =xxx
app.secret = xxxxxx
server.context-path=/wechat
#时间格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#时区设置
spring.jackson.time-zone=Asia/Chongqing
#以下为mybatis相关配置
#springboot默认读取spring.datasource.xxx属性,初始化DataSource并自动注入sqlSessionFactory
#spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/wechat?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=wtyy
#mybatis.mapper-locaitons=classpath:mapper/*.xml
mybatis.mapper-locations=classpath*:mapper/*Ma