WeChat Development Learning diary (8): 7 Steps to understand the weiphp plug-in mechanism, the core goal is to respond to WeChat requests, 7 Steps weiphp

Source: Internet
Author: User

Development and Learning diary (8): Read the weiphp plug-in mechanism in Step 7. The core goal is to respond to requests and Step 7 weiphp
After several hours of organization and review, we have finally understood the mechanism of weiphp. To fully understand it, it will naturally take a lot of time.


Step 2:
Configure public number, http://weiphp.jiutianniao.com/... html

From the above configuration, we can see that the index. php file of the weiphp entry file has received the request and may be responded to by the/home/weixin/index/action.

Step 2:
The index. php entry file verifies whether it is a request.
/**
* Access Verification
* Verify the URL at the entry instead of in the framework, mainly to solve the problem of URL verification timeout.
*/
If (! Empty ($ _ GET ['echostr']) &! Empty ($ _ GET ["signature"]) &! Empty ($ _ GET ["nonce"]) {
}

Step 2:
The entry has been verified, that is, not the "First time". The request will be distributed to the WeixinController index method of the home module.

Step 2:
In the index method, the information such as the token, openid, and fans is obtained first.
The most critical process is to reply to Data.
// Reply to data
$ This-> reply ($ data, $ weixin );

Step 2:
In the reply function, it is to find a suitable plug-in for message response.

The problems involved are plug-ins installed, enabled, and authorized.

After the available plug-ins are prepared, find appropriate plug-ins Based on the message type, events, geographical location, and subscription. For example, if there is a location event, the plug-in will execute the corresponding callback method.

There is also a message.

Reply to the message based on the keyword.

At this time, the problem becomes plug-in locating.

A. You can use the plug-in Identification name, plug-in name, or custom keywords to locate the plug-in to be processed.
B. The plug-in token = 0 is the fuzzy keyword initialized during plug-in installation. All public accounts can be used.
C. Use Fuzzy keywords to locate the processing plug-in
D. The plug-in cannot be located and the operation is terminated.

Question: There are many plug-ins that can process events such as location through code. The message only finds one plug-in. Is that the case?

Step 2:
Weixinmodel of the plug-in.

/**
* Vote Model
*/
Class WeixinAddonModel extends WeixinModel {
Function reply ($ dataArr, $ keywordArr = array ()){
}

Plug-ins, there will basically be a WeixinModel class, if necessary, will respond to the request.

Step 2:
URL response.

There is always a doubt in this place. If the so-called plug-in mechanism is to send a keyword to different class-plug-ins for response, it is too "golden. Is this the core gameplay?

Class VoteController extends AddonsController {
}

Each plug-in may have a Controller that responds to URL requests. For example, there are some management methods and settings for background management and foreground management (which do not directly interact with each other.

In addition, some reply methods in weixinModel may contain URLs defined in the plug-in, which makes it very valuable.

Conclusion: The weiphp framework is simply summarized as 4 points.
1. weiphp is based on Thinkphp and Onethink. Whether weiphp has changed the core code of Thinkphp and Onethink. If there is any change, the Onethink should be changed more.
2. The core entry of weiphp is the index. php and/home/weixin/index methods to verify and respond to requests.
3. The plug-in mechanism is to find the plug-in based on the keyword to let the plug-in respond to the request.
4. the backend management system, client-side front-end management, and plug-in mechanism are all for the core goal of the Framework to "respond to requests ".
This is the most important part.

Wuhan jiutian bird-a leading mobile internet system developer in Wuhan
9 days bird Q & A-http://ask.jiutianniao.com
Nine days bird blog-http://blog.jiutianniao.com
Nine-day bird official website-construction in progress, coming soon
April 17, 2015

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.