【问题标题】:google-wallet subscriptions JWT array sequence ordergoogle-wallet 订阅 JWT 数组序列顺序
【发布时间】:2014-12-28 20:31:43
【问题描述】:

我的代码会生成一个令牌数组,该数组按照 jwt 所需的顺序排列,但是当我运行编码脚本时,它会按照字母顺序重新排序。这会在提交给 google 时导致失败。看起来这个序列是用 assort 函数重新排序的,但不是。我预计爆炸内爆功能会导致此问题,但我无法找到解决方法!

回显的数组“$Token”是:-

 Array ( [iss] => 12345605871924644272 
    [aud] => Google 
    [typ] => google/payments/inapp/subscription/v1 
    [exp] => 1414875564 
    [iat] => 1414871964
    [request]     => array ( [name] => Invoice Number: 106599 
                             [description] => Supported Service 
                             [sellerData] =>user_id:1224245,
                                offer_code:3098576987,affiliate:aksdfbovu9j
       [initialPayment] => Array( [price] => 100 
                                  [currencyCode] => GBP
                                  [paymentType] => prorated ) 
       [recurrence] => Array ( [price] => 30 
                               [currencyCode] => GBP
                               [startTime] => 3600 [frequency] => Monthly
                               [numRecurrences] => 24 
              )
            ) 
       )

然后调用 jwt 编码函数

  $jwtToken = JWT::encode($Token, $sellerSecretKey);

调用的脚本函数是

  public static function encode($payload, $key, $algo = 'HS256')
 {
    $header = array('typ' => 'JWT', 'alg' => $algo);

    $segments = array();
    $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
    $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
    $signing_input = implode('.', $segments);

    $signature = JWT::sign($signing_input, $key, $algo);
    $segments[] = JWT::urlsafeB64Encode($signature);

    return implode('.', $segments);
 }

 /**
 * @param string $msg    The message to sign
 * @param string $key    The secret key
 * @param string $method The signing algorithm
 *
 * @return string An encrypted message
 */
 public static function sign($msg, $key, $method = 'HS256')
 {
    $methods = array(
        'HS256' => 'sha256',
        'HS384' => 'sha384',
        'HS512' => 'sha512',
    );
    if (empty($methods[$method])) {
        throw new DomainException('Algorithm not supported');
    }
    return hash_hmac($methods[$method], $msg, $key, true);
 }

返回的 jwt 具有正确的元素,但顺序错误。首先显示所需的顺序,然后显示我的顺序

{
"iss" : "1337133713371337",
"aud" : "Google",
"typ" : "google/payments/inapp/subscription/v1",
"exp" : "1309988959",
"iat" : "1409988959",
"request" :{
  "name" : "Weekly Cake",
  "description" : "Virtual chocolate cake to fill your virtual tummy every week",
  "sellerData" : "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j",
  "initialPayment" : {
    "price" : "1.49",
    "currencyCode" : "USD",
    "paymentType" : "prorated",
  },
  "recurrence" : {
    "price" : "4.99",
    "currencyCode" : "USD",
    "startTime" : "1309989638",
    "frequency" : "monthly",
    "numRecurrences" : "12",
  }
}
}

我的

{
"aud": "Google", 
"iss": "12345605871924644272", 
"request": {
    "initialPayment": {
        "paymentType": "prorated", 
        "price": "100", 
        "currencyCode": "GBP"
    }, 
    "recurrence": {
        "numRecurrences": "24", 
        "price": "30", 
        "frequency": "Monthly", 
        "currencyCode": "GBP", 
        "startTime": "3600"
    }, 
    "sellerData": "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j", 
    "name": "Invoice Number: 106599", 
    "description": "Supported Service"
}, 
"exp": 1414873724, 
"iat": 1414870124, 
"typ": "google/payments/inapp/subscription/v1"
}

【问题讨论】:

    标签: php arrays android-pay jwt


    【解决方案1】:

    顺序不重要。查看您的 startTime 值 (3600)。

    开始时间:数字。

    可选。从纪元开始重复收费的时间(以秒为单位)。第一次重复将在此字段中指定的时间发生。

    第...

    【讨论】:

    • 感谢 EdSF 我已将开始时间增加了 x100 以防万一,但如果订单无关紧要,我仍然会收到相同的错误,然后我看不到任何其他内容,因为单个项目有效且类型已更改为google/payments/inapp/subscription/v1
    • @Dave 看看你是如何生成expiat('nix epoch)的——对于startTime 应该是一样的。例如1417564800 表示您的 startTimerecurrence 将是 Wed, 03 Dec 2014 00:00:00 GMT Hth...
    • 使用的代码是$payload->SetIssuedAt(time()); $payload->SetExpiration(time()+3600);这与在单项中成功使用相同。我假设正在返回当前时间,并以 iat 加上开始时间(以秒为单位)重复开始时间。我说的对吗?
    • @dave 抱歉,我说错了 - 我的意思是您必须将时间转换为 startTime 的纪元值,就像您为 iatexp 所做的那样。在上面的代码中,您将startTime 设置为3600,即Thu, 01 Jan 1970 01:00:00 GMT(无效)
    • OK 将开始时间更改为 time()+2592000,现在可以使用了!!!!!!首次订阅显示为 2014/12/03。我现在需要的是我的回发工作,我将使用 PHP 完全集成到钱包!
    猜你喜欢
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多