Google 应用内支付:如何处理 Google 的回发 JWT
也许这是一个愚蠢的问题,但我不是高级程序员。我已经 已成功为我的应用程序设置应用内付款,但它只能工作 不使用回发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一年后我遇到了同样的问题,并使用以下代码解决了它:
Google Wallet 的应用内购买文档相对较新,并且缺乏回调方面。此代码适用于沙箱和生产端,只需确保您使用自己的卖家秘密即可。
I had this same problem a year later and solved it with the following code:
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.
将 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.