谷歌钱包订阅JWT数组顺序


google-wallet subscriptions JWT array sequence order

我的代码生成一个令牌数组,该数组的顺序符合jwt所需的顺序,但当我运行编码脚本时,它会按字母顺序重新排序。这会导致提交到谷歌时失败。看起来序列是用排序函数重新排序的,但事实并非如此。我预计爆炸内爆函数会导致这种情况,但我看不到解决的方法!

回声数组"$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"
}

订单应该无关紧要。查看您的startTime值(3600)。

startTime:数字。

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

Hth。。。