令牌无效Travian从curl打电话时

时间:2017-07-24 00:55:10

标签: php curl

我尝试将银交换为黄金,但我收到错误消息:

{"response": {"error":true,"errorMsg":"Token invalid","data":[]}}

令牌是对的,但我不知道这个错误可以帮助我修复

$url ='http://ts1.travian.com/dorf1.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE,$dir  . '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$response = curl_exec($ch);
preg_match("/ajaxToken = '(.*?)'/s", $response, $s3);
$url ='http://ts1.travian.com/ajax.php?cmd=silverExchange';
$data = array('cmd'=>'silverExchange','exTyp'=>'SilverToGold','s' =>'200','g'=>'1','ajaxToken'=>$s3[1]);                                                
$data_json = json_encode($data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);

0 个答案:

没有答案