WeChat third-party platform regularly receives component_verify_ticket, third-party platform ticket push _ PHP Tutorial

Source: Internet
Author: User
The third-party platform regularly receives component_verify_ticket and the third-party platform pushes ticket. The third-party platform regularly receives component_verify_ticket. the third-party platform ticket pushes background: obtains the third-party platform token (component_access_token), and adds the component_verify third-party platform to regularly receive component_verify_tick

Background:

The component_access_token parameter is added to obtain the third-party platform token. Component_verify_ticket is pushed to a third-party platform every 10 minutes by the public platform (the push starts only after the third-party platform is approved by the public account is created ).

Objectives:

Component_verify_ticket pushed by the receiving server

Documentation: (see open platform documentation)

Push component_verify_ticket protocol

After the third-party platform of the public account is created and approved, the server will"Authorization event receiving URL"Component_verify_ticket is pushed every 10 minutes. After receiving the push from ticket, the third-party platform also needs to decrypt it (for details, see [message encryption and decryption access guide]). after receiving the push, the success string must be directly returned.

Therefore, in the open platform management center, find the "authorization event receiving URL", such.

The POST request address for pushing component_verify_ticket is intercepted:

Http ://[Authorization event receiving URL]? Encrypt_type = aes
& Amp; timestamp = 1438521627
& Nonce = 33431792
& Msg_signature = xxxxxx
& Amp; signature = xxxxxxx

Request content format:


AppId
加密XML

Knowing the push xml format, the next step is to decrypt the xml, so I will continue to read the documentation (see the instructions on message encryption and decryption on the open platform)

For decryption, the public platform provides sample code in five languages: c ++, php, java, python, and c # (click to download)

Here, php receives component_verify_ticket based on the sample code of the PHP version (based on the CI framework)

1/** 2 * "authorization event receiving URL" receives component_verify_ticket 3 **/4 public function ticket () {5 require_once (DPL_LIBS. 'wx/wxBizMsgCrypt. php '); 6 $ wx = new WXBizMsgCrypt ($ this-> token, $ this-> encodingAesKey, $ this-> appId); 7 8 $ inputs = (object) array (9 'encryption _ type' => '', 10' timestamp' =>'', 11' nonce '=> '', 12 'MSG _ signature' => '', 13 'signature' =>'' 14); 15 foreach ($ inputs as $ key =>&$ value) {16 $ tmp = $ This-> input-> get ($ key); 17 if (! Empty ($ tmp) {18 $ value = $ tmp; 19} 20} 21 $ this-> save_key_value ('component _ verify_ticket_get ', json_encode ($ inputs )); 22 23 $ fp = fopen ("php: // input", "r"); 24 if (isset ($ fp )&&! Empty ($ fp) {25 $ this-> post_xml = stream_get_contents ($ fp); 26 if (empty ($ this-> post_xml) {27 return; 28} 29} 30 $ this-> save_key_value ('component _ verify_ticket_post ', $ this-> post_xml); 31 32 $ this-> xml = str_replace ('appid ', 'tousername', $ this-> post_xml); 33 34 $ msg_xml = ''; 35 $ errCode = $ wx-> decryptMsg ($ inputs-> msg_signature, $ inputs-> timestamp, $ inputs-> nonce, $ this-> xml, $ msg_xml); 36 37 $ componentVerifyTicket = $ this-> parse_xml ($ msg_xml, 'componentverifyticket '); 38 39 $ this-> save_key_value ('component _ verify_ticket', $ ComponentVerifyTicket); 40 if ($ errCode = 0) {41 echo "success "; 42} else {43} 44 return; 45}

Please note:

From http://www.cnblogs.com/wenki/p/4700828.html

Background: get the third-party platform token (component_access_token), added component_verify...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.