1<?php
2ini_set('display_errors', 1);
3ini_set('display_startup_errors', 1);
4error_reporting(E_ALL);
5$host = 'http://google.com';
6$message = 'Test message';
7$phone = '998999999';
8$username = 'username';
9$password = 'password';
10$post = [
11 "messages" => [
12 [
13 "recipient" => $phone,
14 "message-id" => "itrust" . strval(time()),
15
16 "sms" => [
17 "originator" => "3700",
18 "content" => [
19 "text" => $message
20 ]
21 ]
22 ]
23 ]
24];
25$payloadName = json_encode($post);
26
27$ch = curl_init($host);
28curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
29curl_setopt($ch, CURLOPT_HEADER, 1);
30curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
31curl_setopt($ch, CURLOPT_TIMEOUT, 30);
32curl_setopt($ch, CURLOPT_POST, 1);
33curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadName);
34curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
35$return = curl_exec($ch);
36curl_close($ch);
37
38echo '<pre>';
39var_dump($return);
40echo '</pre>';
41
1<?php
2define('OAUTH_TOKEN_URL','https://api.example.com/oauth/token'); // replace with according to documentation
3$url ='' ; // your redirect url
4$client_id = ''; // your client id from api
5$client_secret = ''; /your client secret from api
6// if api require client id and client secret in paramters then below other wise
7$data = "grant_type=authorization_code&code=".$_GET['code']."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$url;
8
9$headers = array(
10 'Content-Type:application/x-www-form-urlencoded',
11);
12
13// if api requires base64 and into -H header than
14
15//$data = "grant_type=authorization_code&code=".$_GET['code']."&redirect_uri=".$url;
16//$base64 = base64_encode($client_id.":".$client_secret);
17
18//$headers = array(
19 // 'Content-Type:application/x-www-form-urlencoded',
20 // 'Content-Type:application/json',
21 // 'Authorization: Basic '. $base64
22// );
23
24$response = curlPost($data,$headers);
25print_r($response);
26
27function curlPost($data,$headers){
28
29 $ch = curl_init();
30 curl_setopt($ch, CURLOPT_URL,OAUTH_TOKEN_URL);
31 curl_setopt($ch, CURLOPT_POST, 1);
32 curl_setopt($ch, CURLOPT_POSTFIELDS,$data); //Post Fields
33 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34
35
36
37 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
38
39 $server_output = curl_exec ($ch);
40
41 return $server_output;
42 curl_close ($ch);
43
44}