iOS 推送,伺服器。證書。

2021-09-06 08:43:53 字數 2577 閱讀 7068

兩個證書 ios_development.cer    push.pl2 

到當前目錄:把.cer檔案轉換成.pem檔案:

$ openssl x509 -in ios_develoment.cer -inform der

-out pushchatcert.pem

把私鑰.p12檔案轉換成.pem檔案:

$ openssl pkcs12 -nocerts -out pushchatkey.pem -in push.p12

enter import password:

mac verified ok

enter pem pass phrase:          //兩次輸入密文,用於驗證 server

verifying – enter pem pass phrase:

你首先需要為.p12檔案輸入passphrase密碼短語,這樣openssl可以讀它。然後你需要鍵入乙個新的密碼短語來加密pem檔案。還是使用」pushchat」來作為pem的密碼短語。你需要選擇一些更安全的密碼短語。

注意:如果你沒有鍵入乙個pem passphrase,openssl將不會返回乙個錯誤資訊,但是產生的.pem檔案裡面將不會含有私鑰。

最後。把私鑰和證書整合到乙個.pem檔案裡:

cat pushchatcert.pem pushchatkey.pem > ck.pem

測試證書

trying 17.172.232.226…

escape character is 『^]』.

成功。

<?php

// 這裡是我們上面得到的devicetoken,直接複製過來(記得去掉空格)

$devicetoken = '740f4707bebcf74f 9b7c25d4 8e3358945f6aa01da5ddb387462c7eaf 61bb78ad';

// put your private key's passphrase here:

$passphrase = 'abc123456';

// put your alert message here:

$message = 'my first push test!';

$ctx = stream_context_create();

stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');

stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// open a connection to the apns server

//這個為正是的發布位址

$fp = stream_socket_client(

$errstr, 60, stream_client_connect|stream_client_persistent, $ctx);

if (!$fp)

exit

("failed to connect: $err $errstr"

.php_eol);

echo'connected to apns'.php_eol;

// create the payload body

$body['aps'] = array(

'alert' => $message,

'sound'=> 'default'

);// encode the payload as json

$payload = json_encode($body);

// build the binary notification

$msg = chr(0) . pack('n', 32) . pack('h*', $devicetoken) . pack('n', strlen($payload)) . $payload;

// send it to the server

$result = fwrite($fp, $msg, strlen($msg));

if (!$result)

echo'message not delivered'.php_eol;

else

echo'message successfully delivered'.php_eol;

// close the connection to the server

fclose($fp);

?>

接下來我們訪問http://localhost/push/push.php

iphone就會接收到一條推送訊息了,如果有問題的話就檢查上面的操作步驟,特別是加紅的部分

intbadge = [

if(badge > 0)

iOS生成伺服器端的推送證書

生成伺服器端的推送證書 匯出命名為apns dev cert.p12 匯出的時候會設定匯出證書的密碼,請記好設定的密碼。同樣做法匯出專用秘鑰 命名為apns dev key.p12 開啟mac 終端將這些檔案轉換成pem格式 openssl pkcs12 clcerts nokeys out apn...

ios 推送證書

雙擊 aps.cer,開啟鑰匙串,找到這個鑰匙,匯出,得到乙個p12檔案,自己命名。我這叫dc zs.p12。將aps.cer轉換成aps dis.pem格式 openssl x509 in aps.cer inform der out aps dis.pem outform pem 將p12格式的...

伺服器證書

目前網際網路常用的http協議是非常不安全的明文傳輸協議。而ssl協議及其繼任者tls協議,是一種實現網路通訊加密的安全協議,可在客戶端 瀏覽器 和伺服器端 之間建立一條加密通道,保證資料在傳輸過程中不被竊取或篡改。ssl證書,也稱為伺服器證書,是遵守ssl協議的一種數字證書,由全球信任的證書頒發機...