Last active
August 22, 2024 01:25
-
-
Save php-cpm/d46e8cb40c30fb893ee48cb4992c1d8d to your computer and use it in GitHub Desktop.
apple iap App Store Server Notifications V2 parse code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$error = ['code'=>0,'msg'=>'']; | |
$req = json_decode(file_get_contents("php://input"), true); | |
if (//https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv1 | |
!isset($req['environment']) || | |
//https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2 | |
!isset($req['signedPayload']) { | |
$error = ['code' => 400, 'msg' => 'params error']; | |
return $error; | |
} | |
if(isset($req['environment'])) { | |
... | |
return ['code'=>0,'msg'=>'']; | |
} | |
if(isset($req['signedPayload'])) { | |
list($header,$payload,$sign) = explode('.', $req['signedPayload']); | |
$decodePayload = base64_decode($payload); | |
$notificationType = $decodePayload['notificationType']; | |
$env = $decodePayload['data']['environment']; | |
$signedTransactionInfo = $decodePayload['data']['signedTransactionInfo']; | |
list($trans_header,$trans_payload,$trans_sign) = explode('.', $signedTransactionInfo); | |
$dtp = base64_decode($trans_payload); | |
$data = [ | |
"transactionId"=> $dtp["transactionId"], | |
"originalTransactionId"=> $dtp["originalTransactionId"], | |
"bundleId"=> $dtp["bundleId"], | |
"productId"=> $dtp["productId"], | |
"purchaseDate"=> $dtp["purchaseDate"], | |
"originalPurchaseDate"=> $dtp["originalPurchaseDate"], | |
"quantity"=> $dtp["quantity"], | |
"type"=> $dtp["type"], | |
"inAppOwnershipType"=> $dtp["inAppOwnershipType"], | |
"signedDate"=> $dtp["signedDate"], | |
]; | |
return ['code'=>0,'msg'=>'','data'=>$data]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
App Store Server Notifications V2 diffs from App Store Server Notifications V1
you can only get the refund transaction Info this time
you need to check the verify api manually to get older one's status.