「Php/アプリストア連携/返金API/AppStore」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→返金通知のサーバ側モックJSON) |
(→appstore内の返金リクエストurl) |
||
行47: | 行47: | ||
==appstore内の返金リクエストurl== | ==appstore内の返金リクエストurl== | ||
ttps://reportaproblem.apple.com/ | ttps://reportaproblem.apple.com/ | ||
+ | |||
+ | ==apple署名検証== | ||
+ | jsonはjwtエンコードされてるので、jwtデコードする必要がある。 | ||
+ | その際に、apple証明書で、検証する。アプリ別(bundle_id別)ではなく、どのアプリでも同じ証明書で検証する。 | ||
+ | ===openssl_x509_store_add_certが使えない場合はコマンドで実行する=== | ||
+ | <pre> | ||
+ | function custom_store_add_cert($store, $cert) { | ||
+ | if (function_exists('openssl_x509_store_add_cert')) { | ||
+ | return openssl_x509_store_add_cert($store, $cert); | ||
+ | } | ||
+ | // 代替実装 | ||
+ | $tmpFile = tempnam(sys_get_temp_dir(), 'cert'); | ||
+ | file_put_contents($tmpFile, $cert); | ||
+ | $cmd = sprintf('openssl x509 -in %s -addtrust serverAuth', $tmpFile); | ||
+ | shell_exec($cmd); | ||
+ | unlink($tmpFile); | ||
+ | return true; | ||
+ | } | ||
+ | </pre> |
2025年6月6日 (金) 18:13時点における版
目次
appleのstorekitの返金のドキュメント
https://developer.apple.com/jp/documentation/storekit/in-app_purchase/handling_refund_notifications/
ストアからの通知url設定箇所
appstore管理画面/配信/アプリ情報/appstoreサーバ通知
返金通知のサーバ側モックJSON
- subtype: "DISPUTE", or "OTHER"
- signedRenewalInfo: 省略可能(テスト時)
- signedTransactionInfo: 省略可能(テスト時)
- cancellation_reason: 1:ユーザー申請, 0:その他
{ "notificationType": "REFUND", "subtype": "DISPUTE", // または "OTHER" "notificationUUID": "a1b2c3d4-5678-90ef-1234-567890abcdef", "data": { "appAppleId": 123456789, "bundleId": "com.example.app1", "bundleVersion": "1.0", "environment": "Sandbox", "signedRenewalInfo": "...", "signedTransactionInfo": "...", "unifiedReceipt": { "environment": "Sandbox", "latest_receipt": "BASE64_ENCODED_RECEIPT_DATA", "latest_receipt_info": [ { "cancellation_date_ms": "1625097600000", "cancellation_reason": "1", "product_id": "premium_subscription", "transaction_id": "1000000123456789", "original_transaction_id": "1000000123456789", "purchase_date_ms": "1625000000000", "expires_date_ms": "1627600000000" } ], "status": 0 } }, "version": "2.0" }
appstore内の返金リクエストurl
ttps://reportaproblem.apple.com/
apple署名検証
jsonはjwtエンコードされてるので、jwtデコードする必要がある。 その際に、apple証明書で、検証する。アプリ別(bundle_id別)ではなく、どのアプリでも同じ証明書で検証する。
openssl_x509_store_add_certが使えない場合はコマンドで実行する
function custom_store_add_cert($store, $cert) { if (function_exists('openssl_x509_store_add_cert')) { return openssl_x509_store_add_cert($store, $cert); } // 代替実装 $tmpFile = tempnam(sys_get_temp_dir(), 'cert'); file_put_contents($tmpFile, $cert); $cmd = sprintf('openssl x509 -in %s -addtrust serverAuth', $tmpFile); shell_exec($cmd); unlink($tmpFile); return true; }