thirdlogin.blade.php 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. @if(config('aix.system.oauth.wechat_open.is_open') == 1)
  2. @if(config('aix.system.oauth.wechat_open.is_use_official_login') == 0)
  3. @php
  4. if (isset($redirect_url)) {
  5. session(['redirect_url'=>$redirect_url]);
  6. }
  7. session(['wechat_state'=>time(), 'subsite_id'=>get_subsite_id(), "is_bind"=>0, 'type'=>'web']);
  8. @endphp
  9. <script type="text/javascript" src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
  10. <script>
  11. $(function () {
  12. var timer= setInterval(function () {
  13. if(WxLogin){
  14. wechatLogin();
  15. clearInterval(timer);
  16. }
  17. },200)
  18. function wechatLogin() {
  19. //初始化微信登录
  20. var obj = new WxLogin({
  21. id:"thirdlogin-wechat-web",
  22. appid: "{{config('aix.system.oauth.wechat_open.app_id')}}",
  23. scope: "snsapi_login",
  24. redirect_uri: "{{urlencode(config('app.url').route('auth.thirdlogin', ['login_type'=>'wechat'], false))}}",
  25. state: "{{session('wechat_state')}}",
  26. href:"data:text/css;base64,LmltcG93ZXJCb3ggLnRpdGxlewogICBjb2xvcjogIzRkNGQ0ZDsKICAgZm9udC1zaXplOiAxNnB4OwogICBsaW5lLWhlaWdodDogNDRweDsKfQouaW1wb3dlckJveCAucXJjb2RlIHsKICAgIHdpZHRoOiAxNDBweDsKICAgIGhlaWdodDoxNDBweDsKfQouaW1wb3dlckJveCAuc3RhdHVzewogICAgcGFkZGluZzogNXB4IDE0cHg7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjRUVFRUVFOwogICAgYm9yZGVyLXJhZGl1czogNTBweDsKICAgIGNvbG9yOiAjOTk5OTk5OwogICAgZm9udC1zaXplOiAxM3B4Owp9Ci5pbXBvd2VyQm94IC5zdGF0dXMuc3RhdHVzX2Jyb3dzZXIgewogICAgIGRpc3BsYXk6IG5vbmU7Cn0="
  27. });
  28. }
  29. });
  30. </script>
  31. @endif
  32. @if(config('aix.system.oauth.wechat_open.is_use_official_login') == 1)
  33. @php
  34. try{
  35. $jump_url=isset($redirect_url)?$redirect_url:get_subsite_domain(get_subsite_id());
  36. $wechatService=app('App\Services\Common\WechatService');
  37. $officil=$wechatService->getOfficialAccount();
  38. $qrcode=$officil->qrcode->temporary('LoginEvent', 30*60);
  39. $qrcode_url=$officil->qrcode->url($qrcode['ticket']);
  40. }catch(Exception $e){
  41. $qrcode_url = "请在公众内添加ip白名单";
  42. $qrcode['ticket']="please set ip in the official";
  43. $jump_url='/';
  44. }
  45. @endphp
  46. <script>
  47. $(function () {
  48. //初始化微信登录
  49. var official_qrcode='<div class="wtitle">微信登录</div><img src="{!! $qrcode_url !!}">';
  50. $('#thirdlogin-wechat-web').append(official_qrcode);
  51. setInterval(function () {
  52. $.ajax({
  53. method: 'get',
  54. url: "{{route('auth.thirdlogin.checklogin', ['ticket'=>$qrcode['ticket']])}}",
  55. success: function (data) {
  56. //console.log(data);
  57. if (data.data.is_login == 1) {
  58. location.href="{{$jump_url}}";
  59. }
  60. }
  61. });
  62. }, 1000);
  63. });
  64. </script>
  65. @endif
  66. @endif
  67. @if(config('aix.system.oauth.qq.is_open_qq') == 1)
  68. <script>
  69. @php
  70. if (isset($redirect_url)) {
  71. session(['redirect_url'=>$redirect_url]);
  72. }
  73. $redirect_uri=urlencode(config('app.url').route('auth.thirdlogin', ['login_type'=>'qq'], false));
  74. session(['qq_state'=>time(), 'subsite_id'=>get_subsite_id(), 'qq_redirect_uri'=>$redirect_uri, "is_bind"=>0, 'type'=>'web']);
  75. $url="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=".config('aix.system.oauth.qq.app_id')."&redirect_uri=".$redirect_uri."&state=".session('qq_state');
  76. @endphp
  77. $(function () {
  78. var qq_link='<a class="app-icon qq" href="{!! $url !!}"></a>';
  79. $('#other-thirdlogin').append(qq_link);
  80. });
  81. function qq_login()
  82. {
  83. //以下为按钮点击事件的逻辑。注意这里要重新打开窗口
  84. //否则后面跳转到QQ登录,授权页面时会直接缩小当前浏览器的窗口,而不是打开新窗口
  85. var A=window.open("{!! $url !!}","TencentLogin", "width=450,height=320,menubar=0,scrollbars=1,resizable=1,status=1,titlebar=0,toolbar=0,location=1");
  86. }
  87. </script>
  88. @endif