示例#1
0
 /**
  * 对消息进行加密
  * 微信提供
  * @param string $text           需要加密的消息
  * @param string $appid          
  * @param string $encodingAesKey
  * @return string 加密后的消息字符串
  */
 public static function encrypt($text, $appid, $encodingAesKey)
 {
     $encrypted = '';
     $key = self::key($encodingAesKey);
     try {
         $random = StrStatic::randomString('alnum', 16);
         $text = $random . pack("N", strlen($text)) . $text . $appid;
         $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
         $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         $iv = substr($key, 0, 16);
         $text = self::PKCS7Encoder_encode($text);
         mcrypt_generic_init($module, $key, $iv);
         $encrypted = mcrypt_generic($module, $text);
         mcrypt_generic_deinit($module);
         mcrypt_module_close($module);
     } catch (\Exception $e) {
         die($text);
     }
     return base64_encode($encrypted);
 }
示例#2
0
 protected function set_sha1_sign($encrypt, &$timestamp, &$nonce)
 {
     $timestamp = time();
     $nonce = StrStatic::randomString('numeric');
     return $this->sha1_sign($encrypt, $timestamp, $nonce);
 }