php对接微信公众平台消息接口开发流程教程剖析

上传人:今*** 文档编号:105868173 上传时间:2019-10-13 格式:DOC 页数:7 大小:50.50KB
返回 下载 相关 举报
php对接微信公众平台消息接口开发流程教程剖析_第1页
第1页 / 共7页
php对接微信公众平台消息接口开发流程教程剖析_第2页
第2页 / 共7页
php对接微信公众平台消息接口开发流程教程剖析_第3页
第3页 / 共7页
php对接微信公众平台消息接口开发流程教程剖析_第4页
第4页 / 共7页
php对接微信公众平台消息接口开发流程教程剖析_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《php对接微信公众平台消息接口开发流程教程剖析》由会员分享,可在线阅读,更多相关《php对接微信公众平台消息接口开发流程教程剖析(7页珍藏版)》请在金锄头文库上搜索。

1、PHP对接微信公众平台消息接口开发流程教程这篇文章主要介绍了PHP对接微信公众平台消息接口开发流程,如何使用PHP版接口操作公众平台消息,需要的朋友可以参考下一、写好接口程序 在你的服务器上上传好一个接口程序文件,如http:/ 内容如下: 复制代码 代码如下:valid();/$wechatObj-responseMsg();class wechatCallbackapiTest public function valid() $echoStr = $_GETechostr; if($this-checkSignature() echo $echoStr; exit; public func

2、tion responseMsg() $postStr = $GLOBALSHTTP_RAW_POST_DATA; if (!empty($postStr) $postObj = simplexml_load_string($postStr, SimpleXMLElement, LIBXML_NOCDATA); $fromUsername = $postObj-FromUserName; $toUsername = $postObj-ToUserName; $keyword = trim($postObj-Content); $time = time(); $textTpl = %s 0 ;

3、if(!empty( $keyword ) $msgType = text; $contentStr = 你好啊,屌丝; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; else echo 咋不说哈呢; else echo 咋不说哈呢; exit; private function checkSignature() $signature = $_GETsignature; $timestamp = $_GETtimestamp;

4、$nonce = $_GETnonce; $token =TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr = $signature ) return true; else return false; ? 二、配置微信公众平台回复接口 设置回复接口,填好URL和Token(url填上面的http:/ 三、验证接口 用自己的个人微信关注下你的公众账号,给这个账号发一条消息过去,

5、收到原样的消息返回,即验证成功了。 四、开始自定义回复 注释掉$wechatObj-valid(); 这行,同时去掉/$wechatObj-responseMsg();这行的注释。你可以修改responseMsg函数里面的代码,根据用户的消息类型(text,image,location)和消息内容来回复用户不同的内容。消息接口就可以使用了,发个消息试试看吧? 1.封装weixin.class.php 由于微信公众平台的通信使用的是特定格式的XML数据,每次接受和回复都要去做一大堆的数据处理。我们就考虑在这个基础上做一次封装,weixin.class.php,代码如下:复制代码 代码如下:tok

6、en = $token; $this-debug = $debug; /获得用户发过来的消息(消息内容和消息类型 ) public function getMsg() $postStr = $GLOBALSHTTP_RAW_POST_DATA; if ($this-debug) $this-write_log($postStr); if (!empty($postStr) $this-msg = (array)simplexml_load_string($postStr, SimpleXMLElement, LIBXML_NOCDATA); $this-msgtype = strtolower

7、($this-msgMsgType); /回复文本消息 public function makeText($text=) $CreateTime = time(); $FuncFlag = $this-setFlag ? 1 : 0; $textTpl = msgFromUserName msgToUserName $CreateTime %s ; return sprintf($textTpl,$text,$FuncFlag); /根据数组参数回复图文消息 public function makeNews($newsData=array() $CreateTime = time(); $FuncFlag = $this-setFlag ? 1 : 0; $newTplHeader = msgFromUserName msgToUserName $CreateTime %s; $newTplItem = ; $newTplFoot = %s ; $Content =

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号