/** Generic request using the protocol:
  * POSTs data & files, checks the magic header
  * @param array $post Arbitrary data to POST
  * @param array $files Files to upload: { name: path | [path, filename] | [path, filename, mimetype] }
  * @return HttpResponse
  * @throws RemScriptProtocolError
  */
 function _request($post, $files)
 {
     # Prepare
     $request = new HttpRequest($this->script_url, 'POST');
     $request->mimicBrowser();
     $request->headers['Connection'] = 'Close';
     $request->post($post);
     if (!empty($files)) {
         foreach ($files as $name => $upload) {
             list($path, $filename, $mimetype) = (array) $upload + array(null, null, null);
             $request->upload($name, $path, $filename, $mimetype);
         }
     }
     # Request
     try {
         $response = $request->open();
     } catch (HttpRequestError $e) {
         throw new RemScriptProtocolError('Request error: ' . $e->getMessage(), RemScriptProtocolError::REQUEST_ERROR, $e);
     }
     # Response: check code
     if ($response->code != 200) {
         throw new RemScriptProtocolError('Response code: ' . $response->code);
     }
     # Response: check magic
     $expected = self::RESPONSE_MAGIC;
     $actual = fread($response->f, strlen($expected));
     if ($actual !== $expected) {
         throw new RemScriptProtocolError('Wrong magic: ' . var_export($actual, 1));
     }
     # All okay
     return $response;
 }
 public function loginAction()
 {
     $this->view->disable();
     $http_request = new HttpRequest();
     print_r($_SERVER);
     $header = array('Host:106.37.195.128', 'User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0', 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Referer:http://106.37.195.128/chinalifepcsfa/system/userLogin.do', 'Connection:keep-alive');
     $data = 'platformType=0&userId=530123197902182620&password=sp182620';
     $http_respone = $http_request->post('http://106.37.195.128/chinalifepcsfa/system/userLogin.do', $header, $data);
     if (isset($http_respone->headers['Location'])) {
         $location = $http_respone->headers['Location'];
         $cookies = $http_respone->cookies;
         $header2 = array('Host:106.37.195.128', 'User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0', 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Referer:http://106.37.195.128/chinalifepcsfa/system/userLogin.do', 'Connection:keep-alive');
         $http_respone2 = $http_request->get($location, $header2, $cookies);
         preg_match('@href="(/chinalifepcsfa/user/electronicInsurance.do\\?.*)"@Ui', $http_respone2->content, $matches);
         $entrance_href = 'http://106.37.195.128' . $matches[1];
         $header3 = array('Host:106.37.195.128', 'User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0', 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Connection:keep-alive');
         $http_respone3 = $http_request->get($entrance_href, $header3, $cookies);
         $final_url = $http_respone3->headers['Location'];
         $_SESSION['emu_url'] = $final_url;
         $final_header = array('Host:106.37.195.128:7011', 'User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0', 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Connection:keep-alive');
         $final_http_response = $http_request->get($final_url, $final_header, $cookies);
         $_SESSION['emu_cookies'] = $final_http_response->cookies;
     } else {
         echo json_encode(array('success' => false, 'err_msg' => '用户名或密码错误!'));
     }
 }
 protected function _exec()
 {
     $payLog = LogFactory::getLogger(array('prefix' => LogFactory::LOG_MODULE_PLATFORM, 'log_dir' => APP_ROOT . '/log/ApplePayment/', 'archive' => ILogger::ARCHIVE_YEAR_MONTH, 'log_level' => 1));
     $gameuid = $this->getParam("gameuid", 'string');
     $key = $this->getParam("key", 'string');
     //提交审核的时候 使用 沙箱地址
     //		$verify_url = "https://sandbox.itunes.apple.com/verifyReceipt";
     $verify_url = 'https://buy.itunes.apple.com/verifyReceipt';
     $verify_postfields = json_encode(array("receipt-data" => $key));
     $res = HttpRequest::post($verify_url, $verify_postfields);
     $resData = json_decode($res['data'], true);
     if ($resData !== NULL && $resData["status"] == 0) {
         $tradeManager = new TradeLogManager();
         $receipt = $resData["receipt"];
         $id = $receipt['transaction_id'];
         $account = $this->user_account_mgr->getUserAccount($gameuid);
         $payLog->writeInfo($gameuid . " || " . $account['gem'] . " || " . json_encode($receipt));
         $cached_orders = $tradeManager->getOrderCache($gameuid);
         if (empty($cached_orders)) {
             $cached_orders = array();
         }
         if (empty($receipt)) {
             return array('status' => 'error');
         }
         if (in_array($id, $cached_orders)) {
             return TRUE;
         }
         $rewards = InitUser::$treasure_activity;
         $product_id = $receipt['product_id'];
         if ($product_id == "FAMEGEM01") {
             $change['gem'] = 200;
             $item = $this->addReward($gameuid, $rewards['littleFarmGem']);
         } elseif ($product_id == "FAMEGEM02") {
             $change['gem'] = 1100;
             $item = $this->addReward($gameuid, $rewards['largeFarmGem']);
         } else {
             $this->throwException("wrong product_id :" . $product_id, GameStatusCode::PARAMETER_ERROR);
         }
         $this->user_account_mgr->updateUserStatus($gameuid, $change);
         $tradeinfo = array();
         $tradeinfo['gameuid'] = $gameuid;
         $tradeinfo['product_id'] = $product_id;
         $tradeinfo['platform'] = "apple";
         $tradeinfo['orderId'] = $id;
         $tradeinfo['purchaseState'] = 1;
         $tradeinfo['purchasetime'] = time();
         $tradeinfo['status'] = 1;
         $tradeManager->insert($tradeinfo);
         $new_account = $this->user_account_mgr->getUserAccount($gameuid);
         array_push($cached_orders, $id);
         $tradeManager->setOrderCache($gameuid, $cached_orders);
         $payLog->writeInfo($gameuid . " || " . $new_account['gem']);
         if (empty($item)) {
             return array("gem" => $new_account['gem']);
         } else {
             return array("gem" => $new_account['gem'], "items" => $item);
         }
     }
 }
Beispiel #4
0
 /**
  * 发送一个rest Api 请求
  * @param string $api 请求地址
  * @param array<K,V> $query 请求参数
  * @param string $method 请求方法 目前只支持 GET, POST
  * @param string $header http header
  * @param string $curlOpts curl选项
  * @return mixed 解析结果,如果失败将返回false, 否则应返回解析后的服务端返回的json数据
  */
 protected function sendRequest($api, $query, $method = "POST", $header = null, $curlOpts = null)
 {
     $url = $this->http->getResourceAddress($api);
     $query['sign'] = $this->genSign($method, $url, $query);
     if ($header == null) {
         $header = array('User-Agent: ' . $this->makeUA());
     }
     if ($method == 'GET') {
         $response = $this->http->get($api, $query, $header, $curlOpts);
     } else {
         $response = $this->http->post($api, $query, $header, $curlOpts);
     }
     return $this->parse($response);
 }
Beispiel #5
0
 /**
  * @depends testCreateHttpRequest
  * @param HttpRequest $http
  */
 public function testPost($http)
 {
     $rs = $http->post('httpServer.php', $this->payload);
     $this->valiedResponse($rs);
 }