public static function getUserInfo() { // if($userInfo = session('userInfo')){ // return $userInfo; // } $companyInfo = self::getCompanyInfo(); $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']); $weixin = new Wechat($options); if ($userInfo = $weixin->getOauthAccessToken()) { $m = M("Company_888_user_info"); $opt['openId'] = $userInfo['openid']; $result = $m->where($opt)->find(); if ($result) { session('userInfo', $result); return $result; } else { $id = $m->add($opt); $opt['id'] = $id; session('userInfo', $opt); return $opt; } } if (I('get.redirct') == 1) { return ''; } $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&redirct=1'; $url = urlencode($url); $redirctUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$companyInfo['weixin_AppId']}&redirect_uri={$url}&response_type=code&scope=snsapi_base&state=0#wechat_redirect"; header("Location: {$redirctUrl}"); }
public function index() { $companyInfo = $this->getCompanyInfo(888); $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']); $weixin = new Wechat($options); $userInfo = $weixin->getOauthAccessToken(); $type = I('get.t'); if ($this->RedirectUrl($userInfo['openid'], 888)) { switch ($type) { case 'shop-index': header("Location: http://www.icalex.com/Mobile/"); break; case 'shop-product': header("Location: http://www.icalex.com/Mobile/Product"); break; case 'shop-car': header("Location: http://www.icalex.com/Mobile/Order"); break; case 'exchangeQrcode': $m = M('Company_pay_qrcode_paylog'); $result = $m->find(I('get.id')); if (in_array($userInfo['openid'], C('ADMIN_OPENID'))) { if ($result && !$result['exchangeSign']) { $opt['exchangeSign'] = 1; $opt['exchangeTime'] = date("Y-m-d H:i:s"); $opt['exchangeOpenId'] = $userInfo['openid']; $opt['id'] = I('get.id'); if ($m->save($opt)) { echo "<h1>success!</h1>"; } } else { echo "<h1>error!</h1>"; } } else { echo "<h1>no permission!</h1>"; } break; default: header("Location: http://www.icalex.com"); break; } } }