Home > php教程 > php手册 > body text

微信客服之qq消息提醒

WBOY
Release: 2016-06-06 19:34:02
Original
1143 people have browsed it

当用户有消息进入微信公众平台,让接口自动回复消息到客服QQ上,达到及时回复的目的 WeiXinSDK ?php/*******************************************发送QQ信息PHP接口 *******************************************/$sendQQ = new QQ('*******','***********')

当用户有消息进入微信公众平台,让接口自动回复消息到客服QQ上,达到及时回复的目的 WeiXinSDK
<?php

/*******************************************
发送QQ信息PHP接口 
*******************************************/

$sendQQ = new QQ('*******','***********');
$sid = $sendQQ->login();
$sendQQ->send('******','信息',$sid);




class QQ {
  public $id;
  public $password;
  public $error=array();
  public $ssid;
  private $cache;
  public function QQ($id,$password,$ssid=null){
    $this->id=$id;
    $this->password=$password;
    $ssid and file_put_contents($this->cache,$ssid);
  }
    
    
    
  public function login(){
    $r=QQ::ajax(
      'http://pt.3g.qq.com/psw3gqqLogin',
      array(
        qq=>$this->id,pwd=>$this->password,
        loginType=>1,i_p_w=>'qq|pwd|',
        toQQchat=>'true',bid_code=>'3GQQ',
        aid=>'nLoginHandle'
      )
    );
    if(preg_match('/成功[\s\S]+sid=([^&]+)/',$r,$m)){
      return $this->ssid=$m[1];
    }else{
      $this->error[]=$r;
      return false;
    };
  }
        
    
  public function send($qq,$message){
    $retry=3;
    while($retry--){
      $r=QQ::ajax(
        'http://q16.3g.qq.com/g/s?sid='.$this->ssid,
        array(
          msg=>$message,num=>$qq,'do'=>'send',u=>$qq,
          'saveURL'=>'0',aid=>'发送QQ消息',on=>1
        )
      );
      if(preg_match('/消息发送成功/',$r))return true;
      $this->error[]=$r;
      $this->login();
    };
    return false;
  }
    
    
    
  private static function ajax($url,$data=null){
    curl_setopt($c=curl_init($url),CURLOPT_RETURNTRANSFER,1);
    $data and $data=http_build_query($data)
          and curl_setopt($c,CURLOPT_POSTFIELDS,$data);
    $s=curl_exec($c);
    curl_close($c);
    return $s;
  }
};


?>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!