ImitateLogin adds a plug-in mechanism and the support of another social networking website.

Source: Internet
Author: User

ImitateLogin adds a plug-in mechanism and the support of another social networking website.

I have introduced imitate-login many times in my article. This is an open-source project that I have been maintaining recently, now we have added support for plug-ins and a new website (for some reason, it will be introduced at the end of the article; it will only appear in the blog ). Hope readers canStar & forkTo support me, and I will decide the time allocation accordingly.

Imitate-login now provides support for plug-ins. Currently, two sections use the plug-in mechanism to implement login and identify verification codes during login; the logon process only supports the MEF (Managed Extensibility Framework) mode, while the verification code recognition process supports the Thrift RPC (Apache Thrift), HTTP RESTful (POST/GET), and MEF modes. The following describes how to develop and configure these three plug-ins. All code is already in Extensions.

 

Thrift RPC

 

In the Imitate Login library, there is a class Thrift toperation generated through the Thrift file. If you are using other languages for development, generate the corresponding class through Thrift. The following describes how to use C # To develop plug-ins.

 

First, create a console application and add a class to inherit thritoperation. Iface and implement it. Here, return directly:

class demo : ThriftOperation.Iface{    public string Operation(OperationObj operationObj)    {        return "1234";    }}

 

Then add a method to the main function to create the Thrift Server:

static void Main(string[] args){    int port = 7801;    string str = ConfigurationManager.AppSettings["ServerPort"];    if (!string.IsNullOrEmpty(str))        int.TryParse(str, out port);    if (args != null && args.Length == 1)    {        int.TryParse(args[0], out port);    }    Start(port);}public static void Start(int port){    TServerSocket serverTransport = new TServerSocket(port, 0, false);    ThriftOperation.Processor processor = new ThriftOperation.Processor(new demo());    TServer server = new TSimpleServer(processor, serverTransport);    Console.WriteLine("Starting server on port {0} ...", port);    server.Serve();}

 

When using the plug-in, you must first start the plug-in program, and then merge the following configurations into the extension. conf file of the program running directory:

{    "ExtendType": 3,    "SupportSite": [2],    "Path": null,    "Host": "127.0.0.1",    "Port": 7801,    "UrlFormat": null,    "HttpMethod": null}

 

You can use PluginConfigBuild to generate a configuration file.


HTTP RESTful

 

Another plug-in method is implemented using the common Http RESTful API. If you use the GET method, you can only input one enumeration to indicate the website and one string as the parameter; if you use the POST method, you need to get an OperationObj class definition through Thrift. Of course, C # can be obtained by directly referencing the imitate-login library. The API compilation method is not described as follows. Next you need to merge the following configurations into the extension. conf file of the program running directory:

{    "ExtendType": 2,    "SupportSite": [6],    "Path": null,    "Host": null,    "Port": 0,    "UrlFormat": "http://localhost:2920/Mail/SendMail?loginSite={0}&imageUrl={1}",    "HttpMethod": "GET"}

 

MEF

 

MEF is a native plug-in mode provided by Microsoft after. NET 4.0. to use this method, you need to use the IMEFOperation class. You need to obtain it by referencing imitate-login. The demo code is as follows:

[Export(typeof(IMEFOperation))][ExportMetadata("loginSite", LoginSite.Baidu)]public class demo : IMEFOperation{    public string Operate(string imageUrl = "", Image image = null, params string[] param)    {        return "1234";    }}

 

In this way, you need to specify the location where the plug-in is stored in the configuration file. The location supports relative running directory or absolute directory; in this example, copy the dll generated by the plug-in to the Extensions directory under the program running directory. The configuration file is as follows:

{    "ExtendType": 1,    "SupportSite": [5, 1],    "Path": "Extensions",    "Host": null,    "Port": 0,    "UrlFormat": null,    "HttpMethod": null}

 

All configuration files can be generated using PluginConfigBuild. SupportSite is an enumeration array of supported login websites.

Now, what do you need to do first!

 

Some content will only be displayed in my blog. Please refer to the original website!

This article is from The NewIdea by Carey Tzou.
Address: http://www.tnidea.com/imitate-login-support-plugin-now.html
No full text or abstract reprinted without authorization!

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.