-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwilio.php
92 lines (69 loc) · 2.36 KB
/
twilio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
function get($uri)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === FALSE) {
$error = curl_error($ch);
}
curl_close($ch);
if (isset($error)) {
die(": $error ($uri)");
}
return $response;
}
/**
* Perform a HTTP GET request.
* @param string $uri Request URI.
* @param mixed $body Request body (JSON string / PHP array).
* @return string Response body as JSON string.
* @throws RippleRestProtocolError if client returns non-200 responses or network problems.
*/
function post($uri, $body)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_string($body) ? $body : json_encode($body));
$response = curl_exec($ch);
if ($response === FALSE) {
$error = curl_error($ch);
}
curl_close($ch);
if (isset($error)) {
die("CURL: $error ($uri)");
}
return $response;
}
$msg=$_POST["Body"];
list($phone,$amount)=split(' ', $msg);
echo 'Msg received: ' . $msg;
echo 'Phone: ' . $phone;
echo 'amount:' . $amount;
$secretkey="sn3nxiW7v8KXzPzAqzyHXbSSKNuN9";
$amount=1;
$issueraddress="rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn";
$srcaddress="rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn";
$dstaddress="ra5nK24KXen9AHvsdFTKHSANinZseWnPcX";
$id=get("https://api.ripple.com/v1/uuid");
$id=json_decode($id,true);
echo $id['uuid'];
$prepare=get("https://api.ripple.com/v1/accounts/$srcaddress/payments/paths/$dstaddress/$amount+USD+$issueraddress?source_currencies=USD");
$id2=json_decode($prepare,true);
print_r($id2);
$paymentdata=$id2["payments"][0];
$data=array(
"secret"=>$secretkey,
"client_resource_id"=>$id['uuid'],
"payment"=>$paymentdata
);
$out=post("https://api.ripple.com/v1/accounts/$srcaddress/payments?",$data);
print_r($out);
?>