我的cURL请求没有给出任何回复

时间:2017-02-14 06:42:20

标签: php curl

我有cURL请求。

$data[] = 'oep_action=reg';
$data[] = 'oep_fullname=Dawar Khan';
$data[] = 'oep_usertype=G0';
$data[] = 'oep_idno=881041106';
$data[] = 'oep_idexpiry=03/01/2022';
$data[] = 'oep_dob=03/03/1988';
$data[] = 'oep_phoneno=36566339';
$data[] = 'oep_email=ali.zia.1991@gmail.com';
$data[] = 'oep_returnurl=http://localhost/ali/api.php';
$data[] = 'oep_accountid=XXXXXXXXX';

$secretkey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$sortedarray = SortArray($data);

$hashkey = strtoupper(hash_hmac('SHA256', implode("&", $sortedarray), pack('H*', $secretkey)));

echo $datastr = '{ "Params": { "FullName": "'.get2ndParam($data[1]).'", "Email": "'.get2ndParam($data[7]).'", "MobileNumber": "'.get2ndParam($data[6]).'", "UserType": "'.get2ndParam($data[2]).'", "IDNumber": "'.get2ndParam($data[3]).'", "IDExpiry": "'.get2ndParam($data[4]).'", "DOB": "'.get2ndParam($data[5]).'" }, "AccountID": "'.get2ndParam($data[9]).'", "SecureHash": "'.$hashkey.'" }';

$url = 'https://api/epost.om/Restfulservice.svc/EpostRegistration';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/json;charset=UTF-8 ',
 'Content-Length: ' . strlen($datastr))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastr);
$result = curl_exec($ch);
//var_dump($result);
curl_close($ch);

$json_result = json_decode($result, true);
echo '<pre>';print_r($json_result);echo '</pre>';

function get2ndParam($str){
    $txt = explode('=',$str);
    return $txt[1];
}

function SortArray(array $array) {
    if (count($array) == 0) {
        return $array;
    }
    $pivot = $array[0];
    $left = $right = array();
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i] < $pivot) {
            $left[] = $array[$i];
        } else {
            $right[] = $array[$i];
        }
    }
    return array_merge(SortArray($left), array(
        $pivot
        ), SortArray($right));
}

应该以这种格式给我回复。

  

{&#34; EpostID&#34;:&#34; string&#34;,&#34; Status&#34;:&#34; string&#34;,&#34; RmmsAmount&#34;:& #34; string&#34;,&#34; RmmsExpiry&#34;:&#34; string&#34; }

但它让我空白。我做错了什么?

0 个答案:

没有答案