


Access the script interface.php implementation code, script interface.php_PHP tutorial
Access script interface.php to implement the code, script interface.php
Undertake the above WeChatCallBack
Fields that are common to various messages are defined in the member variables of the WeChatCallBack class, and these fields are assigned values in the init function. At the same time, the parsed XML object is also used as the member variable $_postObject of this class and assigned in init. The purpose is to obtain the special fields of specific types of messages when implementing the business logic of specific public accounts.
The process function is a function that needs to be overloaded when implementing the business logic of a specific public account. The default implementation is to return an "not implemented" error message.
The focus of this article is the access script. The access script is interface.php in the project root directory. The code list is as follows:
require_once dirname(__FILE__) . '/common/GlobalFunctions.php';
Function checkSingnature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = WEIXIN_TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = shal( $tmpStr );
if( $tmpStr == $signature ) {
return true;
} else {
return false;
}
}
if(checkSignature()) {
if($_GET["echostr"]) {
echo $_GET["echostr"];
exit(0);
}
} else {
// Malicious request: Get the source IP and write it to the log
$ip = getIp();
interface_log(ERROR, EC_OTHER, 'malicious: ' . $ip);
exit(0);
}
Function getWeChatObj($toUserName) {
if($toUserName == USERNAME_FINDFACE) {
require_once dirname(__FILE__) . '/class/
WeChatCallBackMeiri10futu.php' ;
return new WeChatCallBackMeir10futu();
}
if($toUserName == USERNAME_MR) {
require_once dirname(__FILE__) . '/class/
WeChatCallBackMeir10futu.php' ;
return new WeChatCallBackMeir10futu();
}
if($toUserName == USERNAME_ES) {
require_once dirname(__FILE__) . '/class/
WeChatCallBackEchoServer.php' ;
return new WeChatCallBackEchoServer();
}
require_once dirname(__FILE__) . '/class/WeChatCallBcak.php' ;
Return new WeChatCallBack();
}
function exitErrorInput() {
echo 'error input!' ;
Interface_log(INFO, EC_OK, "***** interface request end ******") ;
Interface_log(INFO, EC_OK, "********************** ******") ;
Interface_log(INFO, EC_OK, "") ;
exit( 0 );
}
$postStr = file_get_contents ( "php://input" );
interface_log(INFO, EC_OK, "");
interface_log(INFO, EC_OK, "******************************");
interface_log(INFO, EC_OK, "***** interface request start *****");
interface_log(INFO, EC_OK, 'request: ' . var_export($_GET, ture)) ;
if (empty ( $postStr )) {
Interface_log (ERROR, EC_OK, "error input!" );
exitErrorInput();
}
// Get parameters
$postObj = simplexml_load_string ( $postStr, 'SimpleXMLElement',
LIBXML_NOCDATA ) ;
$toUserName = ( string ) trim ( $postObj->ToUserName ) ;
if (! $toUserName) {
Interface_log ( ERROR, EC_OK, "error input!" ) ;
exitErrorInput() ;
} else {
$wechatObj = getWeChatObj ($ toUserName);
}
retStr = $ wechatObj->process ();
interface_log(INFO, EC_OK, "***** interface request end *****") ;
interface_log(INFO, EC_OK, "******************************") ;
interface_log(INFO, EC_OK, "");
?>
Interface.php logical description:
1. Use the checkSignature function to verify whether the request is legal. If it is illegal, record the malicious source IP.
2. Obtain the POST data, parse the XML data, determine which public account the message is sent to based on ToUserName, then load the corresponding file and obtain the corresponding object (getWeChatObj function).
3. Call the init function of the object to initialize the object.
4. Call the process function of the object to process the public account logic and get the return message string.
5. Return the message.
Get source IP function:
Function getIp ()
{
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"] ;
} else if (isser($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"] ;
} else {
$realip = $SERVER["REMOTE_ADDR"];
}
} else {
if (getenv(""HTTP_X_FORWARDED_FOR")) {
$realip = getenv("HTTP_X_FORWARDED_FOR") ;
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP") ;
} else {
$realip = getenv("REMOVE_ADDR") ;
}
}
return $realip;
}
___________over____________
is the short message access code for the mobile network information service business in the second type of value-added telecommunications business, which is divided into two categories: full network and ground network. The full network sp access code is the full network operational sp starting with 1066. Access codes, and non-commercial sp access codes starting with 1069 for the entire network; sp access codes for the ground network are divided into commercial sp access codes starting with 1062 and non-commercial sp access codes starting with 1063. The application agency for the SP access code for the whole network is the Ministry of Industry and Information Technology, and the application agency for the ground network access code is the local Communications Administration Bureau. So what materials need to be submitted to apply for the SP access code? sp access code application materials 1. Short message service access code application report (number length, scope of application, contact number); 2. Short message service access code (provincial use) application form; 3. Commitment letter for the use of short message service access codes; 4. Original and copy of value-added telecommunications business license (business category: short message service); 5. Original and copy of business license copy; 6. Technical plan, business plan, etc. .
The access code is different in each region
You can only dial 10086 to contact the manual service
Or you can tell me the location of the phone number so I can check it for you!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to execute .sh file in Linux system? In Linux systems, a .sh file is a file called a Shell script, which is used to execute a series of commands. Executing .sh files is a very common operation. This article will introduce how to execute .sh files in Linux systems and provide specific code examples. Method 1: Use an absolute path to execute a .sh file. To execute a .sh file in a Linux system, you can use an absolute path to specify the location of the file. The following are the specific steps: Open the terminal

Cutting is a video editing tool with comprehensive editing functions, support for variable speed, various filters and beauty effects, and rich music library resources. In this software, you can edit videos directly or create editing scripts, but how to do it? In this tutorial, the editor will introduce the method of editing and making scripts. Production method: 1. Click to open the editing software on your computer, then find the "Creation Script" option and click to open. 2. In the creation script page, enter the "script title", and then enter a brief introduction to the shooting content in the outline. 3. How can I see the "Storyboard Description" option in the outline?

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

As a programmer, I get excited about tools that simplify the coding experience. With the help of artificial intelligence tools, we can generate demo code and make necessary modifications as per the requirement. The newly introduced Copilot tool in Visual Studio Code allows us to create AI-generated code with natural language chat interactions. By explaining functionality, we can better understand the meaning of existing code. How to use Copilot to generate code? To get started, we first need to get the latest PowerPlatformTools extension. To achieve this, you need to go to the extension page, search for "PowerPlatformTool" and click the Install button

We've designed this Windows PowerShell scripting tutorial for beginners, whether you're a tech enthusiast or a professional looking to improve your scripting skills. If you have no prior knowledge of PowerShell scripting, this article will start with the basics and be tailored for you. We'll help you master the installation steps for a PowerShell environment and walk you through the main concepts and features of PowerShell scripts. If you're ready to learn more about PowerShell scripting, let's embark on this exciting learning journey together! What is WindowsPowerShell? PowerShell is a hybrid command system developed by Microsoft
