JIYIK CN >

Current Location:Home > Learning > NETWORK >

WeChat public account development tutorial interface configuration and identity authentication

Author:JIYIK Last Updated:2025/03/16 Views:

To become a developer of WeChat official account, you must first have a server that can be accessed externally. The development of WeChat official account does not limit the use of any language. Here we use PHP as the development language.

Interface access configuration

After logging in to the WeChat public platform official website, click the "Modify Configuration" button on the public platform backend management page - Developer Center page , and fill in the server address (URL), Token, and EncodingAESKey, where the URL is the interface URL used by developers to receive WeChat messages and events. The Token can be filled in arbitrarily by the developer and used to generate the signature (the Token will be compared with the Token contained in the interface URL to verify security). The EncodingAESKey is filled in manually by the developer or randomly generated, and will be used as the encryption and decryption key for the message body.

At the same time, developers can choose the message encryption and decryption mode: plain text mode, compatible mode and secure mode. The mode selection and server configuration will take effect immediately after submission. Developers are requested to fill in and select carefully. The default state of the encryption and decryption mode is plain text mode. Selecting compatible mode and secure mode requires configuring the relevant encryption and decryption code in advance. For details, please refer to the document on message body signature and encryption and decryption.

Authentication

After filling in the interface information, we start to authenticate the identity and verify the validity of the server. After we submit the information, the WeChat server will send a GET request to the URL we filled in above. In the URL address filled in above, we can see that we filled in a PHP file. Yes, we use this PHP file for verification.

Some verification codes are as follows

public function valid(){
     $echoStr = $_GET["echostr"];
 //valid signature , option
     if($this->checkSignature()){
        echo $echoStr;
        exit;
     }
}
private function checkSignature(){
    // you must define TOKEN by yourself
    if (!defined("TOKEN")) {
        throw new Exception('TOKEN is not defined!');
    }
    $signature = $_GET["signature"];
    $timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
         $tmpArr = array($token, $timestamp, $nonce);
    // use SORT_STRING rule
         sort($tmpArr, SORT_STRING);
         $tmpStr = implode( $tmpArr );
         $tmpStr = sha1( $tmpStr );
         if( $tmpStr == $signature ){
                   return true;
         }else{
                   return false;
         }
}

From the above code we can see that the WeChat server will send four parameters to our server address, namely:

signature WeChat encrypted signature, signature combines the token parameter filled in by the developer and the timestamp parameter and nonce parameter in the request.
timestamp timestamp
nonce random number
echostr random string

So where does the token come from? The token here is the field below the Token URL that we filled in above. So we need to define the token constant in our verification code

define("TOKEN","The token we filled in"); //Note that the value here must be consistent with what we filled in above

php complete code download

After our verification code is ready, submit the information, and we will be surprised to see that the configuration is successful at the top.

After the access is successful, we need to think about enabling our interface, and then we can achieve the desired effect according to the development documentation.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

PHP+ajax to achieve cross-domain single sign-on

Publish Date:2025/03/16 Views:145 Category:NETWORK

We have previously introduced the principle of cross-domain single sign-on in "Detailed explanation of the implementation methods of three situations of SSO single sign-on" . Here we will introduce how to implement single sign-on using PHP

HTTP2 Tutorial - How to use HTTP/2 with HTTPS

Publish Date:2025/03/16 Views:84 Category:NETWORK

HTTPS is used to build ultra-secure networks connecting computers, machines, and servers to handle sensitive business and consumer information. HTTP/2 browser support includes HTTPS encryption, which actually complements the overall securit

微信公众号接收消息 事件消息处理

Publish Date:2016/10/18 Views:4674 Category:网络

事件消息分为关注/取消关注、扫描带参数的二维码、上报地理位置、自定义菜单、点击菜单拉取消息、点击菜单跳转链接共六种事件。

微信公众号接收消息 普通消息处理

Publish Date:2016/10/14 Views:2385 Category:网络

在微信用户和公众号产生交互的过程中会分为两种情况:一种是微信用户向公众号发送普通消息;另一种是微信用户的某些操作使得微信服务器通过事件推送的形式通知到开发者填写的

微信公众号开发教程获取access_token

Publish Date:2016/10/12 Views:4442 Category:网络

在微信公众号开发过程中,如果我们想要主动向微信服务器推送消息那么我们必须要有access_token。access_token 是公众号的唯一票据。这里我们介绍获取access_token的方法及使用案例。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial