问题
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
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/9399221/google-in-app-payments-howto-to-handle-googles-postback-jwt