I am trying to let people pay on my site with a simple API of Coinpayments (I tought it was simple). So, I found this page of the official Coinpayments website on how to create a transaction and receive money.
So, I am trying to receive the response as JSON en just echo it for now, so I can see what further steps I will take. Now, this is my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.coinpayments.net/index.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"cmd=create_transaction&amount=".$amount."¤cy1=USD¤cy2=BTC&buyer_email=".$email."&version=1&key=b07f0fee01909b919235d58a950378b8c0e5266fa2174e007b24220a592aa92e&format=json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
When I try to echo the $server_output, it gives this: ERROR: Invalid command!. I have searched around, and I couldn't find anybody having the same issue as I do.
Thanks for the help! <3
This is what works for me:
function curl_coin_payment ($postdata = array()) {
$url = "https://www.coinpayments.net/api.php";
$payload = $postdata;
$payload['key'] = 'public_key';
$payload['version'] = 1;
$payload = http_build_query($payload, '', '&');
$api_secret = 'private_key';
$apiseal = hash_hmac('sha512', ($payload), $api_secret);
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($payload)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
"HMAC: $apiseal",
"Content-Type: application/x-www-form-urlencoded",
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $request = curl_exec ($ch); curl_close ($ch);
return $request;
}
Related
The task seemed simple.
The login (email) used for authentication must be passed in the login request parameter. In the request body (Body), the user password is passed as a string encoded in UTF-8.
Example request:
POST /auth/authenticate-by-pass?login=testlogin#testDomain.net HTTP/1.1
Host: somehost.ru
Body: somepassword
Cache-Control: no-cache
If the request is successful, the response will contain a JSON object
Tried to do like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://somehost.ru/auth/authenticate-by-pass?login=mylogin#mydomain.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, "mypassword" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain', 'Host: somehost.ru'));
$result=curl_exec($ch);
$php_obj = json_decode($result, true);
print_r($php_obj);
No result. Nothing is displayed. Please help.
In my understanding what you need can be simply (please amend the headers to further suit your needs if necessary) :
$ch = curl_init();
$post = [
'password' => 'xxxxxx'
];
curl_setopt($ch, CURLOPT_URL, 'http://somehost.ru/auth/authenticate-by-pass?login=mylogin#mydomain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$php_obj = json_decode($result, true);
print_r($php_obj);
curl_close($ch);
Solved the problem. Ken Lee and everyone else thanks for the help.
$ch = curl_init();
$post = 'mypassword';
curl_setopt($ch, CURLOPT_URL, 'http://somehost.ru/auth/authenticate-by-pass?login=mylogin#mydomain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$php_obj = json_decode($result, true);
print_r($php_obj);
curl_close($ch);
How can create one workitem with CURL with PHP:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://dev.azure.com/fernandodomenike/fernando/_apis/wit/workitems/$Task?api-version=5.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
'file' => '#' .realpath('azure.json')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'secret');
$headers = array();
$headers[] = 'Content-Type: application/json-patch+json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
I try execute with command line Windows and work.
Whats is my wrong?
File upload via # is a feature from command line cURL client, you have to implement your own code on PHP to do that.
Example:
$json = file_get_contents('azure.json');
// Attach JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
I hope it helps you.
public function authorizationToken(){
$link = "https://api.ebay.com/identity/v1/oauth2/token";
$codeAuth = base64_encode($this->clientID.':'.$this->certID);
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '.$codeAuth));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=".urlencode($this->authCode)."&redirect_uri=".$this->ruName."&scope=".urlencode('https://api.ebay.com/oauth/api_scope'));
$response = curl_exec($ch);
$json = json_decode($response, true);$info = curl_getinfo($ch);
curl_close($ch);print_r($json);}
It looks like you are getting refresh_token confused with authorization_token, because you are mixing incompatible parameters between the two different requests.
If you are trying to get the initial "AccessToken" (AKA UserAccessToken, access_token, AuthToken, ...), then you should not include the scope parameter in your request body. So your request body should look like this:
grant_type=authorization_code&redirect_uri=<redirect_uri>&code=<authorization_code>
Where <authorization_code> is the value that is returned from here.
For an overview of the difference, I'd recommend this answer over the official docs on the topic.
Try this code
public function authorizationToken(){
$link = "https://api.ebay.com/identity/v1/oauth2/token";
$codeAuth = base64_encode($this->clientID.':'.$this->certID);
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '.$codeAuth));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&scope=".urlencode('https://api.ebay.com/oauth/api_scope'));
$response = curl_exec($ch);
$json = json_decode($response, true);
$info = curl_getinfo($ch);
curl_close($ch);
print_r($json);
}
I am using post method and sql query to send sms. So, I am just trying to get this link formet
http://example.com/smsapi/non-masking?api_key=$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG&smsType=text&mobileNo=(NUMBER)&smsContent=(Message Content)
but my curl code is not working.
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$numbers = "$row[mailing_no]";
$message = "Dear Guardian, $row[name] has swiped his card right now";
$type= "text";
$params = array('api_key'=>'$api_key', 'smsType'=>'$type', 'mobileNo'=>'$number', 'smsContent'=>'$message');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
Just made some improvements to your code, you were using $number on $params, but the variable was named $numbers
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row[mailing_no];
$message = "Dear Guardian, ". $row[name] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
I getting error upon submitting a post request using cURL. So far i have this code:
$login_url = 'http://192.168.1.1/login';
$postArr = array(
'username'=>'username',
'password'=>'password',
'dst' => base_url().'login/home'
);
$this->curlPost($login_url, $postArr);
function curlPost($url, $data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo 'using curl --- '.$url.'<br />';
var_dump($server_output);
}
Basically, this code should do POST username and password to specific url, but unfortunately it is returning "Error 501: Not Implemented" my server is wamp. Anyone have idea what is causing this issue? Thanks