Kirim SMS Melalui Google Voice Dengan PHP

Google voice memang belum resmi dirilis oleh Google, tapi undangan-undangan telah dikirim kepada akun-akun terpilih. Bagi yang ingin menerima undangan silahkan daftar di Google Voice.

Salah satu keuntungan menggunakan aplikasi tersebut adalah mempermudah pengembang website untuk mengirim sms ke setiap pengguna Google voice.

langkah pertama dengan copy-paste kode di bawah ini ke dalam file baru yang diberi nama “class.googlevoice.php”

01 <?php
02 /*
03 License        This code is released under the MIT Open Source License. Feel free to do whatever you want with it.
04 Author        lostleon [at] gmail [dot] com, http://www.lostleon.com/
05 */
06 class GoogleVoice
07 {
08 public $username;
09 public $password;
10 public $status;
11 private $lastURL;
12 private $login_auth;
13 private $inboxURL = 'https://www.google.com/voice/m/';
14 private $loginURL = 'https://www.google.com/accounts/ClientLogin';
15 private $smsURL = 'https://www.google.com/voice/m/sendsms';
16
17 public function __construct($username, $password)
18 {
19 $this->username = $username;
20 $this->password = $password;
21 }
22
23 public function getLoginAuth()
24 {
25 $login_param = "accountType=GOOGLE&Email={$this->username}&Passwd={$this->password}&service=grandcentral&source=lostleonATgmailDOTcom-GoogleVoiceTool";
26 $login_output = $this->curl($this->loginURL, $this->lastURL, $login_param);
27 $this->login_auth = $this->match('/Auth=([A-z0-9_-]+)/', $login_output, 1);
28 return $this->login_auth;
29 }
30
31 public function get_rnr_se()
32 {
33 $auth_param = "?auth=".$this->getLoginAuth();
34 $inbox_output = $this->curl($this->inboxURL.$auth_param, $this->lastURL);
35 $_rnr_se = $this->match('!<input.*?name="_rnr_se".*?value="(.*?)"!ms', $inbox_output, 1);
36 return $_rnr_se;
37 }
38
39 public function sms($to_phonenumber, $smstxt)
40 {
41 $_rnr_se = $this->get_rnr_se();
42 $sms_param = "id=&c=&number=".urlencode($to_phonenumber)."&smstext=".urlencode($smstxt)."&_rnr_se=".urlencode($_rnr_se);
43 $posturl = $this->smsURL."?auth=".$this->login_auth;
44 $sms_output = $this->curl($posturl, $this->lastURL, $sms_param);
45 $this->status = $sms_output;
46 return $sms_output;
47 }
48
49 private function curl($url, $referer = null, $post_param = null)
50 {
51 $ch = curl_init($url);
52 curl_setopt($ch, CURLOPT_HEADER, 0);
53 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
54 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
55 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20");
56
57 if($referer)
58 curl_setopt($ch, CURLOPT_REFERER, $referer);
59
60 if(!is_null($post_param))
61 {
62 curl_setopt($ch, CURLOPT_POST, true);
63 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);
64 }
65
66 $html = curl_exec($ch);
67 $this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
68 curl_close($ch);
69 return $html;
70 }
71
72 private function match($regex, $str, $out_ary = 0)
73 {
74 return preg_match($regex, $str, $match) == 1 ? $match[$out_ary] : false;
75 }
76
77 }
78
79 ?>

setelah itu buat file baru dan beri nama “sendsms.php” dan copy-paste kode di bawah ini.

1 <?php
2 include 'class.googlevoice.php';
3 $gv=new GoogleVoice('username','password');
4 $gv->sms('toPhoneNumber','message');

Masukan username dan password sesuai login pada Google Voice. dan tulis nomer telepon penerima dan pesan yang akan dikirim.

Selamat mencoba…

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s