Heim > php教程 > php手册 > APNS-Batch-Push basierend auf dem Codeigniter-Framework – Ding Dong, überprüfen Sie den Wasserzähler

APNS-Batch-Push basierend auf dem Codeigniter-Framework – Ding Dong, überprüfen Sie den Wasserzähler

WBOY
Freigeben: 2016-08-18 08:57:58
Original
1379 Leute haben es durchsucht
<p><span style="font-family: 宋体, SimSun; font-size: 18px;"> Kürzlich gab es ein Problem mit dem Nachrichten-Push der drahtlosen Türklingel, die mein Teilzeitunternehmen erfolgreich per Crowdfunding finanziert hat. Infolgedessen können einige Benutzer die Push-Nachricht nicht empfangen, was schließlich wirklich beängstigend ist. Der von mir bereitgestellte Backend-Service wirkt sich auf den Ruf des Unternehmens aus. Lassen Sie mich kurz unsere Bedürfnisse vorstellen: Wenn jemand den Türklingelschalter außerhalb der Tür drückt, gibt der Türklingelschalter ein Signal aus. und das empfangende Gateway im Haus empfängt das Signal und sendet auch eine Nachricht an das Mobiltelefon des Benutzers. Das heißt, der Besitzer weiß, dass jemand gedrückt hat Türklingel zu Hause, wenn er nicht zu Hause ist. Das Problem, das hier im Hintergrund gelöst werden muss, besteht darin, einen Anbieter für APNS-Push aufzubauen, denn um Nachrichten an Apple-Mobiltelefone zu pushen, müssen sie gemäß dem von Apple entwickelten Mechanismus über einen eigenen Push-Server an Apples PUSH-Server gesendet werden Der Schwerpunkt meiner Einführung liegt hier nicht darin, wie man diese Plattform aufbaut. Es gibt bereits viele Tutorials im heimischen Internet. Sie können sich beispielsweise auf Folgendes beziehen: </span><span style="font-family: 宋体, SimSun; font-size: 18px;">Lernen Sie Schritt für Schritt, wie man iOS Push ausführt</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;">Die meisten Online-Tutorials sind sinnvoll, aber sie funktionieren auf einem Mobiltelefon. Ich meine, dass sie Nachrichten gleichzeitig an ein Mobiltelefon-Endgerät senden, das von unserem Unternehmen entwickelt wurde Sie können sich auf mehreren Mobiltelefonen anmelden (theoretisch unzählige, da ich im Hintergrund keine Einschränkungen habe). Darüber hinaus sind die Produkte des Unternehmens auch mit einer Sharing-Funktion ausgestattet , kann der Hauptbenutzer das Gerät mit anderen Benutzern teilen, und andere Benutzer können sich gleichzeitig auf verschiedenen Geräten anmelden. Wenn jemand an der Tür klingelt, muss eine Nachricht an alle angemeldeten Benutzer gesendet werden, einschließlich des teilenden Benutzers Dies bedeutet, dass es stapelweise auf viele Mobiltelefonterminals übertragen werden muss. Natürlich ist das Beispiel, das ich hier gegeben habe, nicht so kompliziert. Alle Probleme werden in einer Frage zusammengefasst: Geben Sie ein Array zum Speichern von DeviceToken an. </span><strong><span style="color: #ff0000; font-family: 宋体, SimSun; font-size: 18px;">Wie pusht APNS stapelweise an mehrere Benutzer?</span></strong></p> <p style="text-align: left;"><strong><span style="color: #ff0000;"> </span></strong></p> <p><span style="font-family: 宋体, SimSun; font-size: 18px;">Zuerst entwerfen wir eine Datenbank zum Speichern des Push-Tokens (deviceToken) des Benutzers. Der Einfachheit halber enthält diese Tabelle nur zwei Felder. </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"> <tbody> <tr> <td style="width: 50%;">client_id</td> <td style="width: 50%;">deviceToken</td> </tr> <tr> <td style="width: 50%;">1</td> <td style="width: 50%;">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</td> </tr> </tbody> </table> </div> </div> <p> </p> <p><span style="font-family: 宋体, SimSun; font-size: 18px;">Hier verwende ich das CodeIgniter3-Framework. Wir erstellen ein neues Modell, um Benutzer-DeviceToken-Daten zu verwalten. </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 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 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> </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> </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> </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> </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;">In der ersten Version meines Backends wurden den Online-Tutorials zufolge Nachrichten größtenteils jeweils an ein Terminal gesendet. Ich habe eine kleine Änderung vorgenommen und alle erhaltenen DeviceTokens im Array $deviceTokens gespeichert Der Parameter $ message ist die Nachricht, die gesendet werden muss. Verwenden Sie eine for-Schleife, um nacheinander ein DeviceToken zum Pushen aus dem Array zu entnehmen, und zählen Sie dann, und geben Sie „true“ zurück, wenn alle Pushvorgänge erfolgreich sind. Diese Methode schien keine Mängel aufzuweisen und der Test war erfolgreich, also ging ich direkt online (hauptsächlich, weil ich nicht erwartet hatte, dass das Unternehmen plötzlich ein solches Produkt herausbringen würde, was den Status der Push-Funktion sehr erhöhen würde. Ich habe immer gedacht, dass es optional ist). </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></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;">Es war der obige Code, der später eine Reihe von Push-Problemen verursachte. </span></p> <p><strong><span style="font-family: 宋体, SimSun; font-size: 18px;">Das erste große Problem ist: </span></strong><span style="font-family: 宋体, SimSun; font-size: 18px;">Alle Push-Tokens sind hier standardmäßig gültig, aber tatsächlich kann es dazu kommen, dass der Benutzer die App oder das App-Upgrade direkt löscht deviceToken in der Backend-Datenbank nicht aktualisiert werden, wodurch das Push-Token ungültig wird. Aber wenn jemand an der Tür klingelt, wird es vom Hintergrund immer noch als gültiges DeviceToken behandelt und in $deviceTokens eingefügt. Wie das abgelaufene DeviceToken gelöscht werden kann, ist ein Problem, das berücksichtigt werden muss. </span></p> <p><span style="font-family: 宋体, SimSun; font-size: 18px;">Nachdem ich die relevanten Informationen überprüft hatte, stellte ich fest, dass der APNS-Dienst über einen </span><span style="font-weight: bold; line-height: 1.6; font-family: 宋体, SimSun; font-size: 18px;">Feedback-Service</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;"> verfügt. Inländische Blogs ignorieren diesen Link grundsätzlich Sehr wenige In einigen Informationen wurde erwähnt, dass es zuverlässiger ist, eine offizielle Website bei Google zu finden. Hier finden Sie eine kurze Einführung in diesen Service: </span></p> <p> </p> <p><span style="font-family: 宋体, SimSun; font-size: 18px;">Wenn beim Ausführen eines APNS-Remote-Push der Push fehlschlägt, weil der Benutzer die App deinstalliert hat, zeichnet der APNS-Server das DeviceToken auf und fügt es einer Liste hinzu. Sie können diese Liste abfragen, um das abgelaufene Push-Token zu erhalten. Durch das Löschen dieser ungültigen Token aus der Datenbank kann verhindert werden, dass sie beim nächsten Push zum Push-Array hinzugefügt werden. Die Verbindung zu diesem Dienst ist sehr einfach und ähnelt dem Push-Projekt, außer dass die Adresse anders ist. </span><span style="font-family: 宋体, SimSun; font-size: 18px;"> ist </span><code style="font-size: 13.39px; font-family: Courier, Konsolen, Monospace; Schriftvarianten: normal; Waisen: 2; Hintergrundfarbe: #ffffff; .com<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>< /code><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;">, die Testumgebung ist </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;">feedback.sandbox.push.apple.com</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;"> Ports sind alle 2196. Das vom APNS-Server zurückgegebene Datenformat ist: </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"> <tbody> <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;">Zeitstempel</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;">Ein Zeitstempel (als Vier-Byte-<code style="font-size: 13.39px; font-family: courier, consolas, monospace; color: #666666;">time_t</code>-Wert), der angibt, wann APNs festgestellt haben, dass die App nicht mehr auf dem Gerät vorhanden ist. Dieser Wert, der in der Reihenfolge des Netzwerks angegeben ist, stellt die Sekunden seit 12:00 Uhr Mitternacht am 1. Januar 1970 UTC dar.</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;">Tokenlänge</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;">Die Länge des Gerätetokens als Zwei-Byte-Ganzzahlwert in Netzwerkreihenfolge.</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;">Gerätetoken</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;">Das Gerätetoken im Binärformat.</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;">Um diesen Dienst auszuführen, habe ich einen CI-Framework-Controller geschrieben </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>
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage