【问题标题】:how to get shopee api Authorization use php5.3如何获得shopee api授权使用php5.3
【发布时间】:2019-12-25 11:13:12
【问题描述】:

我想使用源代码获得 shopee 授权。 我使用的语言是 php.5.3.2。 不管我搜索多少次,我都只有高版本的demo,所以找不到我想问的答案。

在shopee中,您可以将默认签名序列和合作伙伴密钥值计算为“HMAC-SHA256”并创建一个自动化值。怎么写成代码?

我已经获得合作伙伴密钥..但我不知道如何获得授权。

【问题讨论】:

  • 考虑到 PHP 5.3 已经 5 年不受支持(没有安全更新等),我真的建议升级到受支持的版本。当你说“我只有一​​个关于更高版本的演示”时,你到底是什么意思?如果您提供一些示例,我们可能会在 5.3 中帮助您做同样的事情。
  • 谢谢你的回答!!我也想升级,但不幸的是我没有升级的情况。也就是说网上有高版本的demo代码,但是我的版本找不到demo代码。
  • 我看到的客户端库代码显示最小代码 PHP7.1,这意味着那里有需要 PHP7.1 的代码。看起来你有2个选择。 1.升级PHP 2.不要使用shopee。
  • Oh or 3. 复习你下载的所有库以使用 PHP5.3
  • “我无法升级” - 那是你应该做的部分。如前所述,PHP 5.3 甚至在 5 年 内都没有获得任何安全更新。这非常不好。

标签: php api php-5.3


【解决方案1】:

为了获得shopee授权,您需要准备一个如下所述的标头,并将此标头与其他所需数据一起发送到 curl 标头中。您可以参考下面给出的示例。

    $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,
    );

准备好之后,在 curl headers 中发送 $header

您的 CURL 请求应该是这样的:

    $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);

希望您的问题由此得到解决。

【讨论】:

    【解决方案2】:

    如果你可以在你的 php 应用中使用 npm 包,你可以使用这个代码:

    import { createHmac } from 'crypto';
        
    const timestamp = getUTCUnixTimestamps();
    const baseString = `${AppID}${Apipath}${timestamp}`;
    const signCode = createHmac('sha256',shopeeAppSecret).update(baseString).digest('hex');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 2021-10-23
      • 2011-06-23
      • 2021-11-01
      相关资源
      最近更新 更多