social-login.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
  6. <title>社交登陆测试页</title>
  7. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  8. </head>
  9. <body>
  10. <div>点击如下按钮,发起登陆的测试</div>
  11. <div>
  12. <button id="wx_pub">微信公众号</button>
  13. </div>
  14. </body>
  15. <script>
  16. let server = 'http://127.0.0.1:28080';
  17. // 微信公众号
  18. $( "#wx_pub").on( "click", function() {
  19. // 获得授权链接
  20. $.ajax({
  21. url: server + "/api/social-auth-redirect?type=31&redirectUri=" +
  22. encodeURIComponent(server + '/api/social-login-get'),
  23. method: 'GET',
  24. success: function( result ) {
  25. if (result.code !== 0) {
  26. alert('获得授权链接失败,原因:' + result.msg)
  27. return;
  28. }
  29. // 跳转重定向
  30. document.location.href = result.data;
  31. }
  32. })
  33. });
  34. </script>
  35. </html>