Exemple #1
0
 /**
  * 调用微信SDK接口,获得相关Token
  * @return 微信SDK接口返回的Token
  */
 private function getAccessToken()
 {
     // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
     $data = json_decode(CTools::GetPHPFileContent("access_token.php"));
     if ($data->expire_time < time()) {
         // 如果是企业号用以下URL获取access_token
         //$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appID&corpsecret=$this->appSecret";
         $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appID}&secret={$this->appSecret}";
         $res = json_decode(CTools::httpGet($url));
         //CTools::SetPHPFileContent("jsapi_token_original.php", json_encode($res));
         $access_token = $res->access_token;
         if ($access_token) {
             $data->expire_time = time() + 7000;
             $data->access_token = $access_token;
             CTools::SetPHPFileContent("access_token.php", json_encode($data));
         }
     } else {
         $access_token = $data->access_token;
     }
     return $access_token;
 }
 function OnActivate()
 {
     global $root;
     //---- validation request
     if (!isset($_REQUEST['key'])) {
         header("Location: http://{$root}/wr_error_invalid.html");
         exit;
     }
     //---- receive key
     $key = str_replace('_', '&', $_REQUEST['key']);
     //--- check activation
     $this->CheckActivation($key);
     //----
     $tools = new CTools();
     //---- extract data and crc32
     $data = base64_decode(str_replace(array('&', ','), array('+', '/'), $key));
     $data = explode("\n", gzuncompress($tools->Crypt($data, $this->crypt_key)));
     $crc32 = base_convert(crc32(implode("\n", array_slice($data, 0, -1))), 10, 36);
     //---- check crc
     if ($crc32 == $data[15]) {
         //--- put parameters in our structure
         $this->user['email'] = $data[0];
         $this->user['password'] = $data[1];
         $this->user['group'] = $data[2];
         $this->user['leverage'] = $data[3];
         $this->user['zipcode'] = $data[4];
         $this->user['country'] = $data[5];
         $this->user['state'] = $data[6];
         $this->user['city'] = $data[7];
         $this->user['address'] = $data[8];
         $this->user['phone'] = $data[9];
         $this->user['name'] = $data[10];
         $this->user['phone_password'] = $data[11];
         $this->user['send_reports'] = $data[12];
         $this->user['deposit'] = $data[13];
         //--- map group name
         $this->user['group'] = Group($this->user['group']);
         //--- create new account
         $ret = $this->CreateAccount($this->user);
         //--- parse result
         $ret = explode("\r\n", $ret);
         //--- it is error?
         if (empty($ret) || empty($ret[0]) || $ret[0] == 'error' || $ret[0] == 'ERROR') {
             //--- parse error code
             if (strpos($ret[1], 'blocked') !== false) {
                 header("Location: http://{$root}/wr_error_blocked.html");
             } else {
                 header("Location: http://{$root}/wr_error_internal.html");
             }
             exit;
         }
         //--- receive login
         $login = explode("=", $ret[1]);
         if (is_array($login)) {
             $login = $login[1];
         }
         //--- set activation
         $this->SetActivation($key);
         //--- goto to complete page
         header("Location: http://{$root}/wr_complete.php?login={$login}");
     } else {
         header("Location: http://{$root}/wr_error_internal.html");
     }
     exit;
 }