编程语言
首页 > 编程语言> > PHP-Google应用内付款:如何处理Google的回发JWT

PHP-Google应用内付款:如何处理Google的回发JWT

作者:互联网

也许这是一个愚蠢的问题,但我不是高级程序员.我有
已成功为我的应用设置了应用内付款,但仅适用
而不使用回发网址.

Google已经花了大约几个小时试图自己解决这个问题,
成功.希望任何人都能帮助我.我已经包含了剧本
处理帖子数据显然有误..这就是Google所说的:

Your server must send a 200 OK response for each HTTP POST message
that Google sends to your postback URL. To send this response, your
server must:

Decode the JWT that’s specified in the jwt parameter of the POST
message. Check to make sure that the order is OK. Get the value of the
JWT’s “orderId” field. Send a 200 OK response that has only one thing
in the body: the “orderId” value you got in step 3.

这是我写的,但据我所知,没有办法对其进行测试(如何模拟来自Google的帖子?).

require_once 'include/jwt.php'; // including luciferous jwt library 

$encoded_jwt = $_POST['jwt']; 
$decoded_jwt = JWT::decode($encoded_jwt, "fdNAbAdfkCDakJQBdViErg"); 
$decoded_jwt_array = (array) $decoded_jwt; 
$orderId = $decoded_jwt_array['response']['orderId']; 

header("HTTP/1.0 200 OK"); 
echo $orderId; 

任何帮助将非常感激.谢谢蒂姆

解决方法:

一年后,我遇到了同样的问题,并使用以下代码解决了该问题:

require_once 'include/jwt.php'; // including luciferous jwt library 

$encoded_jwt = $_POST['jwt']; 
$decodedJWT = JWT::decode($jwt, $sellerSecret);

// get orderId
$orderId = $decodedJWT->response->orderId;

header("HTTP/1.0 200 OK"); 
echo $orderId; 

Google电子钱包的In App Purchase文档是相对较新的文档,缺少回调方面的内容.该代码在沙盒和生产端均有效,只需确保使用自己的卖方机密即可.

标签:jwt,postback,php
来源: https://codeday.me/bug/20191201/2082753.html