Google 应用内支付:如何处理 Google 的回发 JWT

发布于 2025-01-08 02:17:08 字数 800 浏览 1 评论 0原文

也许这是一个愚蠢的问题,但我不是高级程序员。我已经 已成功为我的应用程序设置应用内付款,但它只能工作 不使用回发 url。

我在谷歌上搜索了很多个小时,试图自己解决这个问题,但没有 成功。希望有人能帮助我。我已经包含了脚本 处理发布数据这显然是错误的。这就是谷歌所说的:

您的服务器必须为每个 HTTP POST 消息发送 200 OK 响应 Google 发送到您的回发网址。要发送此回复,您的 服务器必须:

解码 POST 的 jwt 参数中指定的 JWT 信息。检查以确保订单正确。获取值 JWT 的“orderId”字段。发送仅包含一件事的 200 OK 响应 正文中:您在第 3 步中获得的“orderId”值。

这是我写的,但据我所知,无法测试它(我如何模拟来自 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; 

任何帮助将不胜感激。谢谢蒂姆

Maybe its a stupid question but I'm not an advanced programmer. I've
have successfully setup In-App payments for my app but it only works
without using a postback url.

I've Google'd around many hours trying to tackle this myself without
success. Hopefully anybody could help me out. I've included the script
handling the post data which does obviously something wrong.. This is what Google says:

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.

This is what I wrote but as far as I can see there is no way to test it (how can I simulate a post from 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; 

Any help would be much appreciated. Thanks Tim

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不放开 2025-01-15 02:17:08

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

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 Wallet 的应用内购买文档相对较新,并且缺乏回调方面。此代码适用于沙箱和生产端,只需确保您使用自己的卖家秘密即可。

I had this same problem a year later and solved it with the following code:

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 Wallet's In App Purchase documentation is relatively new, and lacking on the callback side. This code works both sandbox and production side, just make sure you use your own seller secret.

故事灯 2025-01-15 02:17:08

将 Google 电子钱包设置中的沙盒回发 URL 设置为测试页面,然后将请求记录到该页面。你会看到一个 JWT。用它来测试。

Set Sandbox Postback URL in your Google Wallet setting to a test page, then log the requests to that page. You will see a JWT. Use it for test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文