HikCentral Professional OpenAPI Authentication and JSON data fetch issue

EDIT: I have included the documentation link for this API. The link is:
https://pinfo.hikvision.com/hkwsen/unzip/20240201150721_74009_doc/

So I have been trying to call the parkingfee/calculate API using cURL PHP and I am able to get the 200 status code which means it reaches the server. But somehow the JSON data is not showing up even though I get the 200 status code. I have concluded it’s an authentication issue but I couldn’t really figure out where I went wrong. I have contacted the tech support from hikvision but they would not help in that term and kept on suggesting for me to use CSHCSDKDemo application that comes with the HCP download. It seems they couldn’t understand my request. The image I attached is the error I have been getting and it shows the status code 200 as well. Any help would be appreciated, thank you.

At first, I kept getting errors like HTTP failed request: 400 status code but when I changed the headers parameters, I finally got the 200 status code which means successfully called the API but the JSON data that comes with it does not show up. And also, in the documentation, it mentioned that I need to calculate the signature using So I am not sure where I went wrong.

Below is the instructions on how to calculate the signature:
Signature Calculation

  1. Calculate the signature string by HmacSHA256 algorithm with the appKey or appSecret to
    generate message digest.
  2. Calculate the message digest by BASE64 algorithm to generate the signature.

This is my code that I use to calculate the signature:

$stringToSign = "{$httpMethod}n". "{$contentMD5}n". "{$contentType}n". "{$apiKey}n". "{$x_ca_nonce}n". "{$timestampInMilliseconds}n". "{$urlEndpoint}n";

// Generate Signature
$signature = hash_hmac('sha256', $stringToSign, $apiSecret, true);
// Encode Signature (base64)
$base64encodedSignature = base64_encode($signature);

Below is the header parameter that gave the 200 status code.

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POST, 1); //set request method to post
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Basic', // Adjust according to API's authentication requirements
    'accept: '. $accept.,
    'accept-encoding: '. $acceptEncoding,
    'accept-language: '. $acceptLanguage,
    'connection: '. $connection,
    'content-length: '. $contentLength, //$contentLength,
    'content-md5: '. $contentMD5,
    'content-type: '. $contentType,
    'host: '. $host,
    'method: '. $httpMethod,
    'server: '. $server,
    'transferEncoding: '. $transferEncoding,
    'x-ca-key: ' . $apiKey,
    'x-ca-signature: ' . $base64encodedSignature,
    'x-ca-signature: x-ca-key, x-ca-timestamp',
    'x-ca-timestamp: ' . $timestampInMilliseconds,
    'x-ca-nonce: ' . $x_ca_nonce,
    'x-ca-secret:' . $apiSecret,
    'x-requested-with: '. $x_requested_with,
    'url: ' . $apiUrl
]);

I am not sure if the error comes from the signature calculation or the header. But the error I’m getting shows:
Status Code: 200 Error decoding JSON response: Control character error, possibly incorrectly encoded

New contributor

abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật