WeChat mini-app message push php Server Verification

Source: Internet
Author: User
Mini-app message push php Server Verification settings page ("settings"> "development settings "):


  1. Set server domain name
    For example: https://hosts.com
    Note the differences between http and https protocols.

  2. Set message push
    2.1 add the server interface test. php to your server. the content of the test. php interface is mainly used to verify whether the message is sent through the token. the code is shown in the official example:
    Define ("TOKEN", "xxxxx");/The token entered in the background
    $ WechatObj = new wechatAPI ();
    $ WechatObj-> isValid ();
    Class wechatAPI
    {
    Public function isValid () // verification interface. If yes, the echostr parameter sent from it is returned.
    {
    $ EchoStr = $ _ GET ["echostr"];
    If ($ this-> checkSignature ()){
    Echo $ echoStr;
    Exit;
    }
    }
    Private function checkSignature () // Official verification function
    {
    $ Signature = $ _ GET ["signature"];
    $ Timestamp = $ _ GET ["timestamp"];
    $ Nonce = $ _ GET ["nonce"];
    $ Token = TOKEN;
    $ TmpArr = array ($ token, $ timestamp, $ nonce );
    Sort ($ tmpArr, SORT_STRING );
    $ TmpStr = implode ($ tmpArr );
    $ TmpStr = sha1 ($ tmpStr );
    If ($ tmpStr = $ signature ){
    Return true;
    } Else {
    Return false;
    }
    }
    };

    2.2 set the background message push information of the applet
    URL (server address): https://hosts.com/xx/test.php
    Token: Any conforming string, as defined above "xxxxx"
    EncodingAESKey (message encryption key): (it is generated randomly and saved on your own. this encryption key is used for decryption)
    Message encryption method: select plaintext for the time being. you do not need to consider encryption and decryption.
    Data format: Select as needed.
    Submit. if there is no problem, it will succeed. (If there is a problem, you can use fake data to test it in a browser)

The above is the details of the php Server Verification for mini-app message push. For more information, see other related articles in the first PHP community!

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.