菜鸟教程小白 发表于 2022-12-12 17:07:04

ios - 使用 Moon-APNS 或 APNS-Sharp 的 Apple 推送通知


                                            <p><p>我很难弄清楚如何将消息从我的服务器发送到 APNS。我使用过 Moon-APNS 和 APNS-Sharp,但我遇到了同样的错误,即“参数不正确”。我使用 KeyChain 生成了 p12 文件。我将文件拖到我的 Win 7 虚拟环境中,并将其放在 bin\debug 文件夹中。以下是 Moon-APNS 的代码:</p>

<pre><code> static void Main(string[] args)
      {
            var deviceToken = &#34;21212d6fefebde4d317cab41afff65631b5a4d47e5d85da305ec610b4013e616&#34;;

            var payload = new NotificationPayload(deviceToken, &#34;hello world&#34;);
            var notificationList = new List&lt;NotificationPayload&gt;() { payload };

            var push = new PushNotification(true, &#34;PushNotificationTest.p12&#34;, &#34;pushchat&#34;);
            var result = push.SendToApple(notificationList);

            Console.WriteLine(&#34;Hello World&#34;);
      }
</code></pre>

<p>有人有想法吗? </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我认为这会对你有所帮助:</p>

<p>OSX 钥匙串(keychain)</p>

<p>在 iPhone Developer Program Portal 中创建适当的推送通知证书后,您应该已经下载了一个名为 apn_developer_identity.cer 的文件。如果你还没有这样做,你应该打开/导入这个文件到钥匙串(keychain),进入你的登录部分。</p>

<p>最后,如果您过滤钥匙串(keychain)以显示您的登录容器的证书,您应该会看到您的证书已列出。展开证书,下面/附加到它应该有一个 key 。</p>

<p>右键单击或 Ctrl+单击相应的证书并选择导出。钥匙串(keychain)会要求您选择要导出的密码。选择一个并记住它。您最终应该得到一个 .p12 文件。您将需要此文件和您选择的密码才能在此处使用通知和反馈库。
开放式SSL</p>

<p>这里是如何使用 open ssl 创建一个 PKCS12 格式文件,你需要你的开发者私钥(可以从钥匙串(keychain)中导出)和 CertificateSigningRequest??.certSigningRequest</p>

<pre><code>1. Convert apn_developer_identity.cer (der format) to pem:

openssl x509 -in apn_developer_identity.cer -inform DER -out apn_developer_identity.pem -outform PEM}

2. Next, Convert p12 private key to pem (requires the input of a minimum 4 char password):

openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12

3. (Optional): If you want to remove password from the private key:

openssl rsa -out private_key_noenc.pem -in private_key.pem

4. Take the certificate and the key (with or without password) and create a PKCS#12 format file:

openssl pkcs12 -export -in apn_developer_identity.pem -inkey private_key_noenc.pem -certfile CertificateSigningRequest??.certSigningRequest -name &#34;apn_developer_identity&#34; -out apn_developer_identity.p12
</code></pre>

<p>我发现 Moon-APNS 更易于在我的应用中使用和配置。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用 Moon-APNS 或 APNS-Sharp 的 Apple 推送通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7080318/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7080318/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用 Moon-APNS 或 APNS-Sharp 的 Apple 推送通知