Home > Backend Development > PHP Tutorial > WeChat third-party platform regularly receives component_verify_ticket, and third-party platform ticket push_PHP tutorial

WeChat third-party platform regularly receives component_verify_ticket, and third-party platform ticket push_PHP tutorial

WBOY
Release: 2016-07-13 09:45:21
Original
1281 people have browsed it

WeChat third-party platform regularly receives component_verify_ticket, and third-party platform ticket push

Background:

Get the third-party platform token (component_access_token) and add the component_verify_ticket parameter. component_verify_ticket is continuously pushed by the public platform to the third-party platform every 10 minutes (the push will not start until the third-party platform has approved the creation of the public account).

Target:

Receive component_verify_ticket

pushed by WeChat server

Document description: (See WeChat Open Platform Documentation)

Push component_verify_ticket protocol

After the public account is created and approved by the third-party platform, the WeChat server will regularly push component_verify_ticket to its "Authorization event receiving URL" every 10 minutes. The third-party platform also needs to decrypt the ticket push after receiving it (see [Message Encryption and Decryption Access Guidelines] for details), and must directly return the string success after receiving it.

So look for “Authorization Event Receiving URL” in the Open Platform Management Center, as shown below.

Intercept the POST request address of component_verify_ticket pushed by WeChat:

http://[Authorization event receiving URL]?encrypt_type=aes
🎜>        &signature=xxxxxxx

Request content format:

                                                                                                                       xml>




After knowing the format of WeChat push xml, the next thing to do is to decrypt the xml, so continue reading the document (see WeChat Open Platform Message Encryption and Decryption Guide)

Regarding decryption, the WeChat public platform provides sample codes in 5 languages: c, php, java, python, c# (click to download)

Here is a sample code based on the PHP version to implement PHP receiving component_verify_ticket (based on CI framework)

Please indicate when sharing:
<span> 1</span>     <span>/*</span><span>*
</span><span> 2</span> <span>    *&ldquo;授权事件接收URL&rdquo;每隔10分钟接收component_verify_ticket
</span><span> 3</span> <span>    *</span><span>*/</span>
<span> 4</span>     <span>public</span> <span>function</span><span> ticket(){
</span><span> 5</span>         <span>require_once</span>(DPL_LIBS.'wx/wxBizMsgCrypt.php'<span>);
</span><span> 6</span>         <span>$wx</span> = <span>new</span> WXBizMsgCrypt(<span>$this</span>->token, <span>$this</span>->encodingAesKey, <span>$this</span>-><span>appId);
</span><span> 7</span> 
<span> 8</span>         <span>$inputs</span> = (<span>object</span>)<span>array</span><span>(
</span><span> 9</span>             'encrypt_type' => '',
<span>10</span>             'timestamp' => '',
<span>11</span>             'nonce' => '',
<span>12</span>             'msg_signature' => '',
<span>13</span>             'signature' => ''
<span>14</span> <span>            );
</span><span>15</span>         <span>foreach</span> (<span>$inputs</span> <span>as</span> <span>$key</span> => &<span>$value</span><span>) {
</span><span>16</span>             <span>$tmp</span> = <span>$this</span>->input->get(<span>$key</span><span>);
</span><span>17</span>             <span>if</span> (!<span>empty</span>(<span>$tmp</span><span>)){
</span><span>18</span>                 <span>$value</span> = <span>$tmp</span><span>;
</span><span>19</span> <span>            }
</span><span>20</span> <span>        }
</span><span>21</span>         <span>$this</span>->save_key_value('component_verify_ticket_get',json_encode(<span>$inputs</span><span>));
</span><span>22</span> 
<span>23</span>         <span>$fp</span> = <span>fopen</span>("php://input","r"<span>);
</span><span>24</span>         <span>if</span> (<span>isset</span>(<span>$fp</span>) && !<span>empty</span>(<span>$fp</span><span>)){
</span><span>25</span>             <span>$this</span>->post_xml = <span>stream_get_contents</span>(<span>$fp</span><span>);
</span><span>26</span>             <span>if</span> (<span>empty</span>(<span>$this</span>-><span>post_xml)){
</span><span>27</span>                 <span>return</span><span>;
</span><span>28</span> <span>            }
</span><span>29</span> <span>        }
</span><span>30</span>         <span>$this</span>->save_key_value('component_verify_ticket_post',<span>$this</span>-><span>post_xml);
</span><span>31</span> 
<span>32</span>         <span>$this</span>->xml = <span>str_replace</span>('AppId', 'ToUserName', <span>$this</span>-><span>post_xml);
</span><span>33</span> 
<span>34</span>         <span>$msg_xml</span> = ''<span>;
</span><span>35</span>         <span>$errCode</span> = <span>$wx</span>->decryptMsg(<span>$inputs</span>->msg_signature, <span>$inputs</span>->timestamp, <span>$inputs</span>->nonce, <span>$this</span>->xml, <span>$msg_xml</span><span>);
</span><span>36</span> 
<span>37</span>         <span>$componentVerifyTicket</span> = <span>$this</span>->parse_xml(<span>$msg_xml</span>,'ComponentVerifyTicket'<span>);
</span><span>38</span> 
<span>39</span>         <span>$this</span>->save_key_value('component_verify_ticket',<span>$componentVerifyTicket</span><span>);
</span><span>40</span>         <span>if</span> (<span>$errCode</span> == 0<span>){
</span><span>41</span>             <span>echo</span> "success"<span>;
</span><span>42</span>         }<span>else</span><span>{
</span><span>43</span> <span>        }
</span><span>44</span>         <span>return</span><span>;
</span><span>45</span>     }
Copy after login

Original text from http://www.cnblogs.com/wenki/p/4700828.html

http://www.bkjia.com/PHPjc/1042462.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/1042462.htmlTechArticleWeChat third-party platform regularly receives component_verify_ticket, third-party platform ticket push background: Obtain third-party platform token (component_access_token) , added component_verify...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template