gemliu 发表于 2015-07-02 11:04

微信客服之qq消息提醒

当用户有消息进入微信公众平台,让接口自动回复消息到客服QQ上,达到及时回复的目的
QQ推送消息部分<?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;
    }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;
}
};


?>

renxiao2003 发表于 2015-07-10 10:09

能自动泡妞更好啊。
页: [1]
查看完整版本: 微信客服之qq消息提醒