public function action_login() { $wx = new WeixinOauth(); $callback_url = $_GET['callback_url']; $login_url = $wx->get_login_url($callback_url); $this->redirect($login_url); }
public function action_index() { $wx = new WeixinOauth(); $user_info = $wx->get_user_info(); if (empty($user_info)) { $callback_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $this->redirect('weixin/oauth/login?callback_url=' . urlencode($callback_url)); } $this->template = View::factory('wschat'); $this->template->user_info = $user_info; }
public function action_wxlogin() { $wx = new WeixinOauth('test'); $user_info = $wx->get_user_info(); if (empty($user_info)) { $redirect_uri = URL::curr(); $this->redirect('weixin/oauth/login?callback_url=' . urlencode($redirect_uri)); } $update_user_info = Cookie::get('update_wx_user'); if (empty($update_user_info)) { $m_wx = Model::factory('oauth_wx_user', 'admin'); $wx_user_field = array('openid' => 1, 'nickname' => 1, 'sex' => 1, 'city' => 1, 'province' => 1, 'country' => 1, 'headimgurl' => 1); $wx_user_info = array_intersect_key($user_info, $wx_user_field); $m_wx->replace_into($wx_user_info); Cookie::set('update_wx_user', 1, 86400); } $user = array('id' => 'wx_' . $user_info['openid'], 'username' => $user_info['nickname'], 'avatar' => $user_info['headimgurl']); $auth = Auth::instance('member'); if ($auth->force_login($user)) { $this->redirect(Request::$referrer); } }
/** * 构造表单提交 * @param array $params * @return string */ public static function build_http_query_multi($params) { if (!$params) { return ''; } uksort($params, 'strcmp'); $pairs = array(); self::$boundary = $boundary = uniqid('------------------'); $MPboundary = '--' . $boundary; $endMPboundary = $MPboundary . '--'; $multipartbody = ''; foreach ($params as $parameter => $value) { if (in_array($parameter, array('pic', 'image')) && $value[0] == '@') { $url = ltrim($value, '@'); $content = file_get_contents($url); $array = explode('?', basename($url)); $filename = $array[0]; $multipartbody .= $MPboundary . "\r\n"; $multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"' . "\r\n"; $multipartbody .= "Content-Type: image/unknown\r\n\r\n"; $multipartbody .= $content . "\r\n"; } else { $multipartbody .= $MPboundary . "\r\n"; $multipartbody .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n"; $multipartbody .= $value . "\r\n"; } } $multipartbody .= $endMPboundary; return $multipartbody; }