2015-05-27 14 views
10

मैंने एक बार एसएमएस वॉयस संदेश भेजने के लिए Google Voice से कनेक्ट करने के लिए PHP क्लास लाइब्रेरी का उपयोग किया था। कॉल कुछ इस तरह काम करेगा:Google वॉइस PHP OAuth 2.0

$gv = new GoogleVoice("GmailAccount", "GmailPassword"); 
$gv->sms("PhoneNumber", "TextMsg"); 

यह अभी हाल तक यह दोषरहित काम 2015/04/20 के रूप में गूगल ने गूगल खाते में प्रवेश के पुराने तरीकों का समर्थन बंद कर दिया। इसलिए मेरी लिपि ने 500 त्रुटि देने पर काम करना बंद कर दिया। Google का कहना है कि आपको प्रमाणीकृत करने के लिए OAuth 2.0 का उपयोग करना है, हालांकि मुझे Google Voice के साथ इसे पूरा करने के तरीके पर ऑनलाइन कोई उदाहरण नहीं मिला है। कोड नीचे है, मैंने यह नहीं लिखा है, कृपया मुझे बताएं कि Google की OAuth सिस्टम का उपयोग करने के लिए कोड को कैसे समायोजित किया जाए।

/* 
Version  0.2 
License  This code is released under the MIT Open Source License. Feel  free to do whatever you want with it. 
Author  [email protected], http://www.lostleon.com/ 
LastUpdate 05/28/2010 


Usage: 


*/ 

class GoogleVoice 
{ 
    public $username; 
    public $password; 
    public $status; 
    private $lastURL; 
    private $login_auth; 
    private $inboxURL = 'https://www.google.com/voice/m/'; 
    private $loginURL = 'https://www.google.com/accounts/ClientLogin'; 
    private $smsURL = 'https://www.google.com/voice/m/sendsms'; 

public function __construct($username, $password) 
{ 
    $this->username = $username; 
    $this->password = $password; 
} 

public function getLoginAuth() 
{ 
    $login_param = "accountType=GOOGLE&Email={$this->username}&Passwd={$this->password}&service=grandcentral&source=com.lostleon.GoogleVoiceTool"; 
    $ch = curl_init($this->loginURL); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    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"); 
    curl_setopt($ch, CURLOPT_REFERER, $this->lastURL); 
    curl_setopt($ch, CURLOPT_POST, "application/x-www-form-urlencoded"); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $login_param); 
    $html = curl_exec($ch); 
    $this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    curl_close($ch); 
    $this->login_auth = $this->match('/Auth=([A-z0-9_-]+)/', $html, 1); 
    return $this->login_auth; 
} 

public function get_rnr_se() 
{ 
    $this->getLoginAuth(); 
    $ch = curl_init($this->inboxURL); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $headers = array("Authorization: GoogleLogin auth=".$this->login_auth, 'User-Agent: 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'); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    $html = curl_exec($ch); 
    $this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    curl_close($ch); 
    $_rnr_se = $this->match('!<input.*?name="_rnr_se".*?value="(.*?)"!ms', $html, 1); 
    return $_rnr_se; 
} 

public function sms($to_phonenumber, $smstxt) 
{ 
    $_rnr_se = $this->get_rnr_se(); 
    $sms_param = "id=&c=&number=".urlencode($to_phonenumber)."&smstext=".urlencode($smstxt)."&_rnr_se=".urlencode($_rnr_se); 
    $ch = curl_init($this->smsURL); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $headers = array("Authorization: GoogleLogin auth=".$this->login_auth, 'User-Agent: 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'); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_REFERER, $this->lastURL); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $sms_param);  
    $this->status = curl_exec($ch); 
    $this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    curl_close($ch); 
    return $this->status; 
} 

private function match($regex, $str, $out_ary = 0) 
{ 
    return preg_match($regex, $str, $match) == 1 ? $match[$out_ary] : false; 
} 
} 
+0

Oauth2 पर स्विच करें, लॉगिन और पासवर्ड सामान हटाएं। – DaImTo

+0

Oauth2 पर जाने के समान सरल नहीं दिखता है। Googlevoice के लिए एपीआई नहीं ढूंढ सकता (ओथ 2 का उपयोग करते समय "स्कोप" चर द्वारा आवश्यक)। अतिरिक्त सलाह का स्वागत है –

उत्तर

5

मैं अगले जवाब देने के लिए आप भेज देंगे: https://stackoverflow.com/a/4131915/2992810

दुर्भाग्यपूर्ण गूगल आवाज उनके एपीआई बदल गया था तो आप इसे अब और उपयोग नहीं कर सकते। https://github.com/aaronpk/Google-Voice-PHP-API (सिर में टिप्पणियों को देखें)

Google Voice एक खुला एपीआई नहीं है, इसलिए वे इसे बनाए रखने नहीं हैं। आपको बताने के लिए खेद है लेकिन मेरे अपने अनुभव में आज एसएमएस सेवाएं इतनी सस्ती हैं कि Google और उनके निरंतर एपीआई परिवर्तनों के मुकाबले वास्तव में सेवा लाइसेंस खरीदने के लिए आपको कम लागत आएगी, आपकी वेबसाइट हमेशा इस तरह के बदलाव के कारण नीचे जा सकती है। संसाधन के रूप में आपके समय के बारे में सोचता है, अपना समय खर्च करने से आपको और अधिक खर्च आएगा!

0

GV4J एक जावा लाइब्रेरी है जो Google Voice में लॉगिन करने में सक्षम है, इसलिए यह आपके PHP कोड को प्रमाणीकृत करने में सक्षम होने के लिए एक अच्छा संदर्भ हो सकता है।

संबंधित मुद्दे