public function invitationGet()
 {
     $openid = I('get.u');
     $companyInfo = $this->getCompanyInfo();
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new TPWechat($options);
     if (!$openid) {
         $oauthToken = $weixin->getOauthAccessToken();
         if (!$oauthToken) {
             $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
             //$url = urlencode($url);
             $redirctUrl = $weixin->getOauthRedirect($url, '', 'snsapi_base');
             header("Location: {$redirctUrl}");
         }
         $openid = $oauthToken['openid'];
     }
     $this->assign('openid', $openid);
     $auth = $weixin->checkAuth();
     $api_ticket = $weixin->getJsTicket();
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $js_sign = $weixin->getJsSign($url);
     $time = time();
     $card_id = 'pk0Ius992-phYJGSJLG2dJfBuFvw';
     $this->assign('card_id', $card_id);
     $signature = new Signature();
     $signature->add_data($api_ticket);
     $signature->add_data($card_id);
     $signature->add_data(strval($time));
     $this->assign('card_signature', $signature->get_signature());
     $this->assign('js_sign', $js_sign);
     $this->assign('tm', $time);
     $this->assign('api_ticket', $api_ticket);
     $this->display();
 }
Esempio n. 2
0
 public static function getUserInfo()
 {
     $companyInfo = self::getCompanyInfo();
     $options = array('token' => 'tokenaccesskey', 'appid' => $companyInfo['weixin_AppId'], 'appsecret' => $companyInfo['weixin_AppSecret']);
     $weixin = new TPWechat($options);
     $userInfo = $weixin->getOauthAccessToken();
     if ($userInfo) {
         $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}");
 }
Esempio n. 3
0
 public static function getOpenid()
 {
     $appid = C('WECHAT_APPID');
     $appsecret = C('WECHAT_SECRET');
     $options = array('appid' => $appid, 'appsecret' => $appsecret);
     $weixin = new TPWechat($options);
     $userInfo = $weixin->getOauthAccessToken();
     if ($userInfo) {
         return $userInfo['openid'];
     }
     // if(I('get.redirct') == 1)
     //     return false;
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
     $url = urlencode($url);
     $redirctUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$url}&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
     header("Location: {$redirctUrl}");
 }