コード例 #1
0
ファイル: Robot.php プロジェクト: WJayWJay/phalapi-library
 /**
  * 按类型分发消息给子类执行响应
  * @return Wechat_OutMessage实例
  */
 public function run()
 {
     // 未通过消息真假性验证
     if (!$this->debug && (!$this->isValid() || !$this->validateSignature($token))) {
         throw new PhalApi_Exception_BadRequest(T('wrong token'));
     }
     $inMessage = new Wechat_InMessage();
     $outMessage = null;
     switch ($inMessage->getMsgType()) {
         case Wechat_InMessage::MSG_TYPE_EVENT:
             $this->handleEvent($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_TEXT:
             $this->handleText($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_IMAGE:
             $this->handleImage($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_VOICE:
             $this->handleVoice($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_VIDEO:
             $this->handleVideo($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_LOCATION:
             $this->handleLocation($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_LINK:
             $this->handleLink($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_DEVICE_EVENT:
             $this->handleDeviceEvent($inMessage, $outMessage);
             break;
         case Wechat_InMessage::MSG_TYPE_DEVICE_TEXT:
             $this->handleDeviceText($inMessage, $outMessage);
             break;
         default:
             break;
     }
     if ($outMessage !== null) {
         $outMessage->setFromUserName($inMessage->getFromUserName());
         $outMessage->setToUserName($inMessage->getToUserName());
     }
     return $outMessage;
 }
コード例 #2
0
    public function testVoiceMsg()
    {
        $GLOBALS['HTTP_RAW_POST_DATA'] = '<xml><ToUserName><![CDATA[gh_43235ff1360f]]></ToUserName>
<FromUserName><![CDATA[oWNXvjipYqRViMpO8GZwXxE43pUY]]></FromUserName>
<CreateTime>1419759468</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<MediaId><![CDATA[fwGXgqFETvBRyh1LHivKGd0juSiXUDvFzzzoKyNgKO_oyU6dD_CrB3mFQGt2BcQN]]></MediaId>
<Format><![CDATA[amr]]></Format>
<MsgId>6097820483449399071</MsgId>
<Recognition><![CDATA[]]></Recognition>
</xml>';
        $wechatInMessage = new Wechat_InMessage();
        $this->assertEquals(Wechat_InMessage::MSG_TYPE_VOICE, $wechatInMessage->getMsgType());
    }