您好,欢迎访问一九零五行业门户网

PHP 微信接口封装类(PHP100)

weixin_run(); //执行接收器方法
class wechatcallbackapitest
{
   private $fromusername;
   private $tousername;
   private $times;
   private $keyword;
public function weixin_run(){
     $this->responsemsg();
$arr[]=array(创恩很靠谱,php100也不错!,aa,http://www.chuangen.com/pic/hj/s_4.png,http://www.chuangen.com);
$arr[]=array(创恩很靠谱,php100也不错!,aa,http://www.chuangen.com/pic/hj/s_4.png,http://www.chuangen.com);
$arr[]=array(创恩很靠谱,php100也不错!,aa,http://www.chuangen.com/pic/hj/s_4.png,http://www.chuangen.com);
$this->fun_xml(news,$arr,array(2,0)); 
   }
function t($n){
   include(t_api.php);
   $c_name=$t_api[$n];
   $json=file_get_contents(http://m.weather.com.cn/data/101110310.html);
   return json_decode($json);
  }
public function valid()
    {
        $echostr = $_get[echostr];
//valid signature , option
        if($this->checksignature()){
        echo $echostr;
        exit;
        }
    }
public function responsemsg()
    {
$poststr = $globals[http_raw_post_data];
if (!empty($poststr)){
              $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata);
                $this->fromusername = $postobj->fromusername;
                $this->tousername = $postobj->tousername;
                $this->keyword = trim($postobj->content);
$this->times = time();
        }else {
        echo this a file for weixin api!;
        exit;
        }
    }
//微信封装类,
//type: text 文本类型, news 图文类型
//text,array(内容),array(id)
//news,array(array(标题,介绍,图片,超链接),...小于10条),array(条数,id)
private function fun_xml($type,$value_arr,$o_arr=array(0)){
 //=================xml header============
 $con=
fromusername}]]>
tousername}]]>
{$this->times}
;
//=================type content============
 switch($type){
case text : 
 $con.=
{$o_arr};  
break;
case news : 
 $con.={$o_arr[0]}
;
foreach($value_arr as $id=>$v){
if($id>=$o_arr[0]) break; else null; //判断数组数不超过设置数
         $con.=
;
}
$con.=
{$o_arr[1]};  
break;
} //end switch
//=================end return============
 echo $con.;
}
private function checksignature()
{
        $signature = $_get[signature];
        $timestamp = $_get[timestamp];
        $nonce = $_get[nonce];
$token = token;
$tmparr = array($token, $timestamp, $nonce);
sort($tmparr);
$tmpstr = implode( $tmparr );
$tmpstr = sha1( $tmpstr );
if( $tmpstr == $signature ){
return true;
}else{
return false;
}
}
}
?>
其它类似信息

推荐信息