微信 php 类,PHP 微信接口封装类_PHP教程

weixin_run(); //执行接收器方法

class wechatCallbackapiTest

{

private $fromUsername;

private $toUsername;

private $times;

private $keyword;

public function weixin_run(){

$this->responseMsg();

$arr[]=array(“很靠谱,不错!”,”aa”,”http://www.chuangen.com/pic/hj/s_4.png”,”http://www.baidu.com”);

$arr[]=array(“很靠谱,不错!”,”aa”,”http://www.chuangen.com/pic/hj/s_4.png”,”http://www.baidu.com”);

$arr[]=array(“很靠谱,不错!”,”aa”,”http://www.chuangen.com/pic/hj/s_4.png”,”http://www.baidu.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=”

{$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;

}

}

}

?>

www.bkjia.comtrueTechArticle?php/** * 微信公众平台接口PHP100封装功能类文件 * author * date 2013-4-9 PRC:E+8 23:03 */define(TOKEN, chuangenit);$wechatObj = new wechatCallbackapiTest();$wechatObj-…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值