请教一个问题:假设我现在已经申请号了认证订阅号,然后我也启用了服务器配置并且url验证通过了。但是我尝试用自己的微信关注这个订阅号,并且发送消息。理论上微信服务器应该会向url发送用户的信息,包括openid什么的。但是实际上我的url里面并没有接收到任何信息。不知道是否有开发过的大侠指点一下?
我的url内的代码:
traceHttp();define("TOKEN", "4321");$access_token = '1234';$wechatObj = new wechatCallbackapiTest();if (isset($_GET['echostr'])) { $wechatObj->valid();}else{ $wechatObj->responseMsg();}class wechatCallbackapiTest{ public function valid() { $echoStr = $_GET["echostr"]; if($this->checkSignature()){ echo $echoStr; exit; } } 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; } } public function responseMsg() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; ob_start(); var_dump($_REQUEST); $a = ob_get_clean(); file_put_contents('1.xml', $a, FILE_APPEND); if (!empty($postStr)){ $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($keyword == "?" || $keyword == "?") { $msgType = "text"; $contentStr = date("Y-m-d H:i:s",time()); $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);// echo $resultStr; file_put_contents('1.xml', $resultStr, FILE_APPEND); } }else{ echo ""; exit; } }}function traceHttp(){ logger("\n\nREMOTE_ADDR:".$_SERVER["REMOTE_ADDR"].(strstr($_SERVER["REMOTE_ADDR"],'101.226')? " FROM WeiXin": "Unknown IP")); logger("QUERY_STRING:".$_SERVER["QUERY_STRING"]);}function logger($log_content){ if(isset($_SERVER['HTTP_APPNAME'])){ //SAE sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); }else{ //LOCAL $max_size = 500000; $log_filename = "log.xml"; if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);} file_put_contents($log_filename, date('Y-m-d H:i:s').' '.$log_content."\r\n", FILE_APPEND); }}
每次我向订阅号发消息后,1.xml确实会有新内容被记录,但只有这些:
array(3) { ["signature"]=> string(40) "2c1f15c808659e38ca8a2bef53068939c7710d09" ["timestamp"]=> string(10) "1423321593" ["nonce"]=> string(10) "1992378621"}
百思不得其解。
回复讨论(解决方案)
http://blog.csdn.net/fuyifang/article/details/40707517
这篇文章我已经看过了,按照文章所说,当我向订阅号发送消息的时候,微信服务器会向订阅号填写的服务器url发送xml格式数据,里面就有用户的openid。问题就是我服务器url这边是接收到微信服务器的发送数据,可是数据里面没有xml格式的数据啊,也没有openid。
腾 讯 微信开发 有技术咨询吧? 程序规则他们定制的 最好问下他们
检查下你服务器配置的消息加解密方式,看是否是明文的
你的代码是什么样程序就会表现什么样
注释掉下面几句:
ob_start();
var_dump($_REQUEST);
$a = ob_get_clean();
file_put_contents('1.xml', $a, FILE_APPEND);
然后向你的公众号发送问号(?)试试
问题已经解决了,就是5楼说的问题。不能用
ob_start();
var_dump($_REQUEST);
$a = ob_get_clean();

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
