Codeigniter 프레임워크 기반 APNS 일괄 푸시—Ding Dong, 수량계 확인
- WBOY원래의
- 2016-08-18 08:57:581397검색
<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;">대부분의 온라인 튜토리얼은 휴대폰에서 작동합니다. 즉, 우리 회사에서 설계한 제품에서는 동일한 계정으로 메시지를 한 번에 푸시한다는 것입니다. 여러 대의 휴대폰에서 로그인이 가능합니다.(이론적으로는 백그라운드에 제한이 없기 때문에 셀 수 없을 정도입니다.) 또한 각 휴대폰에 해당하는 deviceToken도 다릅니다. , 기본 사용자는 기기를 다른 사용자와 공유할 수 있으며, 다른 사용자는 다른 기기에서 동시에 로그인할 수 있습니다. 누군가 초인종을 누르면 공유 사용자를 포함하여 로그인한 모든 사용자에게 메시지가 푸시되어야 합니다. 이는 다수의 휴대전화 단말에 일괄적으로 푸시되어야 한다는 의미이다. 물론 여기서 제시한 예는 그렇게 복잡하지 않습니다. 모든 문제는 하나의 질문으로 요약됩니다. 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></p>
<p><span style="font-family: 宋体, SimSun; font-size: 18px;">먼저 사용자의 푸시 토큰(deviceToken)을 저장할 데이터베이스를 설계합니다. 이 테이블에는 두 개의 필드만 있습니다. </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;">여기서는 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 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;">온라인 튜토리얼에 따르면 내 백엔드의 첫 번째 버전에서는 메시지가 대부분 한 번에 하나의 터미널로 푸시되었으며, 얻은 모든 deviceToken을 $deviceTokens 배열에 저장했습니다. 매개변수 $ message는 푸시해야 하는 메시지입니다. 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></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;"> 서비스가 있다는 걸 알게 됐습니다. 일부 정보에서는 Google에서 공식 웹사이트를 찾는 것이 더 신뢰할 수 있다고 언급했습니다. 이 서비스에 대한 간략한 소개는 다음과 같습니다. </span></p>
<p> </p>
<p><span style="font-family: 宋体, SimSun; font-size: 18px;">APNS 원격 푸시를 수행할 때 사용자가 앱을 제거하여 푸시가 실패하면 APNS 서버는 deviceToken을 기록하고 이를 목록에 추가하여 만료된 푸시 토큰을 얻을 수 있습니다. , 데이터베이스에서 이러한 잘못된 토큰을 지우면 다음 푸시 중에 푸시 배열에 추가되는 것을 방지할 수 있습니다. 이 서비스에 연결하는 방법은 매우 간단하며 푸시 프로젝트와 유사하지만 개발 환경 </span><span style="font-family: 宋体, SimSun; font-size: 18px;">은 </span><code style="font-size: 13.39px; 택배, consolas, 고정 폭; 색상: 일반; 줄 높이: 일반; 과부: #ffffff;"><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>feedback.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;">< /code><span style="font-variant-ligatures: normal; line-height: normal; orphans: 2; widows: 2; font-family: 宋体, SimSun; font-size: 18px; background-color: #ffffff;"></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>feedback.sandbox.push.apple.com<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> 포트는 모두 2196입니다. APNS 서버에서 반환되는 데이터 형식은 다음과 같습니다. </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;">
</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;">APN이 해당 앱이 기기에 더 이상 존재하지 않는다고 판단한 시점을 나타내는 타임스탬프(4바이트 <code style="font-size: 13.39px; font-family: courier, consolas, monospace; color: #666666;">time_t</code> 값)입니다. 네트워크 순서에 따른 이 값은 1970년 1월 1일 자정(UTC) 12시 이후의 초를 나타냅니다.</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>
성명:본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.