예제 #1
0
 // GET variables: timestamp, nonce, msg_signature, encrypt_type
 extract($_GET);
 if (isset($echostr)) {
     // for wechat API validation
     if ($wechat->validateAPI($echostr, $signature, $timestamp, $nonce)) {
         die($echostr);
     } else {
         throw new Exception('API validate failed');
     }
 }
 // get POST data, request message from WeChat
 $raw_data = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : '';
 if (!empty($raw_data)) {
     # decrypt message
     $dataArr = array('raw_data' => $raw_data, 'encrypt_type' => isset($encrypt_type) && $encrypt_type == 'aes' ? "aes" : "raw", 'msg_signature' => $msg_signature, 'timestamp' => $timestamp, 'nonce' => $nonce);
     $result = $wechat->decryptMessage($dataArr);
     if ($result['hasError']) {
         // decryption failed
         die;
     }
     $postArr = $result['postArr'];
     $encrypt_array = array('encrypt_type' => $encrypt_type, 'responseXML' => '', 'timestamp' => $timestamp, 'nonce' => $nonce);
     if ($postArr['MsgType'] == $wechat::MSGTYPE_EVENT && $postArr['Event'] == $wechat::EVENT_SEND_MASS) {
         include_once '../snippet/process_massSend.php';
         die;
     }
     switch ($postArr['MsgType']) {
         case $wechat::MSGTYPE_TEXT:
             include_once '../snippet/process_keyword.php';
             include_once '../snippet/process_text.php';
             include_once '../snippet/response_keyword.php';