123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- include_once "php/wxBizMsgCrypt.php";
- $encodingAesKey = "53o42sbbzslie4tjbll3ta5zlwe11rrk53o42sbbzsl";
- $token = "eqcxcx";
- $appId = "wxd6972323f37bfdf0";
- //traceHttp();
- logger('timestamp:'.$_REQUEST['timestamp']);
- logger('msg_signature:'.$_REQUEST['msg_signature']);
- $msg_sign=$_REQUEST['msg_signature'];
- $timeStamp=$_REQUEST['timestamp'];
- $nonce=$_REQUEST['nonce'];
- logger('signature:'.$_REQUEST['signature']);
- logger('nonce:'.$_REQUEST['nonce']);
- echo "success";
- // $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //获取数据
- // $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- // logger($postObj);
- //exit;
- $encryptMsg = file_get_contents('php://input');
- logger($encryptMsg);
- $xml_tree = new DOMDocument();
- $xml_tree->loadXML($encryptMsg);
- $array_e = $xml_tree->getElementsByTagName('Encrypt');
- //$array_s = $xml_tree->getElementsByTagName('MsgSignature');
- $encrypt = $array_e->item(0)->nodeValue;
- logger($encrypt);
- $msg_sign = $array_s->item(0)->nodeValue;
- //logger($msg_sign);
- $format = "<xml><AppId><![CDATA[toUser]]></AppId><Encrypt><![CDATA[%s]]></Encrypt></xml>";
- $from_xml = sprintf($format, $encrypt);
-
- // 第三方收到公众号平台发送的消息
- $msg = '';
- $errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $encryptMsg, $msg);
- if ($errCode == 0) {
- logger("解密后: " . $msg . "\n");
- } else {
- logger($errCode . "\n");
- }
-
-
-
- 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_wx.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);
- }
- }
- ?>
|