/** * @param string $body * @return mixed * @throws \ErrorException */ public function buildMessagePackage($body) { $xml = simplexml_load_string($body, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xml === false) { throw new \BadFunctionCallException('Load xml error.'); } $crypt = new PrpCrypt($this->_encodingAesKey); $decrypt = $crypt->decrypt((string) $xml->Encrypt, $this->_corpId); return new MessagePackage($decrypt); }
/** * 验证URL * * @param string $msgSignature : 签名串,对应URL参数的msg_signature * @param string $timestamp : 时间戳,对应URL参数的timestamp * @param string $nonce : 随机串,对应URL参数的nonce * @param string $echoStr : 随机串,对应URL参数的echostr * @return string 成功返回0,失败返回对应的错误码 */ public function verifyURL($msgSignature, $timestamp, $nonce, $echoStr) { if (strlen($this->_encodingAesKey) !== self::ENCODING_AES_KEY_LENGTH) { return false; } $pc = new PrpCrypt($this->_encodingAesKey); try { $signature = $this->getSignature($timestamp, $nonce, $echoStr); } catch (\Exception $e) { return false; } if ($signature != $msgSignature) { return false; } return $pc->decrypt($echoStr, $this->_corpId); }
/** * @param string $body * @return string */ protected function decrypt($body) { $xml = static::buildXmlElement($body); $crypt = new PrpCrypt($this->_encodingAesKey); return $crypt->decrypt((string) $xml->Encrypt, $this->_corpId); }
/** * @param string $xml * @return string */ protected function buildEncryptedXml($xml) { $crypt = new PrpCrypt($this->_encodingAesKey); return $crypt->encrypt($xml, $this->_corpId); }