Home > WeChat Applet > Mini Program Development > How to set WeChat applet URL and token

How to set WeChat applet URL and token

小云云
Release: 2018-05-14 16:28:33
Original
10285 people have browsed it

This article mainly introduces relevant information on the detailed explanation of WeChat applet URL and token settings. I hope this article can help everyone solve similar problems. Friends in need can refer to it. I hope it can help everyone.

Detailed explanation of WeChat applet url and token settings

Create a weixin.php file in the code of Sina Cloud Application sae and write the following code

define("TOKEN","myToken");// 后台填写的token,在微信公众平台启用
$wechatObj = new wechatAPI();
$wechatObj->isValid();
class wechatAPI
{
  public function isValid()//验证微信接口,验证函数以外的代码和微信公众号开发token设置相同
  {
     $echoStr = $_GET["echostr"];
     if ($this->checkSignature()) {
       header('content-type:text');//add,一定要加入header
      echo $echoStr;
      exit;
     }
  }
  private function checkSignature()  //官方的验证函数
  {
     $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;
     }
  }
};
Copy after login

After saving, access via url, copy the url in the address bar, and write it into the WeChat public platform

In the development settings of the WeChat public platform, fill in the above to obtain The url and set token will automatically generate EncodingASEKey

Setting completed

Related recommendations:

Node.js access_token implements WeChat access and refresh examples

Vue uses token to jump to the login page after expiration

Token setting details

The above is the detailed content of How to set WeChat applet URL and token. For more information, please follow other related articles on the PHP Chinese website!

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