从后端将 App Store 服务器通知转发给 Adapty 如果您的后端需要在 App Store Connect 中保留其 URL,请将 App Store 服务器通知从您的后端原封不动地转发给 Adapty。如果您的后端不需要在 App Store Connect 中保留其 URL,可改为在 Adapty 中设置转发到您的后端 。这种方式无需编写任何代码。
Adapty 会像处理 Apple 直接发送的通知一样处理来自您后端的通知。借助 Refund Saver ,Adapty 仍会对其中的退款请求做出响应。
如果您的后端通过自己的 Pub/Sub 主题接收来自 Google Play 的实时开发者通知,则无需编写任何代码即可将其传递给 Adapty。为 Adapty 添加该主题的推送订阅 。
如需将 App Store 服务器通知传递给 Adapty:
在 Adapty 中,打开您要连接的应用:每个 Adapty 应用都有其专属的通知 URL。前往 App settings > iOS SDK 。在 App Store server notifications 部分,从 URL for App Store server notifications 字段复制 URL。
在您的后端,将 Apple 发送的每条通知转发到您复制的 URL。每个请求需满足以下要求:
保持 Apple 原始请求体不变:{"signedPayload": "…"}。
设置请求头 Content-Type: application/json。
不要添加 Authorization 请求头。
如果 Adapty 也将通知转发给你的后端,请勿将这些通知再回传给 Adapty。
以下是不同编程语言的示例:
Copy
url = "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/" # don't forget to replace this URL
payload = '{"signedPayload":"eyJhbGciOiJFUzI1NiIs..."}' # Apple's request body, unchanged
headers = {
'Content-Type' : 'application/json'
}
response = requests.request( "POST" , url, headers = headers, data = payload) Copy const axios = require ( 'axios' );
const url = 'https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/' ; // don't forget to replace this URL
const payload = '{"signedPayload":"eyJhbGciOiJFUzI1NiIs..."}' ; // Apple's request body, unchanged
const config = {
method: 'post' ,
url: url,
headers: {
'Content-Type' : 'application/json'
},
data: payload,
};
const response = await axios (config); Copy <? php
require_once 'HTTP/Request2.php' ;
$url = 'https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/' ; // don't forget to replace this URL
$payload = '{"signedPayload":"eyJhbGciOiJFUzI1NiIs..."}' ; // Apple's request body, unchanged
$request = new HTTP_Request2 ();
$request -> setUrl ($url);
$request -> setMethod ( HTTP_Request2 :: METHOD_POST );
$request -> setConfig ( array (
'follow_redirects' => TRUE
));
$request -> setHeader ( array (
'Content-Type' => 'application/json'
));
$request -> setBody ($payload);
$response = $request -> send (); Copy String url = "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad45/" ; // don't forget to replace this URL
String payload = "{ \" signedPayload \" : \" eyJhbGciOiJFUzI1NiIs... \" }" ; // Apple's request body, unchanged
OkHttpClient 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 (); Copy 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 。