微信测试号接入--URL配置
来源:互联网 发布:衡水中学 知乎 编辑:程序博客网 时间:2024/06/05 11:02
一、准备工作
需要一个能提供外网访问的 url 地址
a. 获取方式:去阿里云、腾讯云、新浪云等等平台上购买一台虚拟主机。
b. 注意点:可能有的小伙伴用的是 花生壳动态内网穿透 所提供的外网域名。确实该域名是外网域名,但是该外网域名端口不是固定的 80(http) 或 443(https) 端口,所以配置会失败。
二、代码展示
配置失败的原因:很可能是编码问题,在代码最上层添加 utf-8 编码。
<?php/** * wechat php test *///如果配置失败,可能是编码问题,加上这一句header("Content-Type:text/plain;charset=utf-8");//define your tokendefine("TOKEN", "weixin");$wechatObj = new wechatCallbackapiTest();/** 该方法验证成功后,就不要调用了 */$wechatObj->valid();class wechatCallbackapiTest { /** * 验证 * @return [type] [description] */ public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()) { // ob_clean(); echo $echoStr; exit; } } /** * 响应消息 * @return [type] [description] */ 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(); $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>0</FuncFlag> </xml>"; if(!empty( $keyword )) { $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else { echo "Input something..."; } }else { echo ""; exit; } } /** * 校验签名 * @return [type] [description] */ 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 rule sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ) { return true; }else { return false; } }}
三、结果
阅读全文
0 0
- 微信测试号接入--URL配置
- 微信测试公众号 url配置失败的问题
- JAVA微信开发-测试号接入指南
- SYD8801微信接入测试结果
- H3 BPM微信企业号接入配置说明
- 微信公众号开发一(接入配置)
- (基于nodejs)微信测试号(接口配置信息)验证服务器的URL
- 微信公众号url配置失败
- 微信测试号开发之一 接入微信公众号
- 微信开发第一步(接入配置)
- 微信公众号接入
- 微信公众号接入
- 微信测试号的URL和Token原理
- 微信测试号:config:invalid url domain
- 微信蓝牙BLE接入调试指引 测试公众号篇
- 史上最强SpringBoot接入微信公众号(测试)整体流程
- 微信公众平台接口开发-接入验证测试
- 微信“公众平台测试账号”接口接入指南
- WdatePicker日期插件
- 2.2.15内置类与同步:实验2
- java 判断输入的是正数还是0还是负数(正数-10,负数+10)
- 若construct 2只如初见
- STL之Vector
- 微信测试号接入--URL配置
- spring-boot restful接口学习,postman工具
- STL之deque和其他容器
- 循环神经网络基础
- 2.2.14内置类与同步:实验1
- Windbg对过滤驱动DriverEntry函数下断点技巧
- 27. Remove Element
- STL之set
- CentoOS下搭建wordpress全流程