Easy to mistake, notice the name of the plugin
1, create the plugin. Create idiom Solitaire plugin in weiphp admin background, tick enable immediately after installation, do not need configuration item and manage list. Click OK to complete the creation of the plugin.
2, install the plug-in.
3. Check whether the plug-in is installed successfully. Back to the weiphp plug-in management background, you can see the idiom solitaire plugin has been successfully installed, because the plugin is not checked when the need to configure the item, so there is no plug-in configuration page shown here.
4, write the response code. First, let's debug the interface of the idiom solitaire.
From the debug results we can find that to enable users to complete the idiom solitaire, must be repeated to obtain the user's input keyword, when the user entered the "idiom Solitaire" started triggering the plug-in, prompting the user to enter an idiom, and then get the user's next input, the user's next input submitted to the idiom Solitaire interface address, Use the file_get_contents () function to get the content returned by the interface, if the interface return content is an idiom, then continue to obtain the user's next input, and the user input keyword submitted to the interface, according to this law cycle, multiple access to the user's input keywords If the content returned by the interface is not an idiom, such as a "idiom must be 4 Chinese characters" such as a prompt, then reply to the user's message prompts the user to re-enter an idiom or enter "exit" to exit the idiom solitaire; When the user enters the keyword "exit", then exit the idiom solitaire plugin, The user's next input will not be submitted to the idiom solitaire interface.
The development of the entire interactive model we figured out, and then began to write code, the most critical of which is to use the weiphp package of a function set_user_status (), the function of the location and usage:
The approximate meaning of this function is to store the user's input as a cache and associate it with the user's next input, thus completing a coherent input operation. The usage is simple, the first parameter passed is the name of the plug-in, and the second parameter passed is a custom keyword.
5: Let's use this function to write a coherent input operation:
<?php namespace Addons\idioms\model; UseHome\model\weixinmodel; /** * Model of idioms*/classWeixinaddonmodelextendsweixinmodel{functionReply$DATAARR,$KEYWORDARR=Array()) { $config= Getaddonconfig (' idioms ');//get configuration parameters for the background plug-in $api= ' Http://i.itpk.cn/[email protected] '; if($DATAARR[' Content '] = = ' Idiom Solitaire ' | |$DATAARR[' Content '] = = ' Idioms ' | |$DATAARR[' Content '] = = ' 3 ') { $KEYWORDARR[' step '] = ' input '; Set_user_status (' Idioms ',$KEYWORDARR);//Cache Custom Keywords $this->replytext (' Please input an idiom, such as: Lead '); } if($KEYWORDARR[' step '] = = ' input ') { if($DATAARR[' Content '] = = ' exit ') { $this->replytext (' You have quit idiom Solitaire, once again reply to "idiom Solitaire" can enter ~); return false; } $reply=file_get_contents($api.$DATAARR[' Content ']); if($reply= = ' Don't come to deceive home, not casually dozen 4 words is the idiom da! ' | |$reply= = ' idiom must be 4 Kanji ') { $KEYWORDARR[' step '] = ' input '; Set_user_status (' Idioms ',$KEYWORDARR); $this-Replytext ($reply." \ n "." Re-enter an idiom to start solitaire, enter "Exit" to exit the idiom solitaire '); } Else { $KEYWORDARR[' step '] = ' input '; Set_user_status (' Idioms ',$KEYWORDARR); $this->replytext ($reply); } } }}
5, Test.
Talk about weiphp public platform development--1, idioms Solitaire Plugin