LoginController.class.php 8.9 KB

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