Home  >  Article  >  WeChat Applet  >  Mini program message push configuration case

Mini program message push configuration case

angryTom
angryTomforward
2020-03-07 10:27:294006browse

This article introduces the configuration method of the message push capability of the WeChat mini program. I hope it will be helpful to friends who are learning mini program development!

Mini program message push configuration case

Mini program message push configuration case

In order to enrich the service capabilities of the mini program and improve service quality, WeChat is The Mini Program provides customer service messaging capabilities so that Mini Program users can communicate with the Mini Program service provider conveniently and quickly. After enabling and setting the message push configuration, messages sent by users to the mini program and event push required by developers will be forwarded to the server address by WeChat. Let's take a look at how to configure this. This is a case rendering of my own configuration.

Recommended learning: Small program development

Mini program message push configuration case

I define the api.php file in the root directory of my server, and fill in the address of the URL For http://www.100txy.com/api.php, the specific code of the file api.php is as follows

<?php
define("TOKEN","100txy");// 后台填写的token
$wechatObj = new wechatAPI();
$wechatObj->isValid();
class wechatAPI
{
  public function isValid()//验证微信接口,如果确认是微信就返回它传来的echostr参数
  {
     $echoStr = $_GET["echostr"];
     if ($this->checkSignature()) {
     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;
   }
  }
};

After configuration and submission, it can be enabled successfully!

For more related tutorials, please pay attention to PHP Chinese website!

The above is the detailed content of Mini program message push configuration case. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.100txy.com. If there is any infringement, please contact admin@php.cn delete