Full introduction to weibo fan platform development

Source: Internet
Author: User

The most convenient way to develop the weibo fan platform is to migrate it, but the weibo fan platform has made some changes.

From: http://open.weibo.com/wiki/%E5%BE% AE %E4%BF%A1%E5%BC%80%E5%8F%91%E8%80%85%E8%BF%81%E7%A7%BB%E6%8C%87%E5%8D%97

 

Developer Migration Guide

If you have developed a public platform before using the weibo fan service platform, we strongly recommend that you read this document to understand the details that need to be paid attention to during the migration process;


The developer migration problem was taken into account at the beginning of the design of the weibo fan service interface, so the migration cost is not high. However, developers still need to adapt to the following three differences:

Difference 1: Fill in the Token and Appkey when applying for the message interface.

When applying for a message interface, Weibo requires the developer to fill in the URL and Appkey, and requires the developer to fill in the URL and Token;


The Token is a random character entered by the developer. It is only used to "verify the URL validity;

The Appkey of Weibo is provided by the official Weibo team. It is used not only to verify the URL validity, but also to represent the developer's identity;


In the "verify URL validity" section, the AppSecret corresponding to the developer's Appkey is used to generate the signature. In other words, the signature field encryption process of Weibo is basically the same, the only difference is that the Token field used for encryption is replaced by the AppSecret field for Weibo;

Difference 2: access_token is generated in different ways and has different validity periods.

The access_token is obtained by calling the corresponding API through the AppID and AppSecret of the public account;

The access_token credential used for calling the weibo fan service interface is automatically returned by the powder server platform (for example) after the URL is verified successfully when the message interface is applied );

In addition, the access_token credential of the weibo fan service interface can also be obtained through the OAuth2.0 authorization interface of Weibo, but this is currently under development and is not yet available;

With regard to the validity period, the access_token is valid for 7200 seconds and developers need to constantly refresh it. However, the access_token credential of the weibo fan service interface is valid for one year, developers can re-bind or authorize the blue V account one year later;

Therefore, we can easily use the platform code on Weibo with slight changes.

The source code is posted below:

<? Php/*** Weibo fan interface * @ author caigen. li * @ email it@exynoz.com * @ date 2014-5-13 * Document reference * 1. http://open.weibo.com/wiki/%E5%BE% AE %E4%BF%A1%E5%BC%80%E5%8F%91%E8%80%85%E8%BF%81%E7%A7%BB%E6%8C%87%E5%8D%97*2. http://open.weibo.com/wiki/%E6%B6%88%E6%81%AF%E6%8E%A8%E9%80%81%E6%9C%8D%E5%8A%A1#.E6.B6.88.E6.81.AF.E6.8E.A8.E9.80.81.E6.9C.8D.E5.8A.A1.E6.A6.82.E8.BF.B0 * /// APPKEYdefine ("TOKEN", "XXXXXXXXX XXXXXXXX "); // APPSECRETdefine (" SECRET "," SECRET "); // access_token. After the url is verified, define (" ACTOKEN "," token ") is displayed on the developer page "); $ wechatObj = new weiboChatApi (); $ wechatObj-> valid (); class weiboChatApi {public function valid () {$ echoStr = $ _ GET ["echostr"]; // valid signature, option if ($ this-> checkSignature () {echo $ echoStr; exit ;}} public fun Ction responseMsg () {// get post data, May be due to the different environments $ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; // extract post dataif (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ fromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ keyword = trim ($ postObj-> Content); $ time = time (); $ textTpl = "<xml> <ToUserName> <! [CDATA [% s]> </ToUserName> <FromUserName> <! [CDATA [% s]> </FromUserName> <CreateTime> % s </CreateTime> <MsgType> <! [CDATA [% s]> </MsgType> <Content> <! [CDATA [% s]> </Content> <FuncFlag> 0 </FuncFlag> </xml> "; if (! Empty ($ keyword) {$ msgType = "text"; $ contentStr = "Welcome to weibo world! "; $ ResultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr;} else {echo" Input something... ";}} else {echo" "; exit ;}} private function checkSignature () {$ signature =$ _ GET [" signature "]; $ timestamp = $ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = SECRET; // different from, use APP_SECRET to verify $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ tmpArr, SORT_STR ING); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpStr = $ signature) {return true ;} else {return false ;}}}?>

The APPKEY and APPSECRET mentioned above can be obtained after the http://open.weibo.com/apps registers the application.

Very good lunk!

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.