Php 谷歌钱包订阅JWT数组序列顺序
我的代码生成一个令牌数组,该数组的顺序与jwt所需的顺序相同,但是当我运行编码脚本时,它会按照字母顺序重新排序。这会导致提交到google时失败。看起来序列是通过分类功能重新排序的,但不是。我预计爆炸内爆函数会导致这种情况,但我看不到解决方法 回显数组“$Token”是:- 然后使用调用jwt encode函数Php 谷歌钱包订阅JWT数组序列顺序,php,arrays,android-pay,jwt,Php,Arrays,Android Pay,Jwt,我的代码生成一个令牌数组,该数组的顺序与jwt所需的顺序相同,但是当我运行编码脚本时,它会按照字母顺序重新排序。这会导致提交到google时失败。看起来序列是通过分类功能重新排序的,但不是。我预计爆炸内爆函数会导致这种情况,但我看不到解决方法 回显数组“$Token”是:- 然后使用调用jwt encode函数 $jwtToken = JWT::encode($Token, $sellerSecretKey); 调用的脚本函数为 public static function encod
$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",
}
}
}
地雷
秩序不重要。查看您的
startTime
值(3600
)
开始时间:号码
可选。从历元开始重复充电的时间(秒)。第一次重复将在此字段中指定的时间发生
Hth…谢谢EdSF,为了以防万一,我将开始时间增加了x100,但如果订单不重要,我仍然会收到相同的错误,那么我看不到任何其他内容,因为单个项目正常工作,并且类型已更改为ogle/payments/inapp/subscription/v1@Dave看看如何生成
exp
和iat
('nix epoch)-对于startTime
,它应该是相同的。e、 g.1417564800
表示您的startTime
对于recurrence
将是Wed,2014年12月3日00:00:00 GMT
Hth…使用的代码是$payload->SetIssuedAt(time());$payload->SetExpiration(time()+3600);这与在单个项目中成功使用的相同。我假设返回的是当前时间,重复出现的开始时间为iat加上开始时间(以秒为单位)。我说得对吗?@dave抱歉,我说错了-我的意思是你必须将startTime
的时间转换为历元值,就像你对iat
和exp
所做的那样。在上面的代码中,您将startTime
设置为3600
,即Thu,1970年1月1日01:00:00 GMT
(无效)OK更改了开始时间()+2592000,现在可以工作了!!!!!!首次认购日期为2014/12/03。我现在需要的是我的回发工作,我将完全集成到钱包使用PHP!!
{
"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"
}