最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot實(shí)現(xiàn)微信及QQ綁定登錄的示例代碼

 更新時(shí)間:2023年07月03日 09:55:37   作者:orton777  
本文主要介紹了SpringBoot實(shí)現(xiàn)微信及QQ綁定登錄的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本文將介紹如何使用 Spring Boot 實(shí)現(xiàn)微信和 QQ 的綁定登錄功能。我們將通過簡單的步驟和代碼示例來說明如何實(shí)現(xiàn)這兩種社交平臺(tái)的登錄集成。

準(zhǔn)備工作

在開始之前,確保你已經(jīng)完成以下準(zhǔn)備工作:

  • 注冊(cè)微信開放平臺(tái)和 QQ 開放平臺(tái),獲取相應(yīng)的 AppID 和 AppSecret。
  • 為你的應(yīng)用配置回調(diào) URL,并確保該 URL 能夠被外部訪問。
  • 安裝 Spring Boot 及其相關(guān)依賴。

實(shí)現(xiàn)微信登錄

1. 添加依賴

在 pom.xml 文件中添加以下依賴:

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-core</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-config</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-security</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-weixin</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

2. 配置微信登錄

在 application.properties 文件中添加以下配置:

spring.social.weixin.app-id=你的微信AppID
spring.social.weixin.app-secret=你的微信AppSecret

在 WebSecurityConfig 類中添加以下代碼:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
? ? @Autowired
? ? private WeixinConnectionFactory weixinConnectionFactory;
? ? @Override
? ? protected void configure(HttpSecurity http) throws Exception {
? ? ? ? http
? ? ? ? ? ? .apply(springSocialConfigurer())
? ? ? ? ? ? .and()
? ? ? ? ? ? // 其他配置
? ? ? ? ;
? ? }
? ? @Bean
? ? public SpringSocialConfigurer springSocialConfigurer() {
? ? ? ? SpringSocialConfigurer configurer = new SpringSocialConfigurer();
? ? ? ? configurer.signupUrl("/signup");
? ? ? ? return configurer;
? ? }
? ? @Bean
? ? public ConnectionFactoryLocator connectionFactoryLocator() {
? ? ? ? ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
? ? ? ? registry.addConnectionFactory(weixinConnectionFactory);
? ? ? ? return registry;
? ? }
? ? @Bean
? ? public UsersConnectionRepository usersConnectionRepository() {
? ? ? ? return new InMemoryUsersConnectionRepository(connectionFactoryLocator());
? ? }
? ? @Bean
? ? public WeixinConnectionFactory weixinConnectionFactory() {
? ? ? ? return new WeixinConnectionFactory(
? ? ? ? ? ? environment.getProperty("spring.social.weixin.app-id"),
? ? ? ? ? ? environment.getProperty("spring.social.weixin.app-secret"));
? ? }
}

3. 實(shí)現(xiàn)綁定登錄

在 WeixinController 類中添加以下代碼:

@RestController
@RequestMapping("/weixin")
public class WeixinController {
? ? @Autowired
? ? private ConnectionFactoryLocator connectionFactoryLocator;
? ? @Autowired
? ? private UsersConnectionRepository usersConnectionRepository;
? ? @GetMapping("/signin")
? ? public String signin(HttpServletRequest request) {
? ? ? ? Connection<Weixin> connection = new OAuth2ConnectionFactory<Weixin>(
? ? ? ? ? ? (WeixinConnectionFactory) connectionFactoryLocator.getConnectionFactory(Weixin.class))
? ? ? ? ? ? .createConnection(new AccessGrant(request.getParameter("code")));
? ? ? ? // 綁定登錄邏輯
? ? ? ? // ...?
? ? ? ? return "綁定成功";
? ? }
}

實(shí)現(xiàn) QQ 登錄

1. 添加依賴

在 pom.xml 文件中添加以下依賴:

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-qq</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

2. 配置 QQ 登錄

在 application.properties 文件中添加以下配置:

spring.social.qq.app-id=你的QQAppID
spring.social.qq.app-secret=你的QQAppSecret

在 WebSecurityConfig 類中添加以下代碼:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
? ? @Autowired
? ? private QQConnectionFactory qqConnectionFactory;
? ? @Override
? ? protected void configure(HttpSecurity http) throws Exception {
? ? ? ? http
? ? ? ? ? ? .apply(springSocialConfigurer())
? ? ? ? ? ? .and()
? ? ? ? ? ? // ? ? ? ? ? ?// 其他配置
? ? ? ? ;
? ? }
? ? @Bean
? ? public SpringSocialConfigurer springSocialConfigurer() {
? ? ? ? SpringSocialConfigurer configurer = new SpringSocialConfigurer();
? ? ? ? configurer.signupUrl("/signup");
? ? ? ? return configurer;
? ? }
? ? @Bean
? ? public ConnectionFactoryLocator connectionFactoryLocator() {
? ? ? ? ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
? ? ? ? registry.addConnectionFactory(qqConnectionFactory);
? ? ? ? return registry;
? ? }
? ? @Bean
? ? public UsersConnectionRepository usersConnectionRepository() {
? ? ? ? return new InMemoryUsersConnectionRepository(connectionFactoryLocator());
? ? }
? ? @Bean
? ? public QQConnectionFactory qqConnectionFactory() {
? ? ? ? return new QQConnectionFactory(
? ? ? ? ? ? environment.getProperty("spring.social.qq.app-id"),
? ? ? ? ? ? environment.getProperty("spring.social.qq.app-secret"));
? ? }
}

3. 實(shí)現(xiàn)綁定登錄

在 QQController 類中添加以下代碼:

@RestController
@RequestMapping("/qq")
public class QQController {
? ? @Autowired
? ? private ConnectionFactoryLocator connectionFactoryLocator;
? ? @Autowired
? ? private UsersConnectionRepository usersConnectionRepository;
? ? @GetMapping("/signin")
? ? public String signin(HttpServletRequest request) {
? ? ? ? Connection<QQ> connection = new OAuth2ConnectionFactory<QQ>(
? ? ? ? ? ? (QQConnectionFactory) connectionFactoryLocator.getConnectionFactory(QQ.class))
? ? ? ? ? ? .createConnection(new AccessGrant(request.getParameter("code")));
? ? ? ? // 綁定登錄邏輯
? ? ? ? // ...?
? ? ? ? return "綁定成功";
? ? }
}

總結(jié)

通過本文的介紹,我們已經(jīng)學(xué)會(huì)了如何使用 Spring Boot 實(shí)現(xiàn)微信和 QQ 的綁定登錄功能?,F(xiàn)在你可以將這兩種社交平臺(tái)的登錄集成到你的應(yīng)用中,為用戶提供更加便捷的登錄方式。當(dāng)然,以上代碼僅作為示例,你還需要根據(jù)實(shí)際需求進(jìn)行相應(yīng)的調(diào)整和優(yōu)化。

到此這篇關(guān)于SpringBoot實(shí)現(xiàn)微信及QQ綁定登錄的示例代碼的文章就介紹到這了,更多相關(guān)Spring Boot微信QQ綁定登錄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java BeanUtils工具類常用方法講解

    Java BeanUtils工具類常用方法講解

    這篇文章主要介紹了Java BeanUtils工具類常用方法講解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Spring?異步接口返回結(jié)果的四種方式

    Spring?異步接口返回結(jié)果的四種方式

    這篇文章主要介紹了Spring?異步接口返回結(jié)果的四種方式,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下
    2022-08-08
  • java排序高級(jí)之選擇排序?qū)崿F(xiàn)方法

    java排序高級(jí)之選擇排序?qū)崿F(xiàn)方法

    這篇文章主要介紹了java排序高級(jí)之選擇排序?qū)崿F(xiàn)方法,較為全面的分析了選擇排序的原理與具體實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-02-02
  • Spring Dao層@Repository與@Mapper的使用

    Spring Dao層@Repository與@Mapper的使用

    這篇文章主要介紹了Spring Dao層@Repository與@Mapper的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • java開發(fā)ExecutorService監(jiān)控實(shí)現(xiàn)示例詳解

    java開發(fā)ExecutorService監(jiān)控實(shí)現(xiàn)示例詳解

    這篇文章主要為大家介紹了java開發(fā)ExecutorService監(jiān)控實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • JAVA使用動(dòng)態(tài)代理對(duì)象進(jìn)行敏感字過濾代碼實(shí)例

    JAVA使用動(dòng)態(tài)代理對(duì)象進(jìn)行敏感字過濾代碼實(shí)例

    這篇文章主要介紹了JAVA使用動(dòng)態(tài)代理對(duì)象進(jìn)行敏感字過濾代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • SpringBoot讀取外部的配置文件的代碼實(shí)現(xiàn)

    SpringBoot讀取外部的配置文件的代碼實(shí)現(xiàn)

    這篇文章主要介紹了SpringBoot讀取外部的配置文件的代碼實(shí)現(xiàn),文中通過代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-11-11
  • springboot + swagger 實(shí)例代碼

    springboot + swagger 實(shí)例代碼

    本篇文章主要介紹了springboot + swagger 實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • Java包裝類原理與用法實(shí)例分析

    Java包裝類原理與用法實(shí)例分析

    這篇文章主要介紹了Java包裝類,結(jié)合實(shí)例形式分析了Java包裝類基本概念、功能、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下
    2020-04-04
  • Java jpa外連接查詢join案例詳解

    Java jpa外連接查詢join案例詳解

    這篇文章主要介紹了Java jpa外連接查詢join案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09

最新評(píng)論

雷州市| 贵州省| 惠州市| 玉林市| 社旗县| 孟连| 陇南市| 香港 | 长垣县| 抚远县| 漯河市| 丘北县| 宣化县| 宜川县| 松溪县| 莱阳市| 西安市| 全州县| 荆州市| 犍为县| 新建县| 松溪县| 通辽市| 博乐市| 新巴尔虎右旗| 房山区| 墨脱县| 开阳县| 新郑市| 长宁区| 扶风县| 兴山县| 耿马| 正蓝旗| 策勒县| 广灵县| 南投市| 七台河市| 大宁县| 湄潭县| 长岭县|