. NET implements the interfaces of the weibo fan service platform and the. net fan service platform.

Source: Internet
Author: User
Tags openid

. NET implements the interfaces of the weibo fan service platform and the. net fan service platform.


 

[Article Index]

 

[1. Sina weibo fan service platform interface description]

I will not detail how to apply for the Sina weibo fan service platform. After Blue V certification, you can use the fan service platform. If you need to use the development mode to call the interface, you also need to create an application on the Weibo open platform. Select "microservice application"> "fan service platform" for the type. After the application is registered, you can get the AppKey and AppSecret of the application. Then, choose "Management Center"> "fan service"> "advanced functions" on Weibo to set it to the Development Mode. What is different from the public account is, when using the development mode, you need to customize the Token and add the Signature together with other parameters when verifying the message. When using the development mode, you need to fill inAppKey of the applicationAnd useCorresponding AppSecret. When setting up the weibo fan service platform for the first time, Weibo will verify the configured server address, that is, pass in the echostr parameter through the GET method, and then you need to return the parameter, of course, you can also verify the authenticity of the source.

The management interface of the weibo fan service platform is almost the same as that of the public account, and even icons are similar. The fan service platform is similar to the public account, and the bottom menu and message event push are the same. In comparison, the microblog user's uid is directly returned in the push information, instead of returning only the unique OpenID for the current application.

For the newly configured fan service platform, the message push interface is of the JSON type by default. However, Weibo also provides compatible XML interfaces, if you have developed a public account, you can reuse the code to a great extent. If you need to switch to a different format, please refer to the http://open.weibo.com/wiki/Eps/push/set_format documentation, You need to POST the access_token and format = xml parameters to the interface, it looks very complicated, in fact, the implementation is very simple, you can write or find a program that can POST the parameter, and the access_token does not need to be obtained through OAuth2.0, it is displayed directly on the Management page of The weibo fan service platform (valid for one year), for example.

String signature = Request. queryString ["signature"]; String timestamp = Request. queryString ["timestamp"]; String nonce = Request. queryString ["nonce"]; Boolean isRight = CheckSignature. check (signature, timestamp, nonce, "APP_SECRET ");

When the verification source is valid, you can use Senparc. weiXin. the MessageHandler of MP can process messages. Generally, we need to inherit this class to implement custom responses. For example, the following code can reply all messages sent by users to the "Default reply message ":

1 public class WeiboMessageHandler: MessageHandler <MessageContext> 2 {3 private ResponseMessageText responseMessage; 4 5 public WeiboMessageHandler (Stream inputStream) 6: base (inputStream) 7 {8 this. responseMessage = this. createResponseMessage <ResponseMessageText> (); 9} 10 11 public override IResponseMessageBase DefaultResponseMessage (IRequestMessageBase requestMessage) 12 {13 this. responseMessage. content = "Default reply message"; 14 return responseMessage; 15} 16}

Then, we can call MessageHandler through the following code in HttpHanlder to obtain the processed result and output it:

1 if (String. equals ("POST", Request. httpMethod. toUpperInvariant () // the POST method replies with information 2 {3 WeiboMessageHandler messageHandler = new WeiboMessageHandler (Request. inputStream); 4 messageHandler. execute (); 5 6 Response. output. write (messageHandler. responseDocument. toString (); 7}

In addition, in the inherited MessageHandler, you can use the following methods to implement different functions:

1. ireeclipsemessagebase OnTextRequest (RequestMessageText requestMessage): text message
2. ireeclipsemessagebase OnEventRequest (IRequestMessageEventBase requestMessage): event message
3. ireeclipsemessagebase OnEvent_ClickRequest (RequestMessageEvent_Click requestMessage): Click Event message in the menu.
4. ireeclipsemessagebase OnEvent_ViewRequest (RequestMessageEvent_View requestMessage): click the link message in the menu.
5. IResponseMessageBase OnEvent_SubscribeRequest (RequestMessageEvent_Subscribe requestMessage): the user subscribes to event messages.
6. IResponseMessageBase OnEvent_UnsubscribeRequest (RequestMessageEvent_Unsubscribe requestMessage): the user cancels the subscription to event messages.

For example, FromUserName can be obtained in each requestMessage, so only the unique OpenID of each application can be ensured, while the uid of the user can be obtained in Weibo. For text messages, the Content attribute in requestMessage can be used to obtain the text Content sent by the user, and different results are returned based on the different Content sent by the user; for Event messages, the Event type can be obtained through the Event attribute; for Menu click events and link messages, the EventKey attribute can indicate the name of the menu event and the Url address to jump to after clicking the menu, especially for click events, you can return different content based on different eventkeys. in the user's subscription and cancellation methods, you can write related tags in your own database. In addition to the above methods that can be reloaded, there are many methods that can be reloaded, for messages that are not processed independently (for example, if the corresponding method is not reloaded or processed elsewhere), messages in DefaultResponseMessage are returned by default.

It should be noted that in the weibo fan service platform, only four types of messages sent by users are Text, Image, Voice, and Position (Location, there are no Video or Link types. For event messages, there are the same subscribe, unsubscribe, and subscribe) and menu CLICK events (CLICK) and menu CLICK links (VIEW). Events that do not open the chat window automatically report geographical LOCATION information (LOCATION), but with more user attention (follow) and unfollow events.

 

[3. Handling of special Weibo events]

Senparc. WeiXin. MP uses a heavy load method to easily implement public accounts, but Weibo differs from the pushed information. It doesn't matter if there are few Weibo posts, but additional processing is required for two more Weibo events (paying attention to and canceling attention. Of course, modifying the source code of Senparc. WeiXin. MP is a solution, but the following method is required when NuGet is used for management or you do not want to modify the original code.

Because Senparc. weiXin. MP itself does not support the follow and unfollow types. Therefore, the correct Event attribute cannot be obtained through RequestMessage in MessageHandler or requestMessage in the OnEventRequest method, and its Event attribute is always "Enter, senparc. weiXin. by default, the MP will press Enter to process the event. Therefore, we need to read information from the raw data, such as the following code:

1 public override IResponseMessageBase OnEventRequest (IRequestMessageEventBase requestMessage) 2 {3 String key = this. requestDocument. root. element ("Event "). value. toLowerInvariant (); 4 5 switch (key) 6 {7 case "follow": // follow 8 return this. onEvent_FollowRequest (requestMessage); 9 case "unfollow": // cancel follow 10 return this. onEvent_UnfollowRequest (requestMessage); 11} 12 13 // other event processing Code 14 15 return base. onEventRequest (requestMessage); 16} 17 18 public IResponseMessageBase OnEvent_FollowRequest (IRequestMessageEventBase requestMessage) 19 {20 // process user attention event 21 22 return this. responseMessage; 23} 24 public IResponseMessageBase OnEvent_UnfollowRequest (IRequestMessageEventBase requestMessage) 25 {26 // process the user to cancel the follow event 27 28 return this. responseMessage; 29}

Of course, for older versions of Senparc. WeiXin. MP, an error occurs in the inheritance relationship of RequestMessageEventBase (RequestMessageEventBase should be implemented but not IRequestMessageEventBase ). When the event type system is not recognized, a null pointer error occurs when Execute MessageHanlder (). Update to the latest version 7.0.18 or later to solve this problem.

 

[Reference]


How to call the JAVA WebService Interface in. NET

Service reference can be added as long as wsdl is supported.

Net webservice interface problems

. Net, c # Is the selected development language
Xml should be an interface that uses xml data format for communication.
Webservice: the interface is implemented in the form of webservice, that is, the soap protocol.
Peanut shells, that is, domain name binding

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.