Beispiel #1
0
 /**
  * 将公众平台回复用户的消息加密打包.
  * <ol>
  *    <li>对要发送的消息进行AES-CBC加密</li>
  *    <li>生成安全签名</li>
  *    <li>将消息密文和安全签名打包成xml格式</li>
  * </ol>
  *
  * @param string  $xml          公众平台待回复用户的消息,xml格式的字符串
  * @param integer $timestamp    时间戳,可以自己生成,也可以用URL参数的timestamp
  * @param string  $nonce        随机串,可以自己生成,也可以用URL参数的nonce
  *
  * @return string 加密后的可以直接回复用户的密文,包括msg_signature, timestamp,
  *                nonce, encrypt的xml格式的字符串
  */
 public function encryptMsg($xml, $nonce = null, $timestamp = null)
 {
     $encrypt = $this->encrypt($xml, Wechat::getOption('appId'));
     $nonce || ($nonce = uniqid());
     $timestamp || ($timestamp = time());
     //生成安全签名
     $signature = $this->getSHA1(Wechat::getOption('token'), $timestamp, $nonce, $encrypt);
     $response = array('Encrypt' => $encrypt, 'MsgSignature' => $signature, 'TimeStamp' => $timestamp, 'Nonce' => $nonce);
     //生成响应xml
     return XML::build($response);
 }
Beispiel #2
0
 /**
  * Build reply XML.
  *
  * @param string           $to
  * @param string           $from
  * @param MessageInterface $message
  *
  * @return string
  */
 protected function buildReply($to, $from, $message)
 {
     $base = ['ToUserName' => $to, 'FromUserName' => $from, 'CreateTime' => time(), 'MsgType' => $message->getType()];
     return XML::build(array_merge($base, $this->transformer->transform($message)));
 }
Beispiel #3
0
 public function xml($elements = '', $version = '1.0', $encoding = 'utf-8')
 {
     return XML::build($elements, $version, $encoding);
 }
Beispiel #4
0
 /**
  * 将公众平台回复用户的消息加密打包.
  * <ol>
  *    <li>对要发送的消息进行AES-CBC加密</li>
  *    <li>生成安全签名</li>
  *    <li>将消息密文和安全签名打包成xml格式</li>
  * </ol>
  *
  * @param string $xml 公众平台待回复用户的消息,xml格式的字符串
  * @param string $nonce 随机串,可以自己生成,也可以用URL参数的nonce
  * @param int $timestamp 时间戳,可以自己生成,也可以用URL参数的timestamp
  *
  * @return string 加密后的可以直接回复用户的密文,包括msg_signature, timestamp,
  *                nonce, encrypt的xml格式的字符串
  */
 public function encryptMsg($xml, $nonce = null, $timestamp = null)
 {
     $encrypt = $this->encrypt($xml, $this->appId);
     !is_null($nonce) || ($nonce = substr($this->appId, 0, 10));
     !is_null($timestamp) || ($timestamp = time());
     //生成安全签名
     $signature = $this->getSHA1($this->token, $timestamp, $nonce, $encrypt);
     $response = array('Encrypt' => $encrypt, 'MsgSignature' => $signature, 'TimeStamp' => $timestamp, 'Nonce' => $nonce);
     //生成响应xml
     return XML::build($response);
 }