query("SELECT o.owner_code,c.owner_name FROM sp_owner o join sp_owner_company c ON o.company =c.owner_id WHERE o.company in(".$company.")"); $this->owner_name = $device[0]['owner_name']; $str = ""; foreach ($device as $val) { $str .= "'" . $val['owner_code'] . "',"; } $newstr = substr($str, 0, strlen($str) - 1); return $newstr; } public function getCompileUrl() { $Data = I(''); if (empty($Data['curl'])) { $R['flag'] = false; $R['msg'] = '缺少关键参数curl'; echo json_encode($R); exit(); } $curl = $Data['curl']; $tourl = urlencode($curl); $R['flag'] = true; $R['turl'] = $tourl; $R['msg'] = '当前路径编译成功'; echo json_encode($R); exit(); } public function getPageAuthorization() { if (!strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger") != false) { //跳转登录页 $R['msg'] = '页面授权未通过,跳转登录页面'; $R['flag'] = false; echo json_encode($R); exit(); } if (!isset($_SESSION['idopenid']) && empty($_SESSION['idopenid'])) { $Data = I(''); $code = $Data['code']; if (empty($code)) { $R['msg'] = '路径编译成功'; $R['flag'] = false; echo json_encode($R); exit(); } else { $user_openid = $this->s_curl('https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx41e478e592f9e04a&secret=fc165de4aa5cd24b628baa30b100e146&code=' . $code . '&grant_type=authorization_code'); $res = M()->query("SELECT phone FROM sp_wx_customuser WHERE openid='" . $user_openid['openid'] . "' and type='wx'"); if (count($res) > 0) { $_SESSION['idopenid'] = $user_openid['openid']; $_SESSION['openid'] = $user_openid['openid']; $this->iphone = $res[0]['phone']; $_GET['phone'] = $res[0]['phone']; $_SESSION['phone'] = $res[0]['phone']; $R['msg'] = '页面授权通过,用户权限通过'; $R['flag'] = true; echo json_encode($R); exit(); } else { unset($_SESSION['idopenid']); unset($_SESSION['phone']); $R['msg'] = '页面授权未通过,跳转登录页面'; $R['flag'] = false; echo json_encode($R); exit(); } } } else { $res = M()->query("SELECT phone FROM sp_wx_customuser WHERE openid='" . $_SESSION['idopenid'] . "' and type='wx'"); if (count($res) > 0) { $this->iphone = $res[0]['phone']; $_GET['phone'] = $res[0]['phone']; $_SESSION['phone'] = $res[0]['phone']; $R['msg'] = '页面授权通过,用户权限通过'; $R['flag'] = true; echo json_encode($R); exit(); } else { unset($_SESSION['idopenid']); unset($_SESSION['phone']); $R['msg'] = '页面授权未通过,跳转登录页面'; $R['flag'] = false; echo json_encode($R); exit(); } } } public function getPageAuthorization1() { $http = 'https://'; $code = I('get.code'); // print_r("SELECT phone,openid FROM sp_wx_customuser WHERE openid='" . $_SESSION['app_token'] . "' and type='app' and phone='".$_SESSION['phone']."'"); // exit(); if (isset($_SESSION['app_token'])&&isset($_SESSION['phone'])){ $res = M()->query("SELECT phone,openid FROM sp_wx_customuser WHERE type='app' and phone='".$_SESSION['phone']."'"); header('Location:https://qhome.usky.cn/work/#/?op='.$res[0]['openid']);//项目首页 }else{ if (!strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger") != false) { header('Location:https://qhome.usky.cn/work/index.html#/pages/login/login'); exit(); } if (!isset($_SESSION['idopenid']) && empty($_SESSION['idopenid'])) { if (empty($code)) { $tourl = urlencode($http . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]); 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 '); } else { $user_openid = $this->s_curl('https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx41e478e592f9e04a&secret=fc165de4aa5cd24b628baa30b100e146&code=' . $code . '&grant_type=authorization_code'); $res = M()->query("SELECT phone,openid FROM sp_wx_customuser WHERE openid='" . $user_openid['openid'] . "' and type='wx'"); if (count($res) > 0) { $_SESSION['idopenid'] = $user_openid['openid']; $_SESSION['openid'] = $user_openid['openid']; $this->iphone = $res[0]['phone']; $_GET['phone'] = $res[0]['phone']; $_SESSION['phone'] = $res[0]['phone']; // header('Location:https://iot.usky.cn/ceshi.html?op='.$res['openid']);//项目首页 header('Location:https://qhome.usky.cn/work/#/?op='.$res[0]['openid']);//项目首页 } else { unset($_SESSION['idopenid']); unset($_SESSION['phone']); // header('Location:https://iot.usky.cn/ceshi.html?');//登录页 header('Location:https://qhome.usky.cn/work/index.html#/pages/login/login'); } } } else { $res = M()->query("SELECT phone,openid FROM sp_wx_customuser WHERE openid='" . $_SESSION['idopenid'] . "' and type='wx'"); if (count($res) > 0) { $this->iphone = $res[0]['phone']; $_GET['phone'] = $res[0]['phone']; $_SESSION['phone'] = $res[0]['phone']; // print_r($res); // exit(); // header('Location:https://iot.usky.cn/ceshi.html?op='.$res['openid']);//项目首页 header('Location:https://qhome.usky.cn/work/#/?op='.$res[0]['openid']); } else { unset($_SESSION['idopenid']); unset($_SESSION['phone']); header('Location:https://qhome.usky.cn/work/index.html#/pages/login/login');//登录页 // header('Location:https://qhome.usky.cn/work/index.html#/pages/login/login'); } } } } private function s_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $file_contents = curl_exec($ch); curl_close($ch); $arr = json_decode($file_contents, true); return $arr; } }