Codeigniter フレームワークに基づく APNS バッチ プッシュ - Ding Dong、水道メーターを確認してください
- WBOYオリジナル
- 2016-08-18 08:57:581395ブラウズ
<p><span style="font-family: 宋体, SimSun; font-size: 18px;"> 最近、私のアルバイト先がクラウドファンディングを成功させたワイヤレスドアホンのメッセージプッシュに問題があり、その結果、一部のユーザーがプッシュメッセージを受信できなくなってしまい、本当に困っています。私が自分で提供したバックエンド サービスは会社の評判に影響します。私たちのニーズを簡単に紹介します。その会社は、誰かがドアの外でドアベル スイッチを押すと、信号を発します。家の中の受信ゲートウェイが信号を受信すると、ユーザーの携帯電話にメッセージがプッシュされます。つまり、所有者は、誰かが家のドアホンを押したことがわかります。彼は家にいません。ここでバックグラウンドで解決する必要がある問題は、APNS プッシュ用のプロバイダーを構築することです。メッセージを Apple 携帯電話にプッシュするには、Apple が設計したメカニズムに従ってメッセージを Apple の PUSH サーバーにプッシュする必要があるからです。各携帯電話は deviceToken に対応します。ここでの説明の焦点は、このプラットフォームを構築する方法ではありません。国内のインターネットにはすでにかなりの数のチュートリアルがあります。たとえば、次を参照できます: </span><span style="font-family: 宋体, SimSun; font-size: 18px;">iOS プッシュの作り方を段階的に教えます</span></p>
<p style="text-align: center;"><img src="http://images2015.cnblogs.com/blog/801509/201608/801509-20160815193218250-1934481869.jpg" alt="" border="0"></p>
<p style="text-align: left;"><span style="font-family: 宋体, SimSun; font-size: 18px;">オンラインチュートリアルのほとんどは合理的ですが、それらは携帯電話で動作します。つまり、当社が設計した製品では、同じアカウントを携帯電話端末に一度にプッシュすることができます。携帯電話で複数のデバイスにログインします(バックグラウンドでの制限がないため、理論的には無数にあります)。また、同社の製品は、各携帯電話に対応する共有機能も備えています。つまり、メイン ユーザーは他のユーザーとデバイスを共有でき、他のユーザーが別のデバイスで同時にログインでき、誰かがドアベルを鳴らすと、共有ユーザーを含むログインしているすべてのユーザーにメッセージがプッシュされます。 , つまり、多くの携帯電話端末に一括でプッシュされることになります。もちろん、ここで示した例は、すべての問題が 1 つの質問に抽象化されています。deviceToken を格納するための配列を与えてください。</span><strong><span style="color: #ff0000; font-family: 宋体, SimSun; font-size: 18px;"> APNS はどのようにして複数のユーザーにバッチでプッシュしますか?
</span></strong></p>
<p style="text-align: left;"><strong><span style="color: #ff0000;">
</span></strong>まず、ユーザーのプッシュ トークン (deviceToken) を保存するデータベースを設計します。簡単にするために、このテーブルにはフィールドが 2 つだけあります。 </p>
<p>
<span style="font-family: 宋体, SimSun; font-size: 18px;">
</span>
</p>
<div class="wiz-table-container" style="position: relative; padding: 15px 0px 5px;">
<div class="wiz-table-body">
<table style="width: 100%;" border="1" bgcolor="#FFFFFF">client_id<tbody>
<tr>デバイストークン<td style="width: 50%;">
</td>
<td style="width: 50%;">
</td>1</tr>
<tr>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<td style="width: 50%;">
</td>
<td style="width: 50%;">
</td>
<p> </p>
<p><span style="font-family: 宋体, SimSun; font-size: 18px;">ここでは CodeIgniter3 フレームワークを使用して、ユーザーの deviceToken データを管理する新しいモデルを作成します。 </span></p>
<div id="highlighter_460547" class="syntaxhighlighter php">
<div class="wiz-table-container" style="position: relative; padding: 15px 0px 5px;">
<div class="wiz-table-body">
<table class="noBorderTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2" style="height: 16px;">1</div>
<div class="line number2 index1 alt1" style="height: 16px;">2</div>
<div class="line number3 index2 alt2" style="height: 16px;">3</div>
<div class="line number4 index3 alt1" style="height: 16px;">4</div>
<div class="line number5 index4 alt2" style="height: 16px;">5</div>
<div class="line number6 index5 alt1" style="height: 16px;">6</div>
<div class="line number7 index6 alt2" style="height: 16px;">7</div>
<div class="line number8 index7 alt1" style="height: 16px;">8</div>
<div class="line number9 index8 alt2" style="height: 16px;">9</div>
<div class="line number10 index9 alt1" style="height: 16px;">10</div>
<div class="line number11 index10 alt2" style="height: 16px;">11</div>
<div class="line number12 index11 alt1" style="height: 16px;">12</div>
<div class="line number13 index12 alt2" style="height: 16px;">13</div>
<div class="line number14 index13 alt1" style="height: 16px;">14</div>
<div class="line number15 index14 alt2" style="height: 16px;">15</div>
<div class="line number16 index15 alt1" style="height: 16px;">16</div>
<div class="line number17 index16 alt2" style="height: 16px;">17</div>
<div class="line number18 index17 alt1" style="height: 16px;">18</div>
<div class="line number19 index18 alt2" style="height: 16px;">19</div>
<div class="line number20 index19 alt1" style="height: 16px;">20</div>
<div class="line number21 index20 alt2" style="height: 16px;">21</div>
<div class="line number22 index21 alt1" style="height: 16px;">22</div>
<div class="line number23 index22 alt2" style="height: 16px;">23</div>
<div class="line number24 index23 alt1" style="height: 16px;">24</div>
<div class="line number25 index24 alt2" style="height: 16px;">25</div>
<div class="line number26 index25 alt1" style="height: 16px;">26</div>
<div class="line number27 index26 alt2" style="height: 16px;">27</div>
<div class="line number28 index27 alt1" style="height: 16px;">28</div>
<div class="line number29 index28 alt2" style="height: 16px;">29</div>
<div class="line number30 index29 alt1" style="height: 16px;">30</div>
<div class="line number31 index30 alt2" style="height: 16px;">31</div>
<div class="line number32 index31 alt1" style="height: 16px;">32</div>
<div class="line number33 index32 alt2" style="height: 16px;">33</div>
<div class="line number34 index33 alt1" style="height: 16px;">34</div>
<div class="line number35 index34 alt2" style="height: 16px;">35</div>
<div class="line number36 index35 alt1" style="height: 16px;">36</div>
<div class="line number37 index36 alt2" style="height: 16px;">37</div>
<div class="line number38 index37 alt1" style="height: 16px;">38</div>
<div class="line number39 index38 alt2" style="height: 16px;">39</div>
<div class="line number40 index39 alt1" style="height: 16px;">40</div>
<div class="line number41 index40 alt2" style="height: 16px;">41</div>
<div class="line number42 index41 alt1" style="height: 16px;">42</div>
<div class="line number43 index42 alt2" style="height: 16px;">43</div>
<div class="line number44 index43 alt1" style="height: 16px;">44</div>
<div class="line number45 index44 alt2" style="height: 16px;">45</div>
<div class="line number46 index45 alt1" style="height: 16px;">46</div>
<div class="line number47 index46 alt2" style="height: 16px;">47</div>
<div class="line number48 index47 alt1" style="height: 16px;">48</div>
<div class="line number49 index48 alt2" style="height: 16px;">49</div>
<div class="line number50 index49 alt1" style="height: 16px;">50</div>
<div class="line number51 index50 alt2" style="height: 16px;">51</div>
<div class="line number52 index51 alt1" style="height: 16px;">52</div>
<div class="line number53 index52 alt2" style="height: 16px;">53</div>
<div class="line number54 index53 alt1" style="height: 16px;">54</div>
<div class="line number55 index54 alt2" style="height: 16px;">55</div>
<div class="line number56 index55 alt1" style="height: 16px;">56</div>
<div class="line number57 index56 alt2" style="height: 16px;">57</div>
<div class="line number58 index57 alt1" style="height: 16px;">58</div>
<div class="line number59 index58 alt2" style="height: 16px;">59</div>
<div class="line number60 index59 alt1" style="height: 16px;">60</div>
<div class="line number61 index60 alt2" style="height: 16px;">61</div>
<div class="line number62 index61 alt1" style="height: 16px;">62</div>
<div class="line number63 index62 alt2" style="height: 16px;">63</div>
<div class="line number64 index63 alt1" style="height: 16px;">64</div>
<div class="line number65 index64 alt2" style="height: 16px;">65</div>
<div class="line number66 index65 alt1" style="height: 16px;">66</div>
<div class="line number67 index66 alt2" style="height: 16px;">67</div>
<div class="line number68 index67 alt1" style="height: 16px;">68</div>
<div class="line number69 index68 alt2" style="height: 16px;">69</div>
<div class="line number70 index69 alt1" style="height: 16px;">70</div>
<div class="line number71 index70 alt2" style="height: 16px;">71</div>
<div class="line number72 index71 alt1" style="height: 16px;">72</div>
<div class="line number73 index72 alt2" style="height: 16px;">73</div>
<div class="line number74 index73 alt1" style="height: 16px;">74</div>
<div class="line number75 index74 alt2" style="height: 16px;">75</div>
<div class="line number76 index75 alt1" style="height: 16px;">76</div>
<div class="line number77 index76 alt2" style="height: 16px;">77</div>
<div class="line number78 index77 alt1" style="height: 16px;">78</div>
<div class="line number79 index78 alt2" style="height: 16px;">79</div>
<div class="line number80 index79 alt1" style="height: 16px;">80</div>
<div class="line number81 index80 alt2" style="height: 16px;">81</div>
<div class="line number82 index81 alt1" style="height: 16px;">82</div>
<div class="line number83 index82 alt2" style="height: 16px;">83</div>
<div class="line number84 index83 alt1" style="height: 16px;">84</div>
<div class="line number85 index84 alt2" style="height: 16px;">85</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2" style="height: 16px;"><code class="php plain"><?php</code></div>
<div class="line number2 index1 alt1" style="height: 16px;"><code class="php comments">// ios推送令牌管理</code></div>
<div class="line number3 index2 alt2" style="height: 16px;"> </div>
<div class="line number4 index3 alt1" style="height: 16px;"> </div>
<div class="line number5 index4 alt2" style="height: 16px;"> </div>
<div class="line number6 index5 alt1" style="height: 16px;"><code class="php keyword">class</code> <code class="php plain">Apns_model </code><code class="php keyword">extends</code> <code class="php plain">CI_Model</code></div>
<div class="line number7 index6 alt2" style="height: 16px;"><code class="php plain">{</code></div>
<div class="line number8 index7 alt1" style="height: 16px;"> </div>
<div class="line number9 index8 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">__construct()</code></div>
<div class="line number10 index9 alt1" style="height: 16px;"><code class="php space"> </code><code class="php spaces"> </code><code class="php plain">{</code></div>
<div class="line number11 index10 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->load->database();</code></div>
<div class="line number12 index11 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number13 index12 alt2" style="height: 16px;"> </div>
<div class="line number14 index13 alt1" style="height: 16px;"> </div>
<div class="line number15 index14 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">/**</code>
</div>
<div class="line number16 index15 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">* 新建推送令牌</code>
</div>
<div class="line number17 index16 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">* create a apns如果已经存在就更新这个deviceToken</code>
</div>
<div class="line number18 index17 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">* $data is an array organized by controller</code>
</div>
<div class="line number19 index18 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">*/</code>
</div>
<div class="line number20 index19 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">create(</code><code class="php variable">$data</code><code class="php plain">)</code>
</div>
<div class="line number21 index20 alt2" style="height: 16px;">
<code class="php space"> </code><code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number22 index21 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$this</code><code class="php plain">->db->replace(</code><code class="php string">'tb_apns'</code><code class="php plain">, </code><code class="php variable">$data</code><code class="php plain">))</code>
</div>
<div class="line number23 index22 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number24 index23 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">TRUE;</code>
</div>
<div class="line number25 index24 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number26 index25 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">else</code>
</div>
<div class="line number27 index26 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number28 index27 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">FALSE;</code>
</div>
<div class="line number29 index28 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number30 index29 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number31 index30 alt2" style="height: 16px;"> </div>
<div class="line number32 index31 alt1" style="height: 16px;"> </div>
<div class="line number33 index32 alt2" style="height: 16px;"> </div>
<div class="line number34 index33 alt1" style="height: 16px;"> </div>
<div class="line number35 index34 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">//删除某个用户的推送令牌</code>
</div>
<div class="line number36 index35 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php functions">delete</code><code class="php plain">(</code><code class="php variable">$user_id</code><code class="php plain">)</code>
</div>
<div class="line number37 index36 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number38 index37 alt1" style="height: 16px;">
<code class="php spaces"> </code> </div>
<div class="line number39 index38 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code><code class="php plain">(isset(</code><code class="php variable">$user_id</code><code class="php plain">)){</code><code class="php キーワード">if</code><code class="php plain">(isset(</code><code class="php 変数">$user_id</code>)){</div>
<div class="line number40 index39 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$result</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->db-></code><code class="php functions">delete</code><code class="php plain">(</code><code class="php string">'tb_apns'</code><code class="php plain">, </code><code class="php keyword">array</code><code class="php plain">(</code><code class="php string">'client_id'</code> <code class="php plain">=> </code><code class="php variable">$user_id</code><code class="php plain">)); </code>
</div>
<div class="line number41 index40 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">TRUE; </code>
</div>
<div class="line number42 index41 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{</code><code class="php keyword">else</code><code class="php plain">{</code>
</div>
<div class="line number43 index42 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">FALSE;</code>
</div>
<div class="line number44 index43 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number45 index44 alt2" style="height: 16px;"> </div>
<div class="line number46 index45 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number47 index46 alt2" style="height: 16px;"> </div>
<div class="line number48 index47 alt1" style="height: 16px;"> </div>
<div class="line number49 index48 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">//根据推送令牌删除推送令牌</code>
</div>
<div class="line number50 index49 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">deletebytoken(</code><code class="php variable">$token</code><code class="php plain">)</code>
</div>
<div class="line number51 index50 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number52 index51 alt1" style="height: 16px;">
<code class="php spaces"> </code> </div>
<div class="line number53 index52 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(isset(</code><code class="php variable">$token</code><code class="php plain">)) {</code><code class="php キーワード">if</code> <code class="php plain">(isset(</code><code class="php 変数">$token</code>)) {</div>
<div class="line number54 index53 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$result</code><code class="php plain">=</code><code class="php variable">$this</code><code class="php plain">->db-></code><code class="php functions">delete</code><code class="php plain">(</code><code class="php string">'tb_apns'</code><code class="php plain">, </code><code class="php keyword">array</code><code class="php plain">(</code><code class="php string">'deviceToken'</code><code class="php plain">=></code><code class="php variable">$token</code><code class="php plain">));</code>
</div>
<div class="line number55 index54 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">TRUE;</code>
</div>
<div class="line number56 index55 alt1" style="height: 16px;"> </div>
<div class="line number57 index56 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code><code class="php keyword">else</code><code class="php plain">{</code><code class="php keyword">else</code><code class="php plain">{</code>
</div>
<div class="line number58 index57 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">FALSE;</code>
</div>
<div class="line number59 index58 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number60 index59 alt1" style="height: 16px;"> </div>
<div class="line number61 index60 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number62 index61 alt1" style="height: 16px;"> </div>
<div class="line number63 index62 alt2" style="height: 16px;"> </div>
<div class="line number64 index63 alt1" style="height: 16px;"> </div>
<div class="line number65 index64 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">//查询某个用户的iso推送令牌</code>
</div>
<div class="line number66 index65 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">get(</code><code class="php variable">$client_id</code><code class="php plain">)</code>
</div>
<div class="line number67 index66 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number68 index67 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$sql</code> <code class="php plain">= </code><code class="php string">"SELECT deviceToken FROM `tb_apns` WHERE `client_id`='$client_id'"</code><code class="php plain">;</code>
</div>
<div class="line number69 index68 alt2" style="height: 16px;"> </div>
<div class="line number70 index69 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$result</code> <code class="php plain">= </code><code class="php variable">$this</code><code class="php plain">->db->query(</code><code class="php variable">$sql</code><code class="php plain">);</code>
</div>
<div class="line number71 index70 alt2" style="height: 16px;"> </div>
<div class="line number72 index71 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(</code><code class="php variable">$result</code><code class="php plain">->num_rows()>0)</code>
</div>
<div class="line number73 index72 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number74 index73 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php variable">$result</code><code class="php plain">->result_array();</code>
</div>
<div class="line number75 index74 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number76 index75 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">else</code>
</div>
<div class="line number77 index76 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number78 index77 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">FALSE;</code>
</div>
<div class="line number79 index78 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number80 index79 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number81 index80 alt2" style="height: 16px;"> </div>
<div class="line number82 index81 alt1" style="height: 16px;"> </div>
<div class="line number83 index82 alt2" style="height: 16px;"> </div>
<div class="line number84 index83 alt1" style="height: 16px;"> </div>
<div class="line number85 index84 alt2" style="height: 16px;"><code class="php plain">}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><span style="font-family: 宋体, SimSun; font-size: 18px;"> 私のバックエンドの最初のバージョンでは、オンライン チュートリアルによれば、メッセージはほとんど一度に 1 つの端末にプッシュされ、取得したすべての deviceToken を $deviceTokens 配列に格納する必要がありました。メッセージの場合は、for ループを使用して配列から deviceToken を順番に取り出してプッシュし、カウントし、すべてのプッシュが成功した場合に true を返します。この方法には問題はないようで、テストは成功したので、直接オンラインにアクセスしました (主な理由は、プッシュ機能のステータスが非常に高くなるような製品を会社が突然リリースするとは予想していなかったからだ。私はずっとオプションだと思っていました)。 </span></p>
<p> </p>
<div id="highlighter_623968" class="syntaxhighlighter php">
<div class="wiz-table-container" style="position: relative; padding: 15px 0px 5px;">
<div class="wiz-table-body">
<table class="noBorderTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2" style="height: 16px;">1</div>
<div class="line number2 index1 alt1" style="height: 16px;">2</div>
<div class="line number3 index2 alt2" style="height: 16px;">3</div>
<div class="line number4 index3 alt1" style="height: 16px;">4</div>
<div class="line number5 index4 alt2" style="height: 16px;">5</div>
<div class="line number6 index5 alt1" style="height: 16px;">6</div>
<div class="line number7 index6 alt2" style="height: 16px;">7</div>
<div class="line number8 index7 alt1" style="height: 16px;">8</div>
<div class="line number9 index8 alt2" style="height: 16px;">9</div>
<div class="line number10 index9 alt1" style="height: 16px;">10</div>
<div class="line number11 index10 alt2" style="height: 16px;">11</div>
<div class="line number12 index11 alt1" style="height: 16px;">12</div>
<div class="line number13 index12 alt2" style="height: 16px;">13</div>
<div class="line number14 index13 alt1" style="height: 16px;">14</div>
<div class="line number15 index14 alt2" style="height: 16px;">15</div>
<div class="line number16 index15 alt1" style="height: 16px;">16</div>
<div class="line number17 index16 alt2" style="height: 16px;">17</div>
<div class="line number18 index17 alt1" style="height: 16px;">18</div>
<div class="line number19 index18 alt2" style="height: 16px;">19</div>
<div class="line number20 index19 alt1" style="height: 16px;">20</div>
<div class="line number21 index20 alt2" style="height: 16px;">21</div>
<div class="line number22 index21 alt1" style="height: 16px;">22</div>
<div class="line number23 index22 alt2" style="height: 16px;">23</div>
<div class="line number24 index23 alt1" style="height: 16px;">24</div>
<div class="line number25 index24 alt2" style="height: 16px;">25</div>
<div class="line number26 index25 alt1" style="height: 16px;">26</div>
<div class="line number27 index26 alt2" style="height: 16px;">27</div>
<div class="line number28 index27 alt1" style="height: 16px;">28</div>
<div class="line number29 index28 alt2" style="height: 16px;">29</div>
<div class="line number30 index29 alt1" style="height: 16px;">30</div>
<div class="line number31 index30 alt2" style="height: 16px;">31</div>
<div class="line number32 index31 alt1" style="height: 16px;">32</div>
<div class="line number33 index32 alt2" style="height: 16px;">33</div>
<div class="line number34 index33 alt1" style="height: 16px;">34</div>
<div class="line number35 index34 alt2" style="height: 16px;">35</div>
<div class="line number36 index35 alt1" style="height: 16px;">36</div>
<div class="line number37 index36 alt2" style="height: 16px;">37</div>
<div class="line number38 index37 alt1" style="height: 16px;">38</div>
<div class="line number39 index38 alt2" style="height: 16px;">39</div>
<div class="line number40 index39 alt1" style="height: 16px;">40</div>
<div class="line number41 index40 alt2" style="height: 16px;">41</div>
<div class="line number42 index41 alt1" style="height: 16px;">42</div>
<div class="line number43 index42 alt2" style="height: 16px;">43</div>
<div class="line number44 index43 alt1" style="height: 16px;">44</div>
<div class="line number45 index44 alt2" style="height: 16px;">45</div>
<div class="line number46 index45 alt1" style="height: 16px;">46</div>
<div class="line number47 index46 alt2" style="height: 16px;">47</div>
<div class="line number48 index47 alt1" style="height: 16px;">48</div>
<div class="line number49 index48 alt2" style="height: 16px;">49</div>
<div class="line number50 index49 alt1" style="height: 16px;">50</div>
<div class="line number51 index50 alt2" style="height: 16px;">51</div>
<div class="line number52 index51 alt1" style="height: 16px;">52</div>
<div class="line number53 index52 alt2" style="height: 16px;">53</div>
<div class="line number54 index53 alt1" style="height: 16px;">54</div>
<div class="line number55 index54 alt2" style="height: 16px;">55</div>
<div class="line number56 index55 alt1" style="height: 16px;">56</div>
<div class="line number57 index56 alt2" style="height: 16px;">57</div>
<div class="line number58 index57 alt1" style="height: 16px;">58</div>
<div class="line number59 index58 alt2" style="height: 16px;">59</div>
<div class="line number60 index59 alt1" style="height: 16px;">60</div>
<div class="line number61 index60 alt2" style="height: 16px;">61</div>
<div class="line number62 index61 alt1" style="height: 16px;">62</div>
<div class="line number63 index62 alt2" style="height: 16px;">63</div>
<div class="line number64 index63 alt1" style="height: 16px;">64</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2" style="height: 16px;">
<code class="php keyword">function</code> <code class="php plain">_send_apns(</code><code class="php variable">$deviceTokens</code><code class="php plain">,</code><code class="php variable">$message</code><code class="php plain">)</code>
</div>
<div class="line number2 index1 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number3 index2 alt2" style="height: 16px;"> </div>
<div class="line number4 index3 alt1" style="height: 16px;"> </div>
<div class="line number5 index4 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">// Put your private key's passphrase here:密语</code>
</div>
<div class="line number6 index5 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$passphrase</code> <code class="php plain">= </code><code class="php string">'xxxxx'</code><code class="php plain">;</code>
</div>
<div class="line number7 index6 alt2" style="height: 16px;"> </div>
<div class="line number8 index7 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">////////////////////////////////////////////////////////////////////////////////</code>
</div>
<div class="line number9 index8 alt2" style="height: 16px;"> </div>
<div class="line number10 index9 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$ctx</code> <code class="php plain">= stream_context_create();</code>
</div>
<div class="line number11 index10 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">stream_context_set_option(</code><code class="php variable">$ctx</code><code class="php plain">, </code><code class="php string">'ssl'</code><code class="php plain">, </code><code class="php string">'local_cert'</code><code class="php plain">, </code><code class="php string">'xxxx.pem'</code><code class="php plain">);</code>
</div>
<div class="line number12 index11 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">stream_context_set_option(</code><code class="php variable">$ctx</code><code class="php plain">, </code><code class="php string">'ssl'</code><code class="php plain">, </code><code class="php string">'passphrase'</code><code class="php plain">, </code><code class="php variable">$passphrase</code><code class="php plain">);</code>
</div>
<div class="line number13 index12 alt2" style="height: 16px;"> </div>
<div class="line number14 index13 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">// Open a connection to the APNS server</code>
</div>
<div class="line number15 index14 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$fp</code> <code class="php plain">= stream_socket_client(</code>
</div>
<div class="line number16 index15 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php string">'ssl://gateway.push.apple.com:2195'</code><code class="php plain">, </code><code class="php variable">$err</code><code class="php plain">,</code>
</div>
<div class="line number17 index16 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$errstr</code><code class="php plain">, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, </code><code class="php variable">$ctx</code><code class="php plain">);</code>
</div>
<div class="line number18 index17 alt1" style="height: 16px;"> </div>
<div class="line number19 index18 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(!</code><code class="php variable">$fp</code><code class="php plain">)</code>
</div>
<div class="line number20 index19 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php functions">exit</code><code class="php plain">(</code><code class="php string">"Failed to connect: $err $errstr"</code> <code class="php plain">. PHP_EOL);</code>
</div>
<div class="line number21 index20 alt2" style="height: 16px;"> </div>
<div class="line number22 index21 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php functions">echo</code> <code class="php string">'Connected to APNS'</code> <code class="php plain">. PHP_EOL;</code>
</div>
<div class="line number23 index22 alt2" style="height: 16px;"> </div>
<div class="line number24 index23 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">// Create the payload body</code>
</div>
<div class="line number25 index24 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$body</code><code class="php plain">[</code><code class="php string">'aps'</code><code class="php plain">] = </code><code class="php keyword">array</code><code class="php plain">(</code>
</div>
<div class="line number26 index25 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php string">'alert'</code> <code class="php plain">=> </code><code class="php variable">$message</code><code class="php plain">,</code>
</div>
<div class="line number27 index26 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php string">'sound'</code> <code class="php plain">=> </code><code class="php string">'default'</code>
</div>
<div class="line number28 index27 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">);</code>
</div>
<div class="line number29 index28 alt2" style="height: 16px;"> </div>
<div class="line number30 index29 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php comments">// Encode the payload as JSON</code>
</div>
<div class="line number31 index30 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$payload</code> <code class="php plain">= json_encode(</code><code class="php variable">$body</code><code class="php plain">);</code>
</div>
<div class="line number32 index31 alt1" style="height: 16px;"> </div>
<div class="line number33 index32 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$num</code><code class="php plain">=</code><code class="php functions">count</code><code class="php plain">(</code><code class="php variable">$deviceTokens</code><code class="php plain">);</code>
</div>
<div class="line number34 index33 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$countOK</code><code class="php plain">=0;</code><code class="php comments">//统计发送成功的条数</code>
</div>
<div class="line number35 index34 alt2" style="height: 16px;"> </div>
<div class="line number36 index35 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php variable">$num</code><code class="php plain">;</code><code class="php variable">$i</code><code class="php plain">++)</code></div>
<div class="line number37 index36 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">{</code></div>
<div class="line number38 index37 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$deviceToken</code><code class="php plain">=</code><code class="php variable">$deviceTokens</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">];</code></div>
<div class="line number39 index38 alt2" style="height: 16px;"> </div><div class="line number40 index39 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$deviceToken</code><code class="php plain">=preg_replace(</code><code class="php string">"/s/"</code><code class="php plain">,</code><code class="php string">""</code><code class="php plain">,</code><code class="php variable">$deviceToken</code><code class="php plain">);</code><code class="php comments">//删除deviceToken里的空格</code></div>
<div class="line number41 index40 alt2" style="height: 16px;"> </div>
<div class="line number42 index41 alt1" style="height: 16px;"> </div>
<div class="line number43 index42 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php comments">// Build the binary notification</code></div>
<div class="line number44 index43 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$msg</code> <code class="php plain">= </code><code class="php functions">chr</code><code class="php plain">(0) . pack(</code><code class="php string">'n'</code><code class="php plain">, 32) . pack(</code><code class="php string">'H*'</code><code class="php plain">, </code><code class="php variable">$deviceToken</code><code class="php plain">) . pack(</code><code class="php string">'n'</code><code class="php plain">, </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$payload</code><code class="php plain">)) . </code><code class="php variable">$payload</code><code class="php plain">;</code></div>
<div class="line number45 index44 alt2" style="height: 16px;"> </div>
<div class="line number46 index45 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php comments">// Send it to the server</code></div>
<div class="line number47 index46 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$result</code> <code class="php plain">= fwrite(</code><code class="php variable">$fp</code><code class="php plain">, </code><code class="php variable">$msg</code><code class="php plain">, </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$msg</code><code class="php plain">));</code></div>
<div class="line number48 index47 alt1" style="height: 16px;"> </div>
<div class="line number49 index48 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(</code><code class="php variable">$result</code><code class="php plain">)</code></div>
<div class="line number50 index49 alt1" style="height: 16px;"><code class="php spaces"> </code> </div>
<div class="line number51 index50 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">{</code></div>
<div class="line number52 index51 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$countOK</code><code class="php plain">++;</code></div>
<div class="line number53 index52 alt2" style="height: 16px;"><code class="php spaces"> </code> </div>
<div class="line number54 index53 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">}</code><code class="php plain">}</code></div>
<div class="line number55 index54 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">}</code></div>
<div class="line number56 index55 alt1" style="height: 16px;"> </div>
<div class="line number57 index56 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php comments">// Close the connection to the server</code></div>
<div class="line number58 index57 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">fclose(</code><code class="php variable">$fp</code><code class="php plain">);</code></div><div class="line number59 index58 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$countOK</code><code class="php plain">==</code><code class="php variable">$num</code><code class="php plain">)</code></div>
<div class="line number60 index59 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">TRUE;</code></div>
<div class="line number61 index60 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">else</code></div>
<div class="line number62 index61 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">return</code> <code class="php plain">FALSE;</code></div>
<div class="line number63 index62 alt2" style="height: 16px;"> </div>
<div class="line number64 index63 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">}</code></div>
</div>
</td>
</tr>
</tbody>
</table></div>
</div>
</div><p><span style="font-family: 宋体, SimSun; font-size: 18px;">後のプッシュで一連の問題を引き起こしたのは上記のコードでした。 </span></p>
<p><strong><span style="font-family: 宋体, SimSun; font-size: 18px;">最初の大きな問題は: </span></strong><span style="font-family: 宋体, SimSun; font-size: 18px;"> デフォルトでは、すべてのプッシュ トークンが有効です。実際、ユーザーがアプリを直接削除するか、アプリをアップグレードすると、バックグラウンド データベースの deviceToken が生成されない可能性があります。プッシュトークンを無効にします。ただし、誰かがドアベルを鳴らすと、バックグラウンドはそれを有効な deviceToken として扱い、$deviceTokens に含めます。期限切れの deviceToken をクリアする方法は考慮する必要がある問題です。 </span></p>
<p><span style="font-family: 宋体, SimSun; font-size: 18px;">関連情報を確認したところ、APNS サービスには </span><span style="font-weight: bold; line-height: 1.6; font-family: 宋体, SimSun; font-size: 18px;"></span><span id="_baidu_bookmark_start_11" style="display: none; line-height: 0px; font-family: 宋体, SimSun; font-size: 18px;"> というリンクがあり、それに関する情報はほとんどありません。グーグル。このサービスについて簡単に紹介します: </span><span style="font-family: 宋体, SimSun; font-size: 18px;">
</span> </p>
<p></p> APNS リモート プッシュを実行するときに、ユーザーがアプリをアンインストールしたためにプッシュが失敗した場合、APNS サーバーは deviceToken を記録し、リストに追加して、データベースから期限切れのプッシュ トークンを取得できます。これらの期限切れのトークンにより、次回のプッシュ時にプッシュ配列にトークンが追加されなくなる可能性があります。このサービスへの接続は非常に簡単で、開発環境が <p><code style="font-size: 13.39px; font-family:courier, consolas, monospace; color: であることを除いてプッシュ プロジェクトに似ています。 #666666; フォント -variant-ligatures: 通常; 孤児: 2; 背景色: #ffffff;"><span style="font-family: 宋体, SimSun; font-size: 18px;"></code></span>,テスト環境は <span style="font-family: 宋体, SimSun; font-size: 18px;"> </span><code style="font-size: 13.39px; font-family: courier, consolas, monospace; color: #666666; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; background-color: #ffffff;"><span style="font-family: 宋体, SimSun; font-size: 18px;">feedback.push.apple.com</span></code>フィードバック.sandbox.push.apple.com<span style="font-family: 'lucida grande', 'lucida sans unicode', helvetica, arial, verdana, sans-serif; font-size: 13px; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; background-color: #ffffff;"><span style="font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;">ポートはすべて 2196 です。 APNS サーバーから返されるデータ形式は次のとおりです: </span><span style="color: #666666; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;"><span style="color: #666666; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;"></span>
<span style="font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; color: #000000; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;"></span></span></span></p><p style="text-align: center;"><span style="font-family: 'lucida grande', 'lucida sans unicode', helvetica, arial, verdana, sans-serif; font-size: 13px; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; background-color: #ffffff;"><span style="color: #666666; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, simsun; font-size: 18px; background-color: #ffffff;"><span style="font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, simsun; font-size: 18px; color: #000000; background-color: #ffffff;"><img style="max-width:90%" src="http://images2015.cnblogs.com/blog/801509/201608/801509-20160815193218968-445182164.png" alt="" border="0" />
<br /> </span>
</span>
</span>
</p>
<p>
</p>
<div class="wiz-table-container" style="position: relative; padding: 15px 0px 5px;">
<div class="wiz-table-body">タイムスタンプ<table class="noBorderTable" style="border-top-color: #9BB3CD; border-left-color: #9BB3CD; color: #000000; font-family: 'lucida grande', 'lucida sans unicode', helvetica, arial, verdana, sans-serif; font-size: 13px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: #ffffff; margin-bottom: 4em;" border="0" cellspacing="0" cellpadding="5"></td>
<td style="padding: 0.667em; font-size: 13px; vertical-align: middle; border-bottom-color: #9BB3CD; border-right-color: #9BB3CD;">
<p style="font-stretch: normal; font-size: 13px;">アプリがデバイス上に存在しなくなったとAPNが判断した時期を示すタイムスタンプ(4バイトの<code style="font-size: 13.39px; font-family: courier, consolas, monospace; color: #666666;">time_t</code>値として)。 この値はネットワーク順であり、1970 年 1 月 1 日深夜 12:00 UTC からの秒数を表します。</p>
</td>
</tr>
<tr>
<td style="padding: 0.667em; font-size: 13px; vertical-align: middle; border-bottom-color: #9BB3CD; border-right-color: #9BB3CD;" scope="row">
<p style="font-stretch: normal; font-size: 13px;">トークンの長さ</p>
</td>
<td style="padding: 0.667em; font-size: 13px; vertical-align: middle; border-bottom-color: #9BB3CD; border-right-color: #9BB3CD;">
<p style="font-stretch: normal; font-size: 13px;">ネットワーク順序での 2 バイトの整数値としてのデバイス トークンの長さ。</p>
</td>
</tr>
<tr>
<td style="padding: 0.667em; font-size: 13px; vertical-align: middle; border-bottom-color: #9BB3CD; border-right-color: #9BB3CD;" scope="row">
<p style="font-stretch: normal; font-size: 13px;">デバイストークン</p>
</td>
<td style="padding: 0.667em; font-size: 13px; vertical-align: middle; border-bottom-color: #9BB3CD; border-right-color: #9BB3CD;">
<p style="font-stretch: normal; font-size: 13px;">バイナリ形式のデバイス トークン。</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<p><span style="font-family: 'lucida grande', 'lucida sans unicode', helvetica, arial, verdana, sans-serif; font-size: 13px; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; background-color: #ffffff;"><span style="color: #666666; font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;"><span style="font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; color: #000000; background-color: #ffffff;">このサービスを実行するために、CIフレームワークコントローラーを作成しました</span></span></span></p>
<p> </p>
<div id="highlighter_288709" class="syntaxhighlighter php">
<div class="wiz-table-container" style="position: relative; padding: 15px 0px 5px;">
<div class="wiz-table-body">
<table class="noBorderTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2" style="height: 16px;">1</div>
<div class="line number2 index1 alt1" style="height: 16px;">2</div>
<div class="line number3 index2 alt2" style="height: 16px;">3</div>
<div class="line number4 index3 alt1" style="height: 16px;">4</div>
<div class="line number5 index4 alt2" style="height: 16px;">5</div>
<div class="line number6 index5 alt1" style="height: 16px;">6</div>
<div class="line number7 index6 alt2" style="height: 16px;">7</div>
<div class="line number8 index7 alt1" style="height: 16px;">8</div>
<div class="line number9 index8 alt2" style="height: 16px;">9</div>
<div class="line number10 index9 alt1" style="height: 16px;">10</div>
<div class="line number11 index10 alt2" style="height: 16px;">11</div>
<div class="line number12 index11 alt1" style="height: 16px;">12</div>
<div class="line number13 index12 alt2" style="height: 16px;">13</div>
<div class="line number14 index13 alt1" style="height: 16px;">14</div>
<div class="line number15 index14 alt2" style="height: 16px;">15</div>
<div class="line number16 index15 alt1" style="height: 16px;">16</div>
<div class="line number17 index16 alt2" style="height: 16px;">17</div>
<div class="line number18 index17 alt1" style="height: 16px;">18</div>
<div class="line number19 index18 alt2" style="height: 16px;">19</div>
<div class="line number20 index19 alt1" style="height: 16px;">20</div>
<div class="line number21 index20 alt2" style="height: 31px;">21</div>
<div class="line number22 index21 alt1" style="height: 16px;">22</div>
<div class="line number23 index22 alt2" style="height: 16px;">23</div>
<div class="line number24 index23 alt1" style="height: 16px;">24</div>
<div class="line number25 index24 alt2" style="height: 16px;">25</div>
<div class="line number26 index25 alt1" style="height: 16px;">26</div>
<div class="line number27 index26 alt2" style="height: 16px;">27</div>
<div class="line number28 index27 alt1" style="height: 16px;">28</div>
<div class="line number29 index28 alt2" style="height: 16px;">29</div>
<div class="line number30 index29 alt1" style="height: 16px;">30</div>
<div class="line number31 index30 alt2" style="height: 16px;">31</div>
<div class="line number32 index31 alt1" style="height: 16px;">32</div>
<div class="line number33 index32 alt2" style="height: 16px;">33</div>
<div class="line number34 index33 alt1" style="height: 16px;">34</div>
<div class="line number35 index34 alt2" style="height: 16px;">35</div>
<div class="line number36 index35 alt1" style="height: 16px;">36</div>
<div class="line number37 index36 alt2" style="height: 16px;">37</div>
<div class="line number38 index37 alt1" style="height: 16px;">38</div>
<div class="line number39 index38 alt2" style="height: 16px;">39</div>
<div class="line number40 index39 alt1" style="height: 16px;">40</div>
<div class="line number41 index40 alt2" style="height: 16px;">41</div>
<div class="line number42 index41 alt1" style="height: 16px;">42</div>
<div class="line number43 index42 alt2" style="height: 16px;">43</div>
<div class="line number44 index43 alt1" style="height: 16px;">44</div>
<div class="line number45 index44 alt2" style="height: 16px;">45</div>
<div class="line number46 index45 alt1" style="height: 16px;">46</div>
<div class="line number47 index46 alt2" style="height: 16px;">47</div>
<div class="line number48 index47 alt1" style="height: 16px;">48</div>
<div class="line number49 index48 alt2" style="height: 16px;">49</div>
<div class="line number50 index49 alt1" style="height: 16px;">50</div>
<div class="line number51 index50 alt2" style="height: 16px;">51</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2" style="height: 16px;"><code class="php plain"><?php</code></div><div class="line number2 index1 alt1" style="height: 16px;"><code class="php plain">defined(</code><code class="php string">'BASEPATH'</code><code class="php plain">) OR </code><code class="php functions">exit</code><code class="php plain">(</code><code class="php string">'No direct script access allowed'</code><code class="php plain">);</code></div>
<div class="line number3 index2 alt2" style="height: 16px;"> </div>
<div class="line number4 index3 alt1" style="height: 16px;"><code class="php keyword">class</code> <code class="php plain">Admin </code><code class="php keyword">extends</code> <code class="php plain">CI_Controller {</code></div>
<div class="line number5 index4 alt2" style="height: 16px;"> </div>
<div class="line number6 index5 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">__construct()</code></div>
<div class="line number7 index6 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">{</code></div>
<div class="line number8 index7 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php plain">parent::__construct();</code></div>
<div class="line number9 index8 alt2" style="height: 16px;"><code class="php spaces"> </code><code class="php comments">// 加载数据库</code></div>
<div class="line number10 index9 alt1" style="height: 16px;"><code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->load->database();</code>
</div>
<div class="line number11 index10 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$this</code><code class="php plain">->load->model(</code><code class="php string">'apns_model'</code><code class="php plain">);</code>
</div>
<div class="line number12 index11 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number13 index12 alt2" style="height: 16px;"> </div>
<div class="line number14 index13 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">apnsfeedback()</code>
</div>
<div class="line number15 index14 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number16 index15 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$ctx</code> <code class="php plain">= stream_context_create();</code>
</div>
<div class="line number17 index16 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$passphrase</code> <code class="php plain">= </code><code class="php string">'xxxxx'</code><code class="php plain">;</code>
</div>
<div class="line number18 index17 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">stream_context_set_option(</code><code class="php variable">$ctx</code><code class="php plain">, </code><code class="php string">'ssl'</code><code class="php plain">, </code><code class="php string">'local_cert'</code><code class="php plain">, </code><code class="php string">'xxxxxxx.pem'</code><code class="php plain">);</code>
</div>
<div class="line number19 index18 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">stream_context_set_option(</code><code class="php variable">$ctx</code><code class="php plain">, </code><code class="php string">'ssl'</code><code class="php plain">, </code><code class="php string">'passphrase'</code><code class="php plain">, </code><code class="php variable">$passphrase</code><code class="php plain">);</code>
</div>
<div class="line number20 index19 alt1" style="height: 16px;"> </div>
<div class="line number21 index20 alt2" style="height: 31px;">
<code class="php spaces"> </code><code class="php variable">$fp</code> <code class="php plain">= stream_socket_client(</code><code class="php string">'ssl://feedback.push.apple.com:2196'</code><code class="php plain">, </code><code class="php variable">$error</code><code class="php plain">, </code><code class="php variable">$errorString</code><code class="php plain">, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, </code><code class="php variable">$ctx</code><code class="php plain">);</code>
</div>
<div class="line number22 index21 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">if</code> <code class="php plain">(!</code><code class="php variable">$fp</code><code class="php plain">) {</code>
</div>
<div class="line number23 index22 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php functions">echo</code> <code class="php string">"Failed to connect feedback server: $err $errstrn"</code><code class="php plain">;</code>
</div>
<div class="line number24 index23 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">return</code><code class="php plain">;</code>
</div>
<div class="line number25 index24 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number26 index25 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">else</code> <code class="php plain">{</code>
</div>
<div class="line number27 index26 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php functions">echo</code> <code class="php string">"Connection to feedback server OKn"</code><code class="php plain">;</code>
</div>
<div class="line number28 index27 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php functions">echo</code> <code class="php string">"<br>"</code><code class="php plain">;</code>
</div>
<div class="line number29 index28 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">}</code>
</div>
<div class="line number30 index29 alt1" style="height: 16px;"> </div>
<div class="line number31 index30 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php keyword">while</code> <code class="php plain">(</code><code class="php variable">$devcon</code> <code class="php plain">= </code><code class="php functions">fread</code><code class="php plain">(</code><code class="php variable">$fp</code><code class="php plain">, 38))</code>
</div>
<div class="line number32 index31 alt1" style="height: 16px;">
<code class="php spaces"> </code><code class="php plain">{</code>
</div>
<div class="line number33 index32 alt2" style="height: 16px;">
<code class="php spaces"> </code><code class="php variable">$arr</code> <code class="php plain">= unpack(</code><code class="php string">"H*"</code><code class="php plain">, </code><code class="php variable">$devc</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</tr>
</tbody>
</table>
</div>
</div>
声明:この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。