1
我正在學習一個教程,該教程需要我打開一個套接字併發送一個帶有證書的有效載荷:http://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/。等效於php的stream_context_create
我有一定的困難,在搞清楚如何做蟒蛇如下:
// Open the connection
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
// Send the payload
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
// Close Resources
socket_close($apns);
fclose($apns);
我已經在過去使用的python-請求。但僅限於簡單的獲取請求。
我可以使用python-requests在python中重寫上面的代碼,還是有更適合這個任務的東西?
任何你不能使用[pyapns](https://github.com/samuraisam/pyapns)的理由? – 2012-08-10 15:29:35
@MartijnPieters,:) – TheOne 2012-08-10 15:38:21
您是否找到任何解決方案? – 2016-03-14 09:06:08