模拟微信公众号回调请求

1 有时候我们需要调试线上公众号,微信公众号请求我们的接口回调之后,输出的内容到底是什么?有没有报错信息?xml是否是对的?我们可以模拟微信公众号的回调请求。代码如下。

  '.$time.'     ';

$header[]="Content-Type: text/xml; charset=utf-8";
$header[]="User-Agent: Apache/1.3.26 (Unix)";
$header[]="Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
$header[]="Connection: keep-alive";
$header[]="Content-Length: ".strlen($xml);
$ch = curl_init();
$url = 'http://openpf.xxxx.com/wx/gate4space?signature=db5025bc3f75bcb4f16dacc8bb3f5480fc504c5d×tamp='.$time.'&nonce=623483653&openid=oz_WAjnyPnPFE1VnSSDgQby2V1fY';

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res = curl_exec($ch);

//$request_header = curl_getinfo( $ch, CURLINFO_HEADER_OUT);
//print_r($request_header);

//$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
// 根据头大小去获取头信息内容
//$header = substr($sContent, 0, $headerSize);

curl_close($ch);
header('Content-Type:text/xml; charset=utf-8');
echo ($res);

$url = 'http://openpf.xxxx.com/wx/gate4space?signature=db5025bc3f75bcb4f16dacc8bb3f5480fc504c5d×tamp='.$time.'&nonce=623483653&openid=oz_WAjnyPnPFE1VnSSDgQby2V1fY'; 是公众号后台配置的:服务器地址(URL)。

效果如下:

模拟微信公众号回调请求_第1张图片



你可能感兴趣的:(PHP程序员技术精粹)