php curl 腾讯api发微博实例

2013年08月05日 12:11 by:老修

我很反对重复劳动,腾讯官方的SDK看着实在是有点头疼,自己动手丰衣足食,基于腾讯API-OAuth2.0协议php curl 发微博的function:

  1. function postData($access_token,$appid,$openid,$content){//发腾讯微博
  2. $data = array( 
  3. 'access_token'=>$access_token,
  4. 'oauth_consumer_key'=>$appid,
  5. 'openid'=>$openid,
  6. 'format'=>'json',
  7. 'content'=>$content
  8. );
  9. $ch = curl_init();
  10. $timeout = 100;
  11. curl_setopt($ch, CURLOPT_URL, 'https://graph.qq.com/t/add_t');//腾讯博客提交接口
  12. curl_setopt($ch, CURLOPT_REFERER, "http://www.alens.org/");//来路
  13. curl_setopt($ch, CURLOPT_POST, true);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  16. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
  17. $handles = curl_exec($ch); 
  18. curl_close($ch); 
  19. return $handles; 
  20. }

调用方法:

  1. $json_data = postData($access_token,$appid,$openid,$content);
  2. $array = json_decode($json_data,true);
  3. echo '<pre>';print_r($array);

最后编辑时间:0000-00-00 00:00:00