Skip to content

handsomestWei/ruoyi-vue-wxmini

Repository files navigation

若依框架整合微信小程序

依赖

整合功能

  • 微信小程序登录。
  • 微信用户信息同步。
  • 微信小程序支付。

整体设计

  • 新增微信小程序用户体系:新增用户表,区别于若依原有的管理后台用户角色权限体系,单独用于保存微信小程序用户。小程序用户仅操作微信小程序,不登录若依后台。
  • 新增微信小程序后端接口鉴权体系:新增过滤器,单独用于拦截微信小程序后端模块接口做鉴权。
  • 新增微信小程序后端模块

整合改动说明

项目模块改动

在根项目,新增了ruoyi-wxminimodule模块。在根pom.xml文件内:

  • <modules>标签内,会自动将新增模块纳入管理。增加内容如下。
    <modules>
        <module>ruoyi-wxmini</module>
    </modules>
  • <dependencies>标签内,手动添加新增的模块。增加内容如下。
    <dependency>
        <groupId>com.ruoyi</groupId>
        <artifactId>ruoyi-wxmini</artifactId>
        <version>${ruoyi.version}</version>
    </dependency>

ruoyi-admin模块改动

ruoyi-admin模块的pom.xml中,<dependencies>依赖中手动增加了ruoyi-wxmini模块依赖,使得ruoyi-wxmini 模块中的controller控制器被加载和url生效。增加内容如下。

<dependency>
    <groupId>com.ruoyi</groupId>
    <artifactId>ruoyi-wxmini</artifactId>
</dependency>

ruoyi-framework模块改动

修改了过滤器配置,修改com.ruoyi.framework.config.SecurityConfig对象的filterChain 方法,追加匹配规则,对自定义的微信小程序接口url不做登录等鉴权。该部分接口鉴权将交由ruoyi-wxmini模块定义的过滤器处理。增加内容如下。

.antMatchers("/wxmini/**").permitAll()

ruoyi-system模块改动

使用了若依自带的代码生成工具,自动生成业务层代码,并放置在ruoyi-system模块中,对应com.ruoyi.wxmini包。

数据库改动

新增微信用户表,执行sql\wx_user.sql建表。

项目配置文件改动

ruoyi-admin模块里的application.yml配置文件,增加了微信对接配置,示例如下。

wx:
  miniapp:
    configs:
      - appid: test #微信小程序的appid
        secret: test #微信小程序的Secret
        token: #微信小程序消息服务器配置的token
        aesKey: #微信小程序消息服务器配置的EncodingAESKey
        msgDataFormat: JSON
  # 支付配置
  pay:
    appId: test #微信小程序的appid
    mchId: 110 #商户id
    apiV3Key: test #V3密钥
    # https://pay.weixin.qq.com/doc/v3/merchant/4012365345
    # openssl x509 -in apiclient_cert.pem -noout -serial
    certSerialNo: test
    privateKeyPath: classpath:cert/apiclient_key.pem #apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径
    privateCertPath: classpath:cert/apiclient_cert.pem #apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径

ruoyi-admin模块的resources资源文件目录下,增加cert目录,放置支付用的证书。

ruoyi-wxmini模块设计说明

TODO

参考

About

若依框架整合微信小程序登录和支付

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published