我的代码生成一个令牌数组,该数组按照jwt所需的顺序排列,但是当我运行编码脚本时,它会按字母顺序重新排序。这会在提交给谷歌时导致失败。看起来序列是使用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"
}
答案 0 :(得分:1)
订单无关紧要。查看您的startTime
值(3600
)。
startTime:Number。
可选。从纪元开始重复充电的时间以秒为单位。第一次重复将在此字段中指定的时间发生。
... H个