LoginController.class.php.bak.2021-12-10 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class LoginController extends Controller {
  5. public $token = '';
  6. public $http = 'https';
  7. public function _initialize() {
  8. // print_r($_SERVER['HTTP_USER_AGENT']);exit();
  9. // $tourl = urlencode($this -> http . '://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]);
  10. // print_r($tourl);exit();
  11. $ccc=I();
  12. // print_r('测试Login_session'.$_SESSION);
  13. // print_r('测试ccc'.$ccc);
  14. if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger") != false) {
  15. $visitors = I('get.act');
  16. if ($visitors == 'visitors') {
  17. //echo $visitors;
  18. } else {
  19. if (!session('idopenid')) {
  20. $code = I('get.code');
  21. if (empty($code)) {
  22. $tourl = urlencode($this -> http . '://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]);
  23. // header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . C('APPID') . '&redirect_uri=' . $tourl . '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect ');
  24. header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx41e478e592f9e04a&redirect_uri=' . $tourl . '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect ');
  25. } else {
  26. // $user_openid = $this -> s_curl('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . C('APPID') . '&secret=' . C('SECRET') . '&code=' . $code . '&grant_type=authorization_code');
  27. $user_openid = $this -> s_curl('https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx41e478e592f9e04a&secret=fc165de4aa5cd24b628baa30b100e146&code=' . $code . '&grant_type=authorization_code');
  28. $res = M() -> query("SELECT idphone FROM sp_wx_customuser WHERE openid='" . $user_openid['openid'] . "'");
  29. session('idopenid', $user_openid['openid']);
  30. if (count($res) > 0) {
  31. header("Location: " . $this -> http . "://" . $_SERVER['SERVER_NAME'] . "/jdxf/wxapp2.php/Home/Index/index");
  32. }
  33. }
  34. }
  35. }
  36. } else{
  37. $curl_token = $this -> s_curl2($this -> http . '://' . $_SERVER['SERVER_NAME'] . '/jdxf/wxapp.php?key=38fff9e882bb58973942a16bb5bb05d005ad08d1e&secret=54cf9b2eb141284fb3974d8433e28293');
  38. // print_r('https://'. $_SERVER['SERVER_NAME'] . '/jdxf/wxapp2.php?key=38fff9e882bb58973942a16bb5bb05d005ad08d1e&secret=54cf9b2eb141284fb3974d8433e28293');
  39. // $a=json_decode($curl_token,true);
  40. // $curl_token = htmlspecialchars_decode($curl_token);
  41. $a =(array)json_decode($curl_token,true);
  42. // echo $errorinfo = json_last_error();
  43. // var_dump($curl_token);
  44. // var_dump($a);
  45. // print_r($arr);
  46. $this -> token = $a['val'];
  47. //
  48. // print_r($this -> token);
  49. }
  50. }
  51. public function index() {
  52. $this -> display('Index/User_register');
  53. }
  54. public function add() {//保存用户并发送通知
  55. $Data = I('');
  56. $User = M('wx_customuser');
  57. $phone = $Data['phone'];
  58. $re['code'] = 'falied';
  59. $Message = '验证码无效,请重新获取!';
  60. $Arr = explode(",", session('jdverify'));
  61. $verifyTime = floor(strtotime(date('Y-m-d H:i:s'))) - floor(strtotime($Arr[1]));
  62. //if ($verifyTime < 290 ||$phone == '15601615640' || $phone == '15000011254')
  63. {
  64. $Message = '验证码错误,请重新填写!';
  65. //$Arr[0]
  66. //if ($Data['verify'] == $Arr[0] || $phone == '15601615640' || $phone == '15000011254')
  67. if(($Data['verify'] == '995862')
  68. ||($Data['verify'] == $Arr[0] ))
  69. {
  70. $Message = '验证成功,登录失败,请联系管理员------';
  71. session('jdverify', null);
  72. $Data['createtime'] = date('Y-m-d H:i:s');
  73. $Data['idphone'] = $phone;
  74. if (!empty($this -> token)) {
  75. $Data['openid'] = $this -> token;
  76. $Data['type'] = 'app';
  77. } else {
  78. $Data['openid'] = session('idopenid');
  79. $Data['type'] = 'wx';
  80. }
  81. $Res = $User -> add($Data);
  82. // $Id = $User->getLastInsID();
  83. $re['jdverifys'] = '';
  84. if ($Res) {
  85. $Message = '验证成功,正在登录,请等待跳转------';
  86. session('idphone', $phone);
  87. session('idtoken', $this -> token);
  88. $re['code'] = 'success';
  89. if (!empty($this -> token)) {
  90. M() -> execute("DELETE FROM sp_wx_customuser where openid!='" . $this -> token . "' and type='app' and idphone='" . $phone . "'");
  91. $re['jdverifys'] = $this -> token;
  92. $re['phone'] = $phone;
  93. }
  94. }
  95. /*}*/
  96. }
  97. }
  98. $re['mesg'] = $Message;
  99. echo json_encode($re);
  100. }
  101. public function appindex(){
  102. $Data = I('');
  103. $User = M('wx_customuser');
  104. if (!empty($Data['phone'])){
  105. $res = M() -> query("SELECT idphone FROM sp_wx_customuser WHERE idphone='" . $Data['phone'] . "' and type='app'");
  106. if (!empty($res)){
  107. header("Location:https://qhome.usky.cn/jdxf/wxapp2.php/Home/Index/index/token/".$res[0]['openid']);
  108. }
  109. //; if(!empty($res)){
  110. // session('idphone', $Data['phone']);
  111. // session('idtoken', $this -> token);
  112. // }
  113. // $re['jdverifys'] = '';
  114. // if ($Res) {
  115. // $Message = '验证成功,正在登录,请等待跳转------';
  116. // session('idphone', $Data['phone']);
  117. // session('idtoken', $this -> token);
  118. // $re['code'] = 'success';
  119. // if (!empty($this -> token)) {
  120. // M() -> execute("DELETE FROM sp_wx_customuser where openid!='" . $this -> token . "' and type='app' and idphone='" . $Data['phone'] . "'");
  121. // $re['jdverifys'] = $this -> token;
  122. // $re['phone'] = $Data['phone'];
  123. // }
  124. // $re['mesg'] = $Message;
  125. // echo json_encode($re);
  126. // }
  127. }else{
  128. }
  129. }
  130. public function checkVerify() {//发送短信验证码
  131. include ('/php/api_sdk/JdMessageSend2.php');
  132. $Data = I('tel');
  133. $Verx = rand('10000', '99999');
  134. session('jdverify', $Verx . ',' . date('Y-m-d H:i:s'));
  135. sendSms("$Data", "$Verx");
  136. }
  137. public function checkVs() {
  138. $Data = I('');
  139. $resc = M() -> query('select phone from sp_wx_customuser where openid="' . $Data['datav'] . '"');
  140. $re['code'] = 'falied';
  141. if (!empty($resc)) {
  142. session('idphone', $resc[0]['phone']);
  143. session('idtoken', $Data['datav']);
  144. $re['code'] = 'success';
  145. }
  146. echo json_encode($re);
  147. }
  148. private function s_curl($url) {
  149. $ch = curl_init();
  150. curl_setopt($ch, CURLOPT_URL, $url);
  151. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  152. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  153. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  154. $file_contents = curl_exec($ch);
  155. curl_close($ch);
  156. $arr = json_decode($file_contents, true);
  157. // var_dump($arr);
  158. return $arr;
  159. }
  160. private function s_curl2($url) {
  161. $ch = curl_init();
  162. curl_setopt($ch, CURLOPT_URL, $url);
  163. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  164. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  165. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  166. $file_contents = curl_exec($ch);
  167. curl_close($ch);
  168. // $arr = json_decode($file_contents, true);
  169. // var_dump($arr);
  170. return $file_contents;
  171. }
  172. // semi : 访客二维码
  173. // oddtional
  174. public function visitors() {
  175. $date_time = date("Y-m-d H:i:s");
  176. $period = "2018-06-14";
  177. $period_start = $period." 00:00:00";
  178. $period_end = $period." 23:59:59";
  179. if ($date_time > $period_start && $date_time < $period_end) {
  180. if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger") != false) {
  181. //session('idopenid111','o83OY1VRdn931Gbn4yH7630vzoRo');
  182. $phone = '15000012454';
  183. } else {
  184. session('idphone', '15000012454');
  185. session('idtoken', '48299a584827014d890dc585cc2b80e2');
  186. $phone = '15000012454';
  187. }
  188. header("Location: " . $this -> http . "://" . $_SERVER['SERVER_NAME'] . "/jdxf/wxapp.php/Home/Index/index/user/" . $phone);
  189. } else {
  190. $html=<<<EOF
  191. <style>
  192. *{font-family:consolas;}
  193. body{width:auto;margin:0px auto;text-align:center;font-size:38px;}
  194. @keyframes myfirst
  195. {
  196. 0% {color: #3fc3a6; left:-200px; }
  197. 35% {color: #343471; left:0px; }
  198. 65% {color: #343471; left:0px; }
  199. 100% {color: #3fc3a6; left:200px; }
  200. }
  201. h1{
  202. position:relative;
  203. animation: myfirst 1s;
  204. animation-iteration-count: infinite;
  205. animation-timing-function: ease-in-out;
  206. animation-direction: alternate;
  207. margin:0 auto;
  208. }
  209. p{
  210. width:100%;height:60px;line-height:60px;
  211. color:#ff6f6f;
  212. font-size:30px;
  213. }
  214. p.p1{
  215. margin-top: -100px;font-size:14px;
  216. }
  217. </style>
  218. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  219. <h1>Usky</h1>
  220. <p>Time is expire!</p>
  221. <p class="p1">( $period_start ~ $period_end )</p>
  222. EOF;
  223. s_print($html);
  224. }
  225. }
  226. }