


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!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
