function httprequest($url, $data = array(), $abort = false) { if (!function_exists('curl_init')) { return empty($data) ? doget($url) : dopost($url, $data); } $timeout = $abort ? 1 : 2; $ch = curl_init(); if (is_array($data) && $data) { $formdata = http_build_query($data); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $result = curl_exec($ch); return false === $result && false == $abort ? empty($data) ? doget($url) : dopost($url, $data) : $result; }
$token = localToken(); LogUtil::logs(time() . " index.php =====> " . $token, $logFile); $echostr = $_GET["echostr"]; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; LogUtil::logs(time() . " index.php =====> " . $echostr, $logFile); if (!empty($_GET) && checkSignature($signature, $timestamp, $nonce)) { if ($echostr) { echo $echostr; exit; } } $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { dopost($postStr); } else { echo ""; } function dopost($postXml) { $postArray = xml2array($postXml); $postData = $postArray['xml']; error_log('token验证:' . print_R($postData, true), 3, dirname(__FILE__) . '/pay.log'); switch ($postData['MsgType']) { case 'event': $paramsData['Content'] = '欢迎访问WEB人生百科'; $paramsData['MsgType'] = 'text'; send_msg($postData, $paramsData); break; default: