加密的字符串未在Json API中传递

时间:2018-10-25 06:06:40

标签: php encryption

我在将加密值发送到API密钥时遇到问题,当我回显该变量时,该值会显示,但在API密钥中它将显示为空白,并且我们没有任何字符长度。下面是尝试过的代码:

    <?php

include('connection.php');

$mobile = "9886098860";

class AesCipher
{

      Encryted code
}
// USAGE
$secretKey = 'secret key';
$text = $mobile;
$encrypted = AesCipher::encrypt($secretKey, $text);
echo $encrypted;

if(isset($_POST['submit']))
{
 if(isset($_FILES['image'])){

         // Inserting the values to database to store it
    //   }else{
    //      print_r($errors);
    //   }
   }




 if ($result = mysqli_query($con, $query))
{

    echo "data inserted";

// //setup request to send json via POST
$data['merchantid']= '111';
$data['subsid']='0';
$data['mobilenumber']=$mobile;
$data['appid']='0';
**$data['pid']=$encrypted;**
$data['source'] = 'company';


$payload = json_encode($data);

echo $payload;
echo $encrypted;

$URL='https://apirul.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);//get status code
$result1 = json_decode($output);

//echo $status_code;
echo $result1;
echo $ch;
curl_close ($ch);   

?>

当我们进行回显时,将显示加密的变量值,但是当我传递相同的变量时,它将显示 {} 而不是加密的值。

任何人都可以帮助我解决我的问题。

0 个答案:

没有答案