为什么wordpress没有在参数中使用加密字符串

时间:2016-01-08 19:14:08

标签: php wordpress

我写了一个curl函数,在标题中我传递了一些参数。一个参数必须加密。所以我使用AES算法来包含该字符串参数。加密后它包含一些特殊字符,数字。当我发送请求时,wordpress不接受字符串参数,因为它是发送请求。

同样的代码在wordpress之外工作正常但在wordpress中由于特殊的char它给我错误。

我需要做什么设置。所以wordpress将按原样获取参数。

<?phperror_reporting(E_ALL ^ E_WARNING);class AES{ const M_CBC = 'cbc';
 const M_CFB = 'cfb';
 const M_ECB = 'ecb';
 const M_NOFB = 'nofb';
 const M_OFB = 'ofb';
 const M_STREAM = 'stream';
 protected $_key;
 protected $cipher;
 protected $data;
 protected $mode;
 protected $IV;
 /** * * @param type $data * @param type $key * @param type $blockSize * @param type $mode */
 function __construct($data = null, $key = null, $blockSize = null, $mode = null)
 { $this->setData($data);
 $this->setBlockSize($blockSize);
 $this->setKey($key);
 $this->setMode($mode);
 $this->setIV("");
 }
 /** *  * @param type $data */
 public function setData($data)
 {
 $this->data = $data;
 } 
 /** *  * @param type $key */
 public function setKey($key)
 {
 $this->_key = $key;
 }
 /** *  * @param type $blockSize */
 public function setBlockSize($blockSize)
 {
 switch ($blockSize)
 {
 case 128: $this->cipher = MCRYPT_RIJNDAEL_128;
 break;
 case 192: $this->cipher = MCRYPT_RIJNDAEL_192;
 break;
 case 256: $this->cipher = MCRYPT_RIJNDAEL_256;
 break;
 }
 }


 /** *  * @param type $mode */
 public function setMode($mode)
 {
 switch ($mode)
 {
 case AES::M_CBC: $this->mode = MCRYPT_MODE_CBC;
 break;
 case AES::M_CFB: $this->mode = MCRYPT_MODE_CFB;
 break;
 case AES::M_ECB: $this->mode = MCRYPT_MODE_ECB;
 break;
 case AES::M_NOFB: $this->mode = MCRYPT_MODE_NOFB;
 break;
 case AES::M_OFB: $this->mode = MCRYPT_MODE_OFB;
 break;
 case AES::M_STREAM: $this->mode = MCRYPT_MODE_STREAM;
 break;
 default: $this->mode = MCRYPT_MODE_ECB;
 break;
 }
 } 


 /** *  * @return boolean */
 public function validateParams()
 {
 if ($this->data != null && $this->_key != null && $this->cipher != null)
 {
 return true;
 } 
 else
 {
 return FALSE;
 }
 }

 public function setIV($IV)
 {
 $this->IV = $IV;
 } 
 protected function getIV()
 {
 if ($this->IV == "")
 {
 $this->IV = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->mode), MCRYPT_RAND);
 $this->IV = mb_convert_encoding($this->IV,'UTF-8');
 }
 return $this->IV;
 } 



 /** * @return type * @throws Exception */  
 public function encrypt()
 {
 if ($this->validateParams())
 {
 $block = mcrypt_get_block_size($this->cipher, $this->mode);
 $padding = $block - (strlen($this->data) % $block);
 $this->data .= str_repeat(chr($padding), $padding);
 return trim(base64_encode( mcrypt_encrypt( $this->cipher, $this->_key, $this->data, $this->mode, $this->getIV())));
 } 
 else 
 { 
 throw new Exception('Invalid params!');
 }
 } 


 /** *  * @return type * @throws Exception */ 
 public function decrypt()
 {
 if ($this->validateParams())
 {
 return trim(mcrypt_decrypt( $this->cipher, $this->_key, base64_decode($this->data), $this->mode, $this->getIV()));
 }
 else 
 { throw new Exception('Invalid params!');
 }
 } 
 }
 ?><?php date_default_timezone_set("UTC");
 $t = microtime(true);
 $sig_data= date('Y-m-d H:i:s.', substr($t, 0, -3)) . substr($t,-3);


 /// Add your API Key
 $api_key='71ae815b-6075-XXXXX-a12d7878bf47'; 
 /// Add your API Secret
 $private_key='079499d582934XXXXc4dbd12645e4581';
 $mode='cbc';
 $blockSize = 128;
 /// Generate the Signature
 $aes = new AES($sig_data, $private_key, $blockSize, $mode);
 $enc = $aes->encrypt();
 echo $enc;

 $en = preg_replace('/[^a-zA-z]/', 'p', $enc);
 echo $en;

 /// Call the GetProducts Method
 $url="https://api.omgpm.com/network/OMGNetworkApi.svc/v1.1/ProductFeeds/GetProductsByCategory?".http_build_query(array('AgencyID' => 95, 'AID' => 861823, 'MID' =>$mid, "CategoryKeyword" => $opt_category  ,"NumberOfRecords"=>10, 'MinPrice' => 5000000, 'MaxPrice' => 99999999999, 'Currency' => 'INR', 'DiscountedOnly' => 'false', 'ProductSKU' => '', 'Key' => $api_key, 'Sig' => $en, 'SigData' => $sig_data));
 $headers = array("Content-Type: application/json","Accept: application/json","Access-Control-Request-Method: GET" );
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 $result = curl_exec($ch);
 $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);print_r($result);
 ?>

0 个答案:

没有答案