I'm working on Payfort API integration, and facing a problem with integrating using PHP. The link which I have followed mistake is in merchant reference. Where to get this reference?
<?php
$merchant_reference = 'TEST81003';
$redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$return_url = 'https://love.ae/admin/public/login';
$requestParams = array(
'command' => 'PURCHASE',
'access_code' => 'bSCrsxniHsJqWtQ9ki15',
'merchant_identifier' => 'xPzUtIjC',
'merchant_reference' => 'TEST81003',
'amount' => 1050*100,
'currency' => 'AED',
'language' => 'en',
'customer_email' => 'alraqbani#gmail.com',
'token_name' => 'ali',
'return_url' => 'https://love.ae/admin/public/login',
'card_security_code' => '123',
);
// calculating signature
$shaString = '';
ksort($requestParams);
$SHARequestPhrase = '$2y$10$IGSCjOlk9';
$SHAResponsePhrase = '$2y$10$Ll6DBCeeH';
$SHAType = 'sha256';
foreach ($requestParams as $k => $v) {
$shaString .= "$k=$v";
}
if (1 == 1)
$shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
else
$shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;
$signature = hash($SHAType, $shaString);
$requestParams['signature'] = hash($SHAType, $shaString);
// calling payfort api using curl
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
//'Accept: application/json, application/*+json',
//'Connection:keep-alive'
));
curl_setopt($ch, CURLOPT_URL, $redirectUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to wait while trying to connect
//curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']); // timeout in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
return $response;
?>
{"amount":"105000","response_code":"00044","signature":"e85cd4511c0b21649871c3b857d8782a1f4c326325cb04891720a2bb1bae400c","merchant_identifier":"xPzUtIjC","access_code":"bSCrsxniHsJqWtQ9ki15","language":"en","command":"PURCHASE","response_message":"Token name does not exist","merchant_reference":"TEST81003","customer_email":"alraqbani#gmail.com","currency":"AED","status":"00"}
<?php
$merchant_reference = 'TEST81003';
$redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$return_url = 'https://love.ae/admin/public/login';
$requestParams = array(
'command' => 'PURCHASE',
'access_code' => 'bSCrsxniHsJqWtQ9ki15',
'merchant_identifier' => 'xPzUtIjC',
'merchant_reference' => 'TEST81003',
'amount' => 1050*100,
'currency' => 'AED',
'language' => 'en',
'customer_email' => 'alraqbani#gmail.com',
'token_name' => 'ali',
'return_url' => 'https://love.ae/admin/public/login',
'card_security_code' => '123',
);
// calculating signature
$shaString = '';
ksort($requestParams);
$SHARequestPhrase = '$2y$10$IGSCjOlk9';
$SHAResponsePhrase = '$2y$10$Ll6DBCeeH';
$SHAType = 'sha256';
foreach ($requestParams as $k => $v) {
$shaString .= "$k=$v";
}
if (1 == 1)
$shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
else
$shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;
$signature = hash($SHAType, $shaString);
$requestParams['signature'] = hash($SHAType, $shaString);
// calling payfort api using curl
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101
Firefox/20.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
//'Accept: application/json, application/*+json',
//'Connection:keep-alive'
));
curl_setopt($ch, CURLOPT_URL, $redirectUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to
wait while trying to connect
//curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']);
// timeout in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
return $response;
?>
merchant_reference is a unique order number for each payment request.
It could be Primary key of the table or can be generated uniquely.
e.g.
$merchant_reference = '5000-'.time();
merchant_reference
Alphanumeric
Max: 40
Related
in the below example, when i am enabling post data curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
getting 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method', but when i disabled the post data, its working.
Should i pass this data parameters anywhere else?
$get_token = new GetToken();
$token_obj = $get_token->get_session_token();
$accessKeyID = $token_obj->access_key_id;
$secretAccessKey = $token_obj->secret_key;
$regionName = $token_obj->region;
$serviceName = 'execute-api';
$httpMethodName = 'POST';
$canonicalURI = '/orders/salesorder';
$queryParametes = array();
$awsHeaders = array('content-type'=>'application/json','host'=>'api.mysite.com','id_token'=>$token_obj->id_token,'x-amz-date'=>gmdate("Ymd\THis\Z"),'x-amz-security-token'=>$token_obj->session_token);
$payload = "";
$get_aws4_sign = new AWSV4($accessKeyID,$secretAccessKey,$regionName,$serviceName,$httpMethodName,$canonicalURI,$queryParametes,$awsHeaders,$payload);
$headers_result = $get_aws4_sign->getHeaders();
$headersArr = array(
'host' => $headers_result['host'],
'id_token' => $headers_result['id_token'],
'xamzdate' => $headers_result['x-amz-date'],
'xamzsecuritytoken' => $headers_result['x-amz-security-token'],
'Authorization' => $headers_result['Authorization']
);
$data = array("id" => "126757879");
$data_string = json_encode($data);
$ch = curl_init('https://api.mysite.com/orders/salesorder');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'content-type: '.$headers_result['content-type'],
'host: '.$headers_result['host'],
'id_token: '.$headers_result['id_token'],
'x-amz-date: '.$headers_result['x-amz-date'],
'x-amz-security-token: '.$headers_result['x-amz-security-token'],
'Authorization: '.$headers_result['Authorization']
));
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result = json_decode( curl_exec($ch), TRUE);
//close connection
curl_close($ch);
print_r($result);
$get_token = new GetToken();
$token_obj = $get_token->get_session_token();
$accessKeyID = $token_obj->access_key_id;
$secretAccessKey = $token_obj->secret_key;
$regionName = $token_obj->region;
$serviceName = 'execute-api';
$httpMethodName = 'POST';
$canonicalURI = '/orders/salesorder';
$queryParametes = array();
$awsHeaders = array('content-type'=>'application/json','host'=>'api.mysite.com','id_token'=>$token_obj->id_token,'x-amz-date'=>gmdate("Ymd\THis\Z"),'x-amz-security-token'=>$token_obj->session_token);
$data = array("id" => "126757879");
$data_string = json_encode($data);
$payload = $data_string;
$get_aws4_sign = new AWSV4($accessKeyID,$secretAccessKey,$regionName,$serviceName,$httpMethodName,$canonicalURI,$queryParametes,$awsHeaders,$payload);
$headers_result = $get_aws4_sign->getHeaders();
$headersArr = array(
'host' => $headers_result['host'],
'id_token' => $headers_result['id_token'],
'xamzdate' => $headers_result['x-amz-date'],
'xamzsecuritytoken' => $headers_result['x-amz-security-token'],
'Authorization' => $headers_result['Authorization']
);
$ch = curl_init('https://api.mysite.com/orders/salesorder');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'content-type: '.$headers_result['content-type'],
'host: '.$headers_result['host'],
'id_token: '.$headers_result['id_token'],
'x-amz-date: '.$headers_result['x-amz-date'],
'x-amz-security-token: '.$headers_result['x-amz-security-token'],
'Authorization: '.$headers_result['Authorization']
));
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result = json_decode( curl_exec($ch), TRUE);
//close connection
curl_close($ch);
print_r($result);
Good day! I'm trying to load an image using the method appWidgets.saveAppImage. In the beginning I receive URL the server for loading -> getAppImageUploadServer, there all ok!
I receive a hash and an image, send them a POST request and get an error. Here is my code:
$token = "Service_access_key";
$tmp_image = file_get_contents('https://www.ejin.ru/wp-content/uploads/2017/12/667108931864_667108931864-150x150.jpg');
file_put_contents(dirname(__FILE__).'/tmp.jpg',$tmp_image);
$img_path = dirname(__FILE__).'/tmp.jpg';
$post_data = array("image" => "#".$img_path);
$upload_url = file_get_contents("https://api.vk.com/method/appWidgets.getAppImageUploadServer?v=5.85&image_type=50x50&access_token=".$token);
$url = json_decode($upload_url)->response->upload_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
$safe = file_get_contents("https://api.vk.com/method/appWidgets.saveAppImage?v=5.85&hash=".$result['hash']."&image=".$result['image']."&access_token=".$token);
echo $safe;
echo:
"error_code":129,"error_msg":"Invalid photo: file not found, from upl_850128?act=app_widget_image"
what's my mistake?
<?
$request_params = array(
'image_type' => '510x128',
'access_token' => 'xxx',
'v' => '5.92'
);
$t = json_decode(file_get_contents('https://api.vk.com/method/appWidgets.getAppImageUploadServer?'. http_build_query($request_params)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $t->response->upload_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("image" => new CURLFile(dirname(__FILE__).'\img.jpg')));
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
$request_params = array(
'hash' => $result->hash,
'image' => $result->image,
'access_token' => 'xxx',
'v' => '5.92'
);
print_r(file_get_contents('https://api.vk.com/method/appWidgets.saveAppImage?'. http_build_query($request_params)));
?>
I am trying to POST "/orders" to GDAX using a simple PHP function. I am getting no response and no errors. Orders are not getting placed and there are no PHP errors/warnings.
Not sure where I am going wrong.
function gdaxPost ($path, $post_array){
$url = 'https://api-public.sandbox.gdax.com/'.$path;
// Sandbox API #1 - fake key
$key = "03cc35bd4fb48ardad8097e0a45f";
$secret = "ihGzWV+li8AweKcL+oMDUvBzlmq9fR7z6rKksg43VFcWA3zysg6TxM+gGhEn0wg==";
$passphrase = "jqer9jxgfa6qcl";
$time = time();
$data = $time."POST"."/orders";
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret), true));
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_array));
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
return $res;
}
$path = 'orders';
$post_array = array(
"price" => "600",
"size" => "1.01",
"side" => "buy",
"type" => 'limit',
"time_in_force" => "GTC",
"product_id" => "BTC-USD"
);
print_r(json_decode(gdaxPost ($path, $post_array)),true);
EDIT: I fixed the code!
This is the updated working code:
function gdaxPost ($path, $post_array){
$url = 'https://api-public.sandbox.gdax.com/'.$path;
// Sandbox API #1 - fake key
$key = "03cc35bd4fb48ardad8097e0a45f";
$secret = "ihGzWV+li8AweKcL+oMDUvBzlmq9fR7z6rKksg43VFcWA3zysg6TxM+gGhEn0wg==";
$passphrase = "jqer9jxgfa6qcl";
$time = time();
$data = $time."POST"."/".$path.json_encode($post_array);
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret), true));
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_array));
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
return $res;
}
$path = 'orders';
$post_array = array(
"price" => "600",
"size" => "1.01",
"side" => "buy",
"type" => 'limit',
"time_in_force" => "GTC",
"product_id" => "BTC-USD"
);
print_r(gdaxPost ($path, $post_array));
I'm quite new in PHP but for practise I wanted to write a script using curl for logging and send post request to a page site written in asp. I've used libcurl and simple_html_dom.php libraries.
Sometimes I got an error for invalid viewstate, this is the stack trace:
[ViewStateException: Invalid viewstate.
Client IP: 111.11.11.111
Port: 4743
User-Agent: Mozilla/5.0
ViewState: /wEPDwUKLTk1OTAzODYwMA9kFgJmD2QWBAIBD2QWAgIBD2QWCmYPFgIeBFRleHQFRTxtZXRhIHByb3BlcnR5PSJvZzp0aXRsZSIgY29udGVudD0iQURJREFTIEVRVCBSVU5OSU5HIENVU0hJT04gOTEiIC8+IGQCAQ8WAh8ABWY8bWV0YSBwcm9wZXJ0eT0ib2c6aW1hZ2UiIGNvbnRlbnQ9Imh0dHA6Ly9zaG9wLnVyYmFuanVuZ2xlc3RvcmUuaXQvZm90b19hcnRpY29saS9kNjc1NjgtaW50cm8uanBnIiAvPiBkAgIPFgIfAAWVBDxtZXRhIHByb3BlcnR5PSJvZzpkZXNjcmlwdGlvbiIgY29udGVudD0iUmVjZW50ZW1lbnRlLCBvbHRyZSBhbGxlIG1pdGljaGUgU3RhbiBTbWl0aCwgc29ubyB0b3JuYXRlIGluIGF1Z2UgZGVpIHBlenppIGRlbGxhIHNlcmllIE9kZGl0eS4gTmVsIDIwMDUgYWRpZGFzIGhhIGxhbmNpYXRvIHVuYSBjb2xsZXppb25lIHNwZWNpYWxlIGRpIHJ1bm5lcnMgY29uIGFsY3VuaSBkZWkgY29sb3JpIHBpJnVncmF2ZTsgcGF6emkgY2hlIHNpIHBvc3Nhbm8gbWV0dGVyZSBzdSB1bmEgc25lYWtlci4gRSBtZW50cmUgcXVlc3RvIG1vZGVsbG8gZGkgYWRpZGFzIEVRVCBSdW5uaW5nIEN1c2hpb24gbm9uIGZhIHVmZmljaWFsbWVudGUgcGFydGUgZGVsIHJpdG9ybm8gZGVsbGEgY29sbGV6aW9uZSBPZGRpdHkgKG8gZm9yc2UgcyZpZ3JhdmU7PyksIGx...]
[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
http://go.microsoft.com/fwlink/?LinkID=314055]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +153
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +237
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +207
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +199
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.web_articolo_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Here is my code:
<?php
include('simple_html_dom.php');
//method for logging
function login($url,$data){
$headers = array(
'Host' => 'site',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-US;q=0.5,en;q=0.3',
'Accept-Encoding' => 'gzip, deflate',
'Referer' => 'http://somesite.com',
'Connection' => 'keep-alive',
'Content-Type' => 'application/x-www-form-urlencoded'
);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 4000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, 1);
curl_setopt($login, CURLOPT_HTTPHEADER, $headers);
curl_setopt($login, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_POST, 1);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
//$verbose = curl_setopt($login, CURLOPT_VERBOSE, true);
$ris = curl_exec ($login);
curl_close($login);
unset($login);
return $ris;
}
//method for posting data
function post_data($site,$data){
$datapost = curl_init();
curl_setopt($datapost, CURLOPT_URL, $site);
curl_setopt($datapost, CURLOPT_TIMEOUT, 4000);
curl_setopt($datapost, CURLOPT_HEADER, 1);
//curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
curl_setopt($datapost, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($datapost, CURLOPT_POST, 1);
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
$result = curl_exec ($datapost);
curl_close ($datapost);
return $result;
}
function getParamLogin($url,$pageType) {
//return the html page
$html = file_get_html($url);
$eventtarget = '';
$eventargument = '';
if(sizeof($html->find('[id=__EVENTTARGET]')) > 0)
$eventtarget = $html->find('[id=__EVENTTARGET]')[0]->value;
if(sizeof($html->find('[id=__EVENTARGUMENT]')) > 0)
$eventargument = $html->find('[id=__EVENTARGUMENT]')[0]->value;
//post params
$params = array('ctl00_ScriptManager1_HiddenField' => $html->find('[id=ctl00_ScriptManager1_HiddenField]')[0]->value,
'__EVENTTARGET' => $eventtarget,
'__EVENTARGUMENT' => $eventargument,
'__VIEWSTATE' => $html->find('[id=__VIEWSTATE]')[0]->value,
'__VIEWSTATEGENERATOR' => $html->find('[id=__VIEWSTATEGENERATOR]')[0]->value,
'__EVENTVALIDATION' => $html->find('[id=__EVENTVALIDATION]')[0]->value,
'ctl00$search' => '',
'ctl00$newsletter' => ''
);
switch ($pageType) {
case 'firstpage':
$login = array('ctl00$pagina$tlogin_area' => 'user',
'ctl00$pagina$tpassword_area' => 'passwd',
'ctl00$pagina$tinvia' => 'ACCEDI',);
$params = array_merge($params,$login);
break;
case 'secondpage':
$cart = array('__SCROLLPOSITIONX' => '0',
'__SCROLLPOSITIONY' => '0',
'ctl00$pagina$taglie' => '6M',
'ctl00$pagina$tag' => 'Aggiungi al carrello');
$params = array_merge($params,$cart);
break;
}
print_r($params);
return $params;
}
?>
<?php
login('http://www.loginpage.com', getParamLogin('http://www.loginpage.com','firstpage'));
post_data('http://www.anotherpage.com',getParamLogin('http://www.anotherpage.com','secondpage'));
?>
I wonder if there is also a cookie in handle the cookie and then in the viewstate... Someone can help me? Thank you!
i have problem with this website api,
i used this code to generate a shorturl by this api but always i got a White Page Screen without any content!
Please Help me to generate a url:
<?php
function bucksapi($longUrl)
{
$bucksapi = 'myapipass';
$sinoone = 'myusername';
$adts = '2';
$contype = '1';
$domainss = 'linkbucks.com';
$postData = array('originalLink' => $longUrl, 'user' => $sinoone, 'apiPassword' => $bucksapi, 'contentType' => $contype, 'adType' => $adts, 'domain' => $domainss);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.linkbucks.com/api/createLink/single');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
//As the API is on https, set the value for CURLOPT_SSL_VERIFYPEER to false. This will stop cURL from verifying the SSL certificate.
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
$json = json_decode($response);
curl_close($curlObj);
return $json->link;
}
?>
and this for printing the short link:
<?php
$long_url = "http://google.com";
echo bucksapi($long_url);
?>
Based on your work.
<?php
function curl($url, $cookies= NULL, $post = NULL)
{
$ch = #curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (!empty($cookies)) {
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
$page = curl_exec($ch);
var_dump($page);
curl_close($ch);
return $page;
}
function bucksapi($longUrl, $bucksapi, $sinoone, $adts = '2', $contype = '1')
{
$postData = array(
'originalLink' => $longUrl,
'user' => $sinoone,
'apiPassword' => $bucksapi,
'contentType' => $contype,
'adType' => $adts,
'domain' => 'linkbucks.com'
);
$json = json_decode(
curl(
'https://www.linkbucks.com/api/createLink/single',
NULL,
json_encode($postData)
)
);
var_dump($json);
return $json->link;
}
var_dump( bucksapi( "LINK_URL", 'API_KEY', 'USER_NAME' ) );
?>