在 PHP 中为身份验证标头生成签名 - Paypal [英] Generating Signatures for the Authentication Header in PHP - Paypal

查看:43
本文介绍了在 PHP 中为身份验证标头生成签名 - Paypal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近完成了流程创建了从帐户持有人那里检索权限的脚本后,我现在发现我必须转换检索到的 access tokentoken secret(来自 GetAccessToken 响应)到 API 签名 以创建 X-PAYPAL-AUTHORIZATION 标头.

Having recently finished the process of having created the script that retrieves permissions from a account holder I now find that I have to convert the retrieved access token and token secret (from the GetAccessToken response) to the API signature in order to create a X-PAYPAL-AUTHORIZATION header.

X-PAYPAL-AUTHORIZATION 标头包含:

The X-PAYPAL-AUTHORIZATION header contains:

  • 时间戳
  • 来自 GetAccessToken 响应的访问令牌
  • 根据以下信息生成的签名:
    • 您的 API 用户名
    • 您的 API 密码
    • 来自 GetAccessToken 响应的访问令牌
    • 来自 GetAccessToken 响应的令牌秘密
    • PayPal API 操作请求的端点,例如 https://api.paypal.com/nvp
    • HTTPS 传输方式,例如 POST
    • 与请求关联的请求参数

    问题是我找不到如何生成签名.PHP 中没有指南(JAVARuby).

    The problem is I can't find how to generate the signature. There are no guides in PHP (JAVA and Ruby).

    但是,我确实注意到了我遵循的指南中的行(第一个链接)来检索权限:

    I did however note the line in the guide I followed (first link) to retrieve the permissions:

    PayPal 提供了 SDK,您可以使用这些 SDK 为 Java、PHP 和 .NET 生成身份验证标头签名.使用SDK时,会得到两个值,例如:

    PayPal provides SDKs that you can use to generate authentication header signatures for Java, PHP, and .NET. When you use the SDK, you will get two values, such as the following:

    但是接下来是 JAVA 指南,我在 Paypal 的 SDK 中找不到任何内容.

    But what followed was the JAVA guide and I could not find anything amongth Paypal's SDKs.

    任何帮助将不胜感激!

    推荐答案

    这个 文档 实际上从他们的 PHP SDK 中删除了应该为您完成的功能.

    This documentation actually cuts out the function from their PHP SDK that should do it for you.

    private function generateAuthString($apiCred, $accessToken, $tokenSecret, $endpoint)
    {
    $callerUid = $apiCred->getUserName();
    $callerPswd = $apiCred->getPassword();
    $auth = new AuthSignature();
    $response = $auth->genSign($callerUid,$callerPswd,$accessToken,$tokenSecret,'POST',$endpoint);
    $authString =
    "token=".$accessToken.
    ",signature=".$response['oauth_signature'].
    ",timestamp=".$response['oauth_timestamp'];
    return $authString;
    }
    

    这篇关于在 PHP 中为身份验证标头生成签名 - Paypal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆