SpringBoot +春のセキュリティ+ thymeleaf + layui
プログラムのアイデアやリソース出典:
仕事を得るために何のマイクロチャネルインタフェース試験番号ありません
この目的は、書かれたプッシュメッセージのバウンドマイクロチャネル公衆番号への私の卒業プロジェクトのためです。プロジェクトの特徴は以下のとおりです。[テンプレートのメッセージのプッシュ]、[自動返信]、[マイクロ]レターユーザー詳細の三つの機能が、誰にでも利用できる悪魔として使用することができ、初めての尊重が質問を喜ば提起している公共の数字の多くを得ます。
まず第一に、特定の方法を見て:
Mavenは依存しています
<properties>
<weixin-java-mp.version>3.6.0</weixin-java-mp.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<swagger.version>2.7.0</swagger.version>
<mysql-connector.version>5.1.46</mysql-connector.version>
<druid.version>1.1.12</druid.version>
<mp-starter.version>3.1.0</mp-starter.version>
<mybatis-starter.version>2.0.1</mybatis-starter.version>
<pagehelper.version>5.1.2</pagehelper.version>
<pagehelper-auto.version>1.2.3</pagehelper-auto.version>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.locales>zh_CN</project.build.locales>
<docker.image.prefix>wechat-mp-demo</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>${weixin-java-mp.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- Testing Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>${pagehelper-auto.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-starter.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mp-starter.version}</version>
</dependency>
<dependency>
<groupId>com.bscommon</groupId>
<artifactId>bscommon-base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
インターネットインターフェイスコンフィギュレーションを介して転送WX
注:言葉はセキュリティが認証要求をインターセプトします値しないので、DOは、インポート認証セキュリティを書き込みません
最初のマイクロチャネルプラットフォームログイン、あなたが見ることができAPPIDとappsecret、証明書パスのURLを同じトークンおよびコンフィギュレーションファイルを設定するには、インターフェイスコンフィギュレーション情報を
YMLの構成は、(aesKeyは、それが公式公開番号を必要とすることはできません)で示されています。
次いで、直接(デモに変更する項目で、である)、WX-デモ認証とすることができる構成インターフェース上で参照インターフェイス詳細かつ
書き込み後のインタフェースプログラム、その後マイクロチャネル内のURLプラットフォームトークンを埋める、URLとして[ip]/wx/portal/[appid]
、[]、代替の配列であります
ローカルテストの言葉で認証ポート80または443が、なおnatApp浸透してネットワーク内で行うことができ、使用することができる空きチャネルがあります。
構成された身体検査、[OK]をトップのヒントの成功をクリックしてください。
セキュリティの設定
卒業認定の理由は、カスタムの暗号化(MD5)、および数ヤードbcryptのセキュリティデフォルトを要求すべきです。次のようにセッション要求はログインページにジャンプしていない期限切れの投稿を解決するために存在layui、必要性は、プロセッサの成功/失敗をカスタマイズするには:
/**
* 配置文件
**/
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final String KEY = "yljun.com";
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private LoginValidateAuthenticationProvider loginValidateAuthenticationProvider;
@Autowired
private CustomAuthenticationFailure customAuthenticationFailure; //自定义认证失败处理
@Autowired
private CustomAuthenticationSuccess customAuthenticationSuccess; //自定义认证认证处理
@Bean
public PasswordEncoder passwordEncoder() {
// return new BCryptPasswordEncoder(); // 使用 BCrypt 加密
return new CustomPasswordEncoder(); //自定义加密
}
/**
* 自定义配置 wx/** 不拦截微信平台认证
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("wx/**","error/**", "lib/**","js/**", "api/**", "images/**", "css/**").permitAll() // 都可以访问
.antMatchers("/h2-console/**").permitAll() // 都可以访问
.antMatchers("/wxm/**").hasRole("1") // 需要相应的角色才能访问
.antMatchers("/index", "/", "/welcome").hasRole("1")
.and()
.formLogin().failureHandler(customAuthenticationFailure).successHandler(customAuthenticationSuccess) //基于 Form 表单登录验证
.loginPage("/login") // 自定义登录界面
.and().rememberMe().key(KEY); // 启用 remember me
// .and().exceptionHandling().accessDeniedPage("/403"); // 处理异常,拒绝访问就重定向到 403 页面
http.csrf().disable(); //关闭跨域保护
http.headers().frameOptions().sameOrigin(); // 允许来自同一来源的H2 控制台的请求
}
/**
* 认证信息管理
* @param auth
* @throws Exception
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
auth.authenticationProvider(loginValidateAuthenticationProvider);
}
}
特定の機能
具体的な機能は、基本的には、MyBatisの-ぬいぐるみとWX-Javaツールキットが言うここに提供しています。。。。
私はデモに直接リンク。。。私はZageがより腐った書き込みを説明知りません。。。