Ejemplo n.º 1
0
 public static function Forward($url)
 {
     if (strpos($url, '?')) {
         $url .= '&';
     } else {
         $url .= '?';
     }
     foreach (self::$GET_FIELDS as $f) {
         if (isset($_GET[$f])) {
             $url .= $f . '=' . urlencode($_GET[$f]) . '&';
         }
     }
     $post = spWxTransport::Input();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type' => $_SERVER['HTTP_CONTENT_TYPE']]);
     $s = curl_exec($ch);
     $i = curl_getinfo($ch);
     curl_close($ch);
     spWxLogger::Log('spWxRequestForwarder', ['url' => $url, 'data' => $post, 'result' => $s, 'info' => $i]);
     return $s;
 }
Ejemplo n.º 2
0
 /**
  * 消息API
  *
  */
 public static function MessageAPI()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         if (isset($_GET['echostr'])) {
             # ping/pong
             return self::ProcessRequest(self::REQUEST_VALIDATE, new spWxRequestValidationObject(array('echostr' => $_GET['echostr'])));
         }
     } else {
         $input = spWxTransport::Input();
         $postObj = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA);
         $message = array();
         $message['from_username'] = (string) $postObj->FromUserName;
         $message['to_username'] = (string) $postObj->ToUserName;
         $message['create_time'] = (int) $postObj->CreateTime;
         $message['msg_id'] = (int) $postObj->MsgId;
         $message['msg_type'] = (string) $postObj->MsgType;
         switch ($message['msg_type']) {
             case self::REQUEST_TEXT:
                 # 文本类型消息
                 $message['content'] = (string) $postObj->Content;
                 $object = new spWxRequestTextObject($message);
                 break;
             case self::REQUEST_IMAGE:
                 # 图片类型消息
                 $message['pic_url'] = (string) $postObj->PicUrl;
                 $message['media_id'] = (string) $postObj->MediaId;
                 $object = new spWxRequestImageObject($message);
                 break;
             case self::REQUEST_LOCATION:
                 # 地理位置类型消息
                 $message += array('latitude' => (string) $postObj->Location_X, 'longitude' => (string) $postObj->Location_Y, 'scale' => (int) $postObj->Scale, 'label' => (string) $postObj->Label);
                 $object = new spWxRequestLocationObject($message);
                 break;
             case self::REQUEST_URL:
                 # 链接消息(old)
             # 链接消息(old)
             case self::REQUEST_LINK:
                 # 链接消息
                 $message += array('title' => (string) $postObj->Title, 'description' => (string) $postObj->Description, 'url' => (string) $postObj->Url);
                 $object = new spWxRequestLinkObject($message);
                 break;
             case self::REQUEST_EVENT:
                 # 事件消息
                 $message += array('event' => (string) $postObj->Event, 'event_key' => (string) $postObj->EventKey);
                 $object = new spWxRequestEventObject($message);
                 break;
             case self::REQUEST_VOICE:
                 # 语音消息
                 $message += array('media_id' => (string) $postObj->MediaId, 'format' => (string) $postObj->Format, 'recognition' => (string) $postObj->Recognition);
                 $object = new spWxRequestVoiceObject($message);
                 break;
             case self::REQUEST_VIDEO:
                 # 视频
             # 视频
             case self::REQUEST_SHORTVIDEO:
                 # 短视频
                 $message += array('media_id' => (string) $postObj->MediaId, 'thumb_media_id' => (string) $postObj->ThumbMediaId);
                 $object = new spWxRequestVideoObject($message);
                 break;
             default:
                 throw new spWxException('Invalid Message Type');
         }
         return self::ProcessRequest($message['msg_type'], $object);
     }
     return 0;
 }