-
Notifications
You must be signed in to change notification settings - Fork 0
/
ripple.php
138 lines (105 loc) · 3.73 KB
/
ripple.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
require 'twilio/Services/Twilio.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;
*/
$account_sid = "AC3b92f303b5fbff35d8a2183ad8b19c61"; // Your Twilio account sid
$auth_token = "c76b91115d49d7485ef62078870b2ee4"; // Your Twilio auth token
$client = new Services_Twilio($account_sid, $auth_token);
$secretkey="sn3nxiW7v8KXzPzAqzyHXbSSKNuN9";
$amount=1;
$issueraddress="rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn";
$dstaddress="rNAZFtFfeKofrA4JeDMjnrmMkRpN5NstuE"; //Mbale GBP
$srcaddress="rNAZFtFfeKofrA4JeDMjnrmMkRpN5NstuE";//Lawrence ZMK
$trans=get("https://api.ripple.com/v1/accounts/$dstaddress/payments?direction=incoming&exclude_failed=true");
$out=json_decode($trans,true);
print_r($out);
$hashold=$out["payments"][0]["hash"];
echo $hashold;
/** testing twilio **/
$phonetest=+447973212148;
//var_dump($client->account->sms_messages);
/**
$message = $client->account->sms_messages->create(
'+441246488197', // From a Twilio number in your account
$phonetest, // Text any number
"Congratulations You have received 1 million Kwacha !"
);
print $message->sid;
**/
echo "WAITING TRANSACTIONS... on ".$dstaddress;
while(1){
/*if (isset($out["payments"][0]["hash"])){
if (isset($out["payments"][0]["destination_amount"]["value"])){
if (isset($out["payments"][0]["memos"][0]["MemoData"])){
*/
$hash=$out["payments"][0]["hash"];
$value=$out["payments"][0]["destination_amount"]["value"];
$phone=$out["payments"][0]["memos"][0]["MemoData"];
if ($hash!=$hashold){
echo "NEW PAYMENT RECEIVED ";
$message = $client->account->sms_messages->create(
'+441246488197', // From a Twilio number in your account
$phonetest, // Text any number
"Congratulations You have received $value ruppees !"
);
print $message->sid;
$hashold=$hash;
}
/*
}
}
}
*/
sleep (5);
$trans=get("https://api.ripple.com/v1/accounts/$dstaddress/payments?direction=incoming&exclude_failed=true");
$out=json_decode($trans,true);
}
?>