代码如下,测试过可行~ 中文会被忽略,不能纯中文

<?PHP
/*
Google Voice Api
License  :部分代码来自http://www.lostleon.com 增加了错误提示,返回信息,群发,中文转拼音  所需PHP扩展:curl
Author:threesky@gmail.com, http://www.heqee.com/
*/
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=lostleonATgmailDOTcom-GoogleVoiceTool";
    $login_output = $this->curl($this->loginURL, $this->lastURL, $login_param);
    $this->login_auth = $this->match('/Auth=([A-z0-9_-]+)/', $login_output, 1);
    return $this->login_auth;
  }

  public function get_rnr_se()
  {
    $auth_param = "?auth=".$this->getLoginAuth();
    $inbox_output = $this->curl($this->inboxURL.$auth_param, $this->lastURL);
    $_rnr_se = $this->match('!<input.*?name="_rnr_se".*?value="(.*?)"!ms', $inbox_output, 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);
    $posturl = $this->smsURL."?auth=".$this->login_auth;
    $sms_output = $this->curl($posturl, $this->lastURL, $sms_param);
    $this->status = $sms_output;
    return $sms_output;
  }

  private function curl($url, $referer = null, $post_param = null)
  {
    $ch = curl_init($url);
    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");

    if($referer)
        curl_setopt($ch, CURLOPT_REFERER, $referer);

    if(!is_null($post_param))
    {
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);
    }

    $html = curl_exec($ch);
    $this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    return $html;
  }

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

}

$voiceApi = new GoogleVoice('cevin1991@gmail.com','*******');
echo $voiceApi->sms('8615022604794','testsadfasfasfa');


参考阅读:

1 数据源见前面说明
2 另外可以参考更多内容:
http://posttopic.com/topic/google-voice-add-on-development
3 参考openID:http://code.google.com/intl/zh-CN/apis/accounts/docs/OpenID.html


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
Tags: , , , ,
玉奇分享 Homepage Email
2010/05/12 14:48
呵呵,这个代码不错,拿来研究一下!
分页: 1/1 第一页 1 最后页
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐