2012-02-14 65 views
0

我需要一个大约2012年的如何使用PHP cURL登录到UPS的示例。我不打电话之间的会话。有3页要提取,1)登录页面2)密码页面和3)发票页面如何使用php cURL登录到UPS.com

我以前工作过,但它不再。我删除了这个cookie文件,并且它工作了一段时间,然后我收到消息“您的当前请求由于不活动而超时了,您将需要重新启动您的请求。”如果我没有在窗口内登录,即使登录成功,也会超时。我尝试删除cookie文件并重新开始,并没有工作。任何想法如何使它超时窗口是无限的?这里有我有,凭证删除代码:

   $cookie_file_path = "/tmp/cookie.txt"; 
       // remove previous cookie 
       if (file_exists($cookie_file_path)) { 
      `rm -fr {$cookie_file_path}`; 
       } 
      $login_url = 'https://www.ups.com/one-to-one/login'; 
      $password_url = 'https://www.ups.com/one-to-one/password'; 
      $invoice_url = 'upsDOTcomSLASHviewbillSLASHinvoices'; 
      $agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0) Gecko/20100101 Firefox/10.0"; 

      $login_data = "sysid=null&lang=null&langc=null&method=null&returnto=null&loc=en_US&uid=<user_id>&rememberMe=1&next=Next&pm_fp=version%253D1%2526pm%255Ffpua%253Dmozilla%252F5%252E0%2520%2528windows%2520nt%25206%252E1%253B%2520wow64%253B%2520rv%253A10%252E0%2529%2520gecko%252F20100101%2520firefox%252F10%252E0%257C5%252E0%2520%2528Windows%2529%257CWin32%2526pm%255Ffpsc%253D24%257C1920%257C1200%257C1160%2526pm%255Ffpsw%253D%257Cqt6%257Cqt5%257Cqt4%257Cqt3%257Cqt2%257Cqt1%257Cswf%257Cpdf%257Cpdf%2526pm%255Ffptz%253D%252D5%2526pm%255Ffpln%253Dlang%253Den%252DUS%257Csyslang%253D%257Cuserlang%253D%2526pm%255Ffpjv%253D1%2526pm%255Ffpco%253D1"; 
      $password_data = "sysid=null&lang=null&langc=null&method=null&returnto=null&loc=en_US&password=<password>&next=Log+In&pm_fp=version%253D1%2526pm%255Ffpua%253Dmozilla%252F5%252E0%2520%2528windows%2520nt%25206%252E1%253B%2520wow64%253B%2520rv%253A10%252E0%2529%2520gecko%252F20100101%2520firefox%252F10%252E0%257C5%252E0%2520%2528Windows%2529%257CWin32%2526pm%255Ffpsc%253D24%257C1920%257C1200%257C1160%2526pm%255Ffpsw%253D%257Cqt6%257Cqt5%257Cqt4%257Cqt3%257Cqt2%257Cqt1%257Cswf%257Cpdf%257Cpdf%2526pm%255Ffptz%253D%252D5%2526pm%255Ffpln%253Dlang%253Den%252DUS%257Csyslang%253D%257Cuserlang%253D%2526pm%255Ffpjv%253D1%2526pm%255Ffpco%253D1"; 

      $headers[] = "Accept: */*"; 
      $headers[] = "Connection: Keep-Alive"; 
      $headers[] = "Content-Type: application/x-www-form-urlencoded"; 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $login_url); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
      curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
      curl_setopt($ch, CURLOPT_REFERER, 'https://www.ups.com/myups/login'); 
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
      ob_start(); 
      $result = curl_exec ($ch); 
      ob_end_clean(); 
      echo curl_error($ch); // prints nothing if successful 
      //curl_close($ch); 


      //$ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $password_url); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 
      curl_setopt($ch, CURLOPT_HEADER, 1); 
      curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $password_data); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
      curl_setopt($ch, CURLOPT_REFERER, $login_url); 
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
      ob_start(); 
      $result = curl_exec ($ch); 
      ob_end_clean(); 
      echo curl_error($ch)  // prints nothing if successful 
      //curl_close($ch); 


      //$ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $invoice_url); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html; charset=utf-8')); 
      curl_setopt($ch, CURLOPT_HEADER, 1); 
      curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $invoice_data); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
      curl_setopt($ch, CURLOPT_REFERER, $password_url); 
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
      ob_start(); 
      $result = curl_exec ($ch); 
      ob_end_clean(); 
      echo curl_error($ch);  // prints nothing if successful 
      curl_close($ch); 

我不能让过去的第一个登录页面,甚至删除并重新创建的cookie文件后,我得到:

您当前的请求已超时由于不活动。您将需要重新启动您的请求。

任何帮助表示赞赏。

+0

看起来违背了服务条款起坐做到这一点。 – 2012-02-14 01:01:53

+0

UPS确实有这样的API的API,你知道。 – 2012-02-14 01:22:39

回答

1
  1. 尝试从其他服务器连接。也许你被列入黑名单。
  2. CURLOPT_FRESH_CONNECTCURLOPT_FORBID_REUSE卷曲选项。 submiting后数据之前
  3. 访问登陆页面
0

是的,我很无聊,但这就是为什么你不应该这样做。

1.2˚FUPS技术协议:

自动访问。没有任何限制,任何通过自动查询设备,机器人或 托管的UPS技术访问UPS系统或 重复数据收集和提取工具,例程,脚本或具有类似功能的其他机制本身不是UPS 以下目的明文禁止使用 。

+0

啊,好吧,不知道。好吧,不幸的是我必须手动完成。他们没有这个API,顺便说一句。他们有一个跟踪和评级API,但他们没有开发票API。我很欣赏这些反馈。 – user1207994 2012-02-14 01:28:37

+0

我不为他们工作,无论如何,我都不会告诉他们:-) – 2012-02-14 01:32:04