您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 巴音郭楞蒙古分类信息网,免费分类信息发布

php微信开发01

2025/9/30 0:50:00发布22次查看
valid();$wechatobj->responsemsg();class wechatcallbackapitest{ public function valid() { $echostr = $_get[echostr]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { //get post data, may be due to the different environments $poststr = $globals[http_raw_post_data]; //extract post data if (!empty($poststr)){ /* libxml_disable_entity_loader is to prevent xml external entity injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $keyword = trim($postobj->content); $time = time(); $type=$postobj->msgtype; $customevent=$postobj->event; $latitude=$postobj->location_x; $l $texttpl = %s0; //发送位置回复 if($type==location){ $c $msgtype = text; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } //关键字回复 if(!empty( $keyword )) { $msgtype = text; if($keyword==1) { $contentstr = 感谢关注泛it!;} if($keyword==2) { $contentstr = 联系qq:,欢迎投稿以及提出宝贵意见;} if($keyword==3) { $contentstr = 你的图片不错,还是输入文字吧!;} $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }else{ echo input something...; } //关注公众号后回复 if($type=event and $customevent=subscribe){ $c $msgtype = text; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } //图片回复 if($type=image){ $c $msgtype = text; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }  
//switch语句优化
/* switch($type) { //处理文本 case text: //关键字回复 if(!empty( $keyword )) { //$msgtype = text; if($keyword==1) { $contentstr = 回复1查看使用说明\n回复2查看联系方式\n回复3使用翻译字典\n回复4使用机器人聊天功能;} if($keyword==2) { $contentstr = 联系qq:,欢迎投稿以及提出宝贵意见;} }else{ $c } break; //处理图片信息 case image: $c break; //处理位置信息 case location: $c break; //处理关注事件 case event: if($customevent==subscribe) {$c break; default: $c } $msgtype = text; $resultstr=sprintf($texttpl,$fromusername,$tousername,$time,$msgtype,$contentstr); echo $resultstr; */
}else { echo ; exit; }
}
private function checksignature()
{ // you must define token by yourself if (!defined(token)) { throw new exception('token is not defined!'); } $signature = $_get[signature]; $timestamp = $_get[timestamp]; $nonce = $_get[nonce]; $token = token;$tmparr = array($token, $timestamp, $nonce); // use sort_string rulesort($tmparr, sort_string);$tmpstr = implode( $tmparr );$tmpstr = sha1( $tmpstr );if( $tmpstr == $signature ){return true;}else{return false;}}}?>
以上就介绍了php微信开发01,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
巴音郭楞蒙古分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product