php网站开发安全,手机扁平化网站模版,seo关键词排名查询,wordpress搜索 s=一、如何注册 为什么要注册#xff1f;访问 OpenAPI必须拥有Consumer Key和Consumer Secret。 如何注册#xff1f;要获取Consumer Key及Consumer Secret#xff0c;需要消费方#xff08;Consumer#xff09;向服务提供方申请注册#xff0c;服务提供方审核通过后会向消… 一、如何注册 为什么要注册访问 OpenAPI必须拥有Consumer Key和Consumer Secret。 如何注册要获取Consumer Key及Consumer Secret需要消费方Consumer向服务提供方申请注册服务提供方审核通过后会向消费方分配Consumer Key和Consumer Secret 注册时需提供什么信息消费方注册时需要向服务提供方提供以下信息 条目说明消费方名称第三方名称消费方电子邮箱API变化时方便通知消费方OAuth请求URL地址 消费方进行OAuth验证获取令牌及密钥的请求URL地址不包含参数部分 如http://youwebsite/request_token消费方OAuth回调URL地址 消费方OAuth验证通过后的回调URL地址不包含参数部分 如http://youwebsite/request_token_ready 二、如何签名 对 OpenAPI 进行REST请求时有如下几种参数 API方法api_method不需签名参数UnSignArguments需签名参数SignArguments签名api_signature注意各参数值需要进行url encode编码尤其中文时 调用API时需要对第3种参数进行签名签名步骤如下 No.说明1所有需签参数名称必须小写2所有参数值要进行url encode编码尤其中文时,把编码结果转小写3签名参数按字母升序排序4合成签名字符串合成时把“签名密钥”放到最前面然后把已排序的需签名参数清单按照“参数名称参数值”的方式追加到字符串5对合成的签名字符串进行 UTF8 编码6用MD5对签名字符串进行加密生成32位签名第4步合成签名串规则如下 签名密钥参数名称参数值参数名称参数值...... 关于签名密钥的特殊说明 调用API使用的签名密钥OpenAPI.OAuth.RequestTokenoauth_consumer_secretOthersoauth_token_secret UTF8编码及MD5加密的C#参考实现代码如下 using System.Security;using System.Security.Cryptography;using System.Text; //MD5加密public static string GetMd5String(string str){// First we need to convert the string into bytes which// means using a text encoder.byte[] unicodeText System.Text.Encoding.UTF8.GetBytes(str);// Now that we have a byte array we can ask the CSP to hash itMD5 md5 new MD5CryptoServiceProvider();byte[] result md5.ComputeHash(unicodeText);// Build the final string by converting each byte// into hex and appending it to a StringBuilderStringBuilder sb new StringBuilder();for (int i 0; i result.Length; i){sb.Append(result[i].ToString(x2));}// And return itreturn sb.ToString();} 三、请求REST格式 请求REST格式由以下几部分组成 请求REST地址如 http://youserverwebsite/api/rest调用API方法如 ?api_methodOpenAPI.OAuth.RequestToken不需签名参数如 oauth_consumer_key*************需签名参数如 oauth_timestamp****oauth_nonce****oauth_version****签名如 api_signature**** 完整请求REST串 http://youserverwebsite/api/rest? api_methodOpenAPI.oauth.requesttoken oauth_consumer_key**** oauth_noncea65c5e5e903942a994bcb07250431e2b oauth_timestamp1277216551 oauth_version1.0 api_signature6431e9d5b8508a2177920e8c3c624b1b 四、请求REST返回格式 请求REST返回格式为xml格式或者json格式目前仅支持xml格式示例如下 rsp methodopenapi.oauth.authorizetoken flagTrue code descok data token4941c6de38650e58e75a1536d847c2b6/token token_secretc48bcf5ba5166a5b5c409e233811025b/token_secret /data/rsp返回结果格式说明 参数名称备注说明method请求的API方法名称flag请求成功与否标识true成功false失败code结果状态码desc结果说明data结果数据 [返回导航] 转载于:https://www.cnblogs.com/liuxiaojun/archive/2010/09/03/openapi_plot.html