89oinotna Posted April 28, 2017 Report Posted April 28, 2017 i have a problem with the mobile confirmation, this is my code: public static function bufferizeSecret($secret) { if (preg_match('/[0-9a-fA-F]{40}/', $secret)) { return pack('H*', $secret); } if (preg_match('/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/', $secret)) { return base64_decode($secret); } return $secret; } public function generateConfirmationUrl($tag = 'conf') { return 'https://steamcommunity.com/mobileconf/conf?'. $this->generateConfirmationQueryParams($tag); } public function generateConfirmationQueryParams($tag) { $time = time(); return 'p=android:' . $this->deviceId . '&a=' . $_SESSION['steamid'] . '&k=' . $this->getConfirmationKey($time, $tag) . '&t=' . $time . '&m=android&tag=' . $tag; } public static function getConfirmationKey($time, $tag) { if (empty($tag)) { $buf = pack('NN', 0, $time); } else { $buf = pack('NNa*', 0, $time, $tag); } $hmac = hash_hmac('sha1', $buf, self::bufferizeSecret($secret), true); return base64_encode($hmac); } public function fetchConfirmations() { $url = $this->generateConfirmationUrl();echo $url; $confirmations = []; $response = ''; try { $response = $this->request('POST', $url, null);print_r($response); } catch (\Exception $ex) { return $confirmations; } if (strpos($response, '<div>Nothing to confirm</div>') === false) { $confIdRegex = '/data-confid="(\d+)"/'; $confKeyRegex = '/data-key="(\d+)"/'; $confDescRegex = '/<div>((Confirm|Trade with|Sell -) .+)<\/div>/'; preg_match_all($confIdRegex, $response, $confIdMatches); preg_match_all($confKeyRegex, $response, $confKeyMatches); preg_match_all($confDescRegex, $response, $confDescMatches); if (count($confIdMatches[1]) > 0 && count($confKeyMatches[1]) > 0 && count($confDescMatches) > 0) { for ($i = 0; $i < count($confIdMatches[1]); $i++) { $confId = $confIdMatches[1][$i]; $confKey = $confKeyMatches[1][$i]; $confDesc = $confDescMatches[1][$i]; //$confirmations[] = new Confirmation($confId, $confKey, $confDesc); } } } return $confirmations; } public function request($type, $url, $data=null){if(isset($_SESSION['oauth_token'])){$this->mobile=true;}$c = curl_init();curl_setopt($c, CURLOPT_HEADER, false);curl_setopt($c, CURLOPT_NOBODY, false);curl_setopt($c, CURLOPT_URL, $url);curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);if ($this->mobile) { // curl_setopt($c, CURLOPT_HTTPHEADER, ["X-Requested-With: com.valvesoftware.android.steam.community"]); curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"); curl_setopt($c, CURLOPT_COOKIE, $this->buildCookie(self::$DEFAULT_MOBILE_COOKIES)); } else {curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"); }if(isset($data)){curl_setopt($c, CURLOPT_POST, 1);curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($data));}curl_setopt($c, CURLOPT_RETURNTRANSFER, true);curl_setopt($c, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($c, CURLOPT_CUSTOMREQUEST, strtoupper($type));$return = curl_exec($c);if(curl_error($c)){echo 'error:' . curl_error($c);}curl_close($c); //print_r($return);return $return;} private function buildCookie($cookie) { $out = ""; foreach ($cookie as $k => $c) { $out .= "{$k}={$c}; "; } return $out; } but i don't know why it give this error Bad RequestYour browser sent a request that this server could not understand. could anyone help me? Quote
Dr. McKay Posted April 28, 2017 Report Posted April 28, 2017 You need to send a GET request to fetch confirmations. Quote
89oinotna Posted April 29, 2017 Author Report Posted April 29, 2017 lol thank you, now it works Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.