バックエンドのURLをApp Store Connectに保持する必要がある場合は、App Serverの通知をバックエンドからAdaptyへそのまま転送してください。バックエンドのURLをApp Store Connectに設定する必要がない場合は、代わりにAdaptyでバックエンドへの転送を設定してください。その方法ではコードは不要です。
Adaptyで接続するアプリを開きます。各AdaptyアプリにはそれぞれNotification URLがあります。App settings > iOS SDK に移動し、App Store server notifications セクションの URL for App Store server notifications フィールドからURLをコピーします。
String url = "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/"; // don't forget to replace this URLString payload = "{\"signedPayload\":\"eyJhbGciOiJFUzI1NiIs...\"}"; // Apple's request body, unchangedOkHttpClient client = new OkHttpClient().newBuilder() .build();MediaType mediaType = MediaType.parse("application/json");RequestBody body = RequestBody.create(mediaType, payload);Request request = new Request.Builder() .url(url) .method("POST", body) .addHeader("Content-Type", "application/json") .build();Response response = client.newCall(request).execute();
package main "fmt" "strings" "net/http")func main() { url := "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/" // Replace this with the actual URL payload := strings.NewReader(`{"signedPayload":"eyJhbGciOiJFUzI1NiIs..."}`) // Apple's request body, unchanged method := "POST" client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close()}
200 レスポンスは、Adapty が通知を利用できたことを確認するものではありません。Adapty は署名済みペイロードをデコードする前に応答します。通知が Adapty に届いていることを確認するには、サンドボックス購入を行ってください。その後、App Store server notifications セクションの通知ステータスが Active と表示されていることを確認してください。