问题
i want to get shopee authorization using the source code. The language I use is php.5.3.2. No matter how many times I search, I only have a demo about the higher version, so I can't find the answer I want to ask.
In shopee, you can calculate the default signature sequence and partner key value as "HMAC-SHA256" and create an autorization value. How can I write it in code?
i already get partner key.. but i don't know how to get authorization.
回答1:
In order to get shopee authorization, you need to prepare a header as mentioned below and send this header in curl headers with other required data. You can refer to the example given below.
$secretKey = 'Your Secret Key' ;
$baseUrl = "https://partner.shopeemobile.com/api/v1/";
$action = 'The action you want to perform';
$apiUrl = $baseUrl.$action ;
$parameters = 'Required Parameters' ;
$authorisation = $apiUrl."|".json_encode($parmaeters);
$authorisation = rawurlencode(hash_hmac('sha256', $authorisation, $secretKey,
enter code herefalse));
$header = array(
'Content-Type: application/json',
'Authorization: '.$authorisation,
);
After preparing this, send $header in curl headers
YOUR CURL REQUEST WOULD BE LIKE THIS:
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $apiUrl);
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
Hope you get your query resolved by this.
回答2:
If you can use npm package in your php app, you can use this code:
import { createHmac } from 'crypto';
const timestamp = getUTCUnixTimestamps();
const baseString = `${AppID}${Apipath}${timestamp}`;
const signCode = createHmac('sha256',shopeeAppSecret).update(baseString).digest('hex');
来源:https://stackoverflow.com/questions/57570193/how-to-get-shopee-api-authorization-use-php5-3