Micro-channel public number of pit development must give up, must understand the knowledge points

1) to give up python example the development of the document. Since the document in case the code indentation serious, but there is a missing code will result in compilation problems.

Recommended for PHP, simple and approachable, to compile the code indentation errors unsuccessful and there is no trouble.

Tools to quickly build PHP environment (including databases MySQL, server Apache) recommendations: UPUPW.

 

2) The https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1472017492_58YV5 "1.4 Developer Basic Configuration" section, you need direct access to URL server coupled with some PHP code (developer configuration to), to verify the URL configuration without error. code show as below:

<?php
define("TOKEN", "你自定义的TOKEN值"); //TOKEN值
$wechatObj = new wechat();
$wechatObj->valid();
class wechat {
  public function valid() {
    $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);
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );
    if( $tmpStr == $signature ) {
      return true;
    } else {
      return false;
    }
  }
}
?>

  Note: Many places or people have said, "This code will only be verified once", but did not make it clear why "will only validate once," also did not say, "Can the future be deleted." In fact, have already said, it is the reason:

This code is used - URL to verify the configuration without error! Because the public will use the URL and Token number you set the code to access the page on the server, to get access is successful, the URL is valid, after the public use this number to the default URL.

In other words, the basic configuration where the developer after successful verification URL, this code or save this code file, you can deleted. Conversely, if you later modify the URL, you still have to re-establish this code to verify that the new URL-- is still that sentence, verification success deleted.

 

3) the text message reply passive DEMO: Reference https://www.cnblogs.com/PER10/p/11134138.html

Key Code:

// get POST data 
$ postStr = $ GLOBALS [ "HTTP_RAW_POST_DATA is"]; 

// POST of SimpleXML parsing XML data over 
$ postObj simplexml_load_string = ($ postStr, 'the SimpleXMLElement', LIBXML_NOCDATA); 

echo $ ResultStr;

  

Guess you like

Origin www.cnblogs.com/PER10/p/11134029.html