Messages api start

跳转到: 导航, 搜索
第22行: 第22行:
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
|-
 
|-
!width="20%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|校验参数字段
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|校验参数字段
 
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
 
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
!width="70%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
+
!width="75%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
{{rdes_args|signature|string|微博加密签名,signature结合了开发者的appsecret参数)和请求中的timestamp参数,nonce参数}}
+
{{rdes_args|signature|string|微博加密签名,signature结合了开发者的appsecret、和请求中的timestamp参数,nonce参数}}
 
{{rdes_args|timestamp|string|时间戳}}
 
{{rdes_args|timestamp|string|时间戳}}
 
{{rdes_args|nonce|string|随机数}}
 
{{rdes_args|nonce|string|随机数}}
第38行: 第38行:
  
 
<div style="border-radius:3px;padding:10px 10px;background-color:#F8F8F8;border:1px solid #CCC;line-height:150%;">
 
<div style="border-radius:3px;padding:10px 10px;background-color:#F8F8F8;border:1px solid #CCC;line-height:150%;">
将appsecret参数),timestamp参数,nonce参数进行字典排序后,将三个参数字符串拼接成一个字符串进行sha1加密
+
将开发者的appsecret,timestamp参数,nonce参数进行字典排序后,将三个参数字符串拼接成一个字符串进行sha1加密
 
</div>
 
</div>
  

2014年3月24日 (一) 11:50的版本

粉丝服务平台开发接口接入指南

本指南文档可以指导你完成使用『粉丝服务平台开发模式』的主要步骤。


第一步:申请消息接口

媒体、企业、个人认证帐号,在粉服平台网站,可点击进入『粉丝服务平台』高级功能,选择开启开发模式。


然后填写URL和APPKEY,其中URL是开发者用来接收微博消息服务器数据的接口URL。APPKEY为微博认证用户指定并授权要为其开发服务的开发者应用KEY,该APPKEY所对应的APP Secret,将用作生成签名(该签名会和接口URL中包含的签名进行比对,从而验证请求的安全性)。


第二步:验证URL有效性

在开发者首次使用事件推送服务时,需要先通过一次校验来和微博服务器建立首次连接,具体来说:


开发者提交信息后,微博消息服务器将发送GET请求到填写的URL上,GET请求携带四个参数:


校验参数字段 字段类型 字段说明
signature string 微博加密签名,signature结合了开发者的appsecret、和请求中的timestamp参数,nonce参数
timestamp string 时间戳
nonce string 随机数
echostr string 随机字符串


开发者收到请求后,首先通过加密后的signature参数来校验GET请求的真实性,如果确认此次GET请求来自微博服务器,原样返回echostr参数内容就可以成功建立首次连接,否则连接失败。


signature参数的加密规则为:

将开发者的appsecret,timestamp参数,nonce参数进行字典排序后,将三个参数字符串拼接成一个字符串进行sha1加密


function checkSignature() {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];	
        		
	$appsecret= appsecret;  //开发者的appsecret
	$tmpArr = array($appsecret, $timestamp, $nonce);
	sort($tmpArr, SORT_STRING);
	$tmpStr = implode( $tmpArr );
	$tmpStr = sha1( $tmpStr );
	
	if( $tmpStr == $signature ){
		return true;
	}else{
		return false;
	}
}


第三步:成为开发者

验证URL有效性成功后即接入生效,成为开发者。


建立首次连接后,后续每次微博事件推送时也都会带上signature、timestamp、nonce三个参数,开发者依然可以通过对signature的校验判断此条消息的真实性。校验方式与首次建立连接一致。


此后用户每次向微博认证帐号发送消息、或者产生自定义菜单点击事件时,响应URL将得到推送。


此外请注意,粉服平台开发接口只支持80接口。