Google应用内付款:如何处理Google的回发JWT [英] Google in-app payments: howto to handle Google's postback JWT

查看:149
本文介绍了Google应用内付款:如何处理Google的回发JWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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:

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

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:

解码POST的jwt参数中指定的JWT 信息.检查以确保订单正常.获得价值 JWT的"orderId"字段.发送只有一件事的200 OK响应 正文中:您在第3步中获得的"orderId"值.

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的帖子?).

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

推荐答案

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

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电子钱包的应用内购买"文档是相对较新的文档,缺少回调方面的信息.该代码在沙盒和生产端均有效,只需确保使用自己的卖方机密即可.

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应用内付款:如何处理Google的回发JWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆