PHP curl simulation on Jingdong, "general tips to refresh the page after the re

Development after landing, can be, but it has been suggested that
Array
(
[username] => Please refresh the page to re submit
)
This does not know what is going on, had not found any reason, depressed
The word does not say more, code, hope made heroes help,
<?php


class util_curl {
	var $headers;
	var $user_agent;
	var $compression;
	var $cookie_file;
	var $proxy;
	function util_curl($cookies=TRUE,$cookie='cookies.txt',$header = array(),$compression='gzip',$proxy='') {

		if(empty($header))
		{
			$this->headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
			$this->headers[] = 'Connection: Keep-Alive';
			//$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
			//$this->headers[] = '';
		}

		$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
		$this->compression=$compression;
		$this->proxy=$proxy;
		$this->cookies=$cookies;
		if ($this->cookies == TRUE) $this->cookie($cookie);
	}

	function cookie($cookie_file) {
		if (file_exists($cookie_file)) {
			$this->cookie_file=$cookie_file;
		} else {
			if($h = fopen($cookie_file,'w')){
				$this->cookie_file=$cookie_file;
				fclose($h);
			} else {
				$this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
			}

		}
	}
	function get($url) {
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($process, CURLOPT_HEADER, 0);
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($process,CURLOPT_ENCODING , $this->compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}

	function post($url,$data) {
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($process, CURLOPT_HEADER, 0);
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($process, CURLOPT_ENCODING , $this->compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
		curl_setopt($process, CURLOPT_POSTFIELDS, $data);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($process, CURLOPT_POST, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}

	function vpost($url,$data){ // Simulation of submitting data function
		$curl = curl_init(); // Start a CURL session
		//$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=GBK';
		curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($curl, CURLOPT_URL, $url); // To access the address
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // The certificate of inspection source
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // Check the SSL encryption algorithm exists from the certificate
		curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); // Used to simulate the user's browser
		//curl_setopt($curl, CURLOPT_NOBODY, 0);
		if ($this->cookies == TRUE) curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file);;
		if ($this->cookies == TRUE) curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // The use of automatic jump
		curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
		curl_setopt($curl, CURLOPT_POST, 1); // Send a regular Post requests
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post submit data packets
		curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set the timeout limit prevent death cycle
		curl_setopt($curl, CURLOPT_HEADER, 0); // Display Header content returned
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The information returned in document flow form
		$tmpInfo = curl_exec($curl); // Perform operation
		if (curl_errno($curl)) {
			echo 'Errno'.curl_error($curl);//Catching the exception
		}
		curl_close($curl); // Close the CURL session
		return $tmpInfo; // Return data
	}
	function vget($url){ // Simulation of submitting data function
		$curl = curl_init(); // Start a CURL session
		//$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=GBK';
		curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($curl, CURLOPT_URL, $url); // To access the address
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // The certificate of inspection source
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // Check the SSL encryption algorithm exists from the certificate
		curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); // Used to simulate the user's browser
		//curl_setopt($curl, CURLOPT_NOBODY, 0);
		if ($this->cookies == TRUE) curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file);;
		if ($this->cookies == TRUE) curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // The use of automatic jump
		curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
		//curl_setopt($curl, CURLOPT_POST, 0); // Send a regular Post requests
		//curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post submit data packets
		curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set the timeout limit prevent death cycle
		curl_setopt($curl, CURLOPT_HEADER, 1); // Display Header content returned
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The information returned in document flow form
		$tmpInfo = curl_exec($curl); // Perform operation
		if (curl_errno($curl)) {
			echo 'Errno'.curl_error($curl);//Catching the exception
		}
		curl_close($curl); // Close the CURL session
		return $tmpInfo; // Return data
	}

	function error($error) {
		echo "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>util_curl Error</b><br>$error</div></center>";
		die;
	}
}


$shopUser = array();
$shopUser['name'] = 'xxxx';
$shopUser['password'] = 'xxxxxxxxx';

$cookieFile = './cookie_aaa.txt';
$http = new util_curl(true,$cookieFile);

//1 to obtain the login page code, find the value of the UUID variable in the
$showLoginUrl = "https://passport.jd.com/new/login.aspx";
$loginViewStr = $http->vget($showLoginUrl);

preg_match('/<input type="hidden" id="uuid" name="uuid" value="([\s\S]*?)"/',$loginViewStr,$rs);
if(!isset($rs[1])) throw new Exception('Analysis of failure of UUID page source code analysis');
$uuid = $rs[1];

$loginUrl = "https://passport.jd.com/uc/loginService?uuid={$uuid}&ReturnUrl=http%3A%2F%2Fwww.jd.com%2F";
$fields = "uuid={$uuid}&loginname={$shopUser['name']}&nloginpwd={$shopUser['password']}&loginpwd={$shopUser['password']}&machineNet=&machineCpu=&machineDisk=&authcode=";
$response = $http->vpost($loginUrl,$fields);

$jsonObj = json_decode(str_replace(array('(',')'),'',$response),true);

if(isset($jsonObj['success'])) echo 'The successful landing';



print_r($jsonObj);exit;


Started by Winnie at October 26, 2016 - 10:00 PM

Did not do this man

Posted by Winnie at November 05, 2016 - 10:58 PM

Need to enter the code.

Posted by Cherry at November 08, 2016 - 11:26 PM