开发者社区> 问答> 正文

HTTP协议及签名怎么实现?(1)


为方便其它语言能快速实现,在此增加了HTTP的详解
注:云通信下的三类产品(包括短信、语音、流量),接口协议一致

一、前言说明


三类产品平台都提供了调用API和消息回执的交互 举例如:

  1. 通过调用短信的发送API,来成功发送短信

  2. 平台成功收到请求后发送给运营商,等用户最终收到短信后,平台会有最终的状态消息确认,就是消息回执
    对应的协议是:
    • 发送API采用Rest协议:签名算法使用了阿里云的POP协议
    • 发送后消息回执:采用的是阿里云的消息中间件MNS来实现


二、协议说明


由于POP的签名算法比较复杂,下面这里结合短信的发送API一并详细说明

2.1 短信发送API的HTTP协议包示例


请求示例:
  1. [backcolor=transparent]GET [backcolor=transparent]/?[backcolor=transparent]Signature[backcolor=transparent]=[backcolor=transparent]zJDF[backcolor=transparent]%[backcolor=transparent]2BLrzhj[backcolor=transparent]%[backcolor=transparent]2FThnlvIToysFRq6t4[backcolor=transparent]%[backcolor=transparent]3D[backcolor=transparent]&[backcolor=transparent]AccessKeyId[backcolor=transparent]=[backcolor=transparent]testId[backcolor=transparent]&[backcolor=transparent]Action[backcolor=transparent]=[backcolor=transparent]SendSms[backcolor=transparent]&[backcolor=transparent]Format[backcolor=transparent]=[backcolor=transparent]XML[backcolor=transparent]&[backcolor=transparent]OutId[backcolor=transparent]=[backcolor=transparent]123[backcolor=transparent]&[backcolor=transparent]PhoneNumbers[backcolor=transparent]=[backcolor=transparent]15300000001[backcolor=transparent]&[backcolor=transparent]RegionId[backcolor=transparent]=[backcolor=transparent]cn[backcolor=transparent]-[backcolor=transparent]hangzhou[backcolor=transparent]&[backcolor=transparent]SignName[backcolor=transparent]=%[backcolor=transparent]E9[backcolor=transparent]%[backcolor=transparent]98[backcolor=transparent]%[backcolor=transparent]BF[backcolor=transparent]%[backcolor=transparent]E9[backcolor=transparent]%[backcolor=transparent]87[backcolor=transparent]%[backcolor=transparent]8C[backcolor=transparent]%[backcolor=transparent]E4[backcolor=transparent]%[backcolor=transparent]BA[backcolor=transparent]%[backcolor=transparent]91[backcolor=transparent]%[backcolor=transparent]E7[backcolor=transparent]%[backcolor=transparent]9F[backcolor=transparent]%[backcolor=transparent]AD[backcolor=transparent]%[backcolor=transparent]E4[backcolor=transparent]%[backcolor=transparent]BF[backcolor=transparent]%[backcolor=transparent]A1[backcolor=transparent]%[backcolor=transparent]E6[backcolor=transparent]%[backcolor=transparent]B5[backcolor=transparent]%[backcolor=transparent]8B[backcolor=transparent]%[backcolor=transparent]E8[backcolor=transparent]%[backcolor=transparent]AF[backcolor=transparent]%[backcolor=transparent]95[backcolor=transparent]%[backcolor=transparent]E4[backcolor=transparent]%[backcolor=transparent]B8[backcolor=transparent]%[backcolor=transparent]93[backcolor=transparent]%[backcolor=transparent]E7[backcolor=transparent]%[backcolor=transparent]94[backcolor=transparent]%[backcolor=transparent]A8[backcolor=transparent]&[backcolor=transparent]SignatureMethod[backcolor=transparent]=[backcolor=transparent]HMAC[backcolor=transparent]-[backcolor=transparent]SHA1[backcolor=transparent]&[backcolor=transparent]SignatureNonce[backcolor=transparent]=[backcolor=transparent]45e25e9b[backcolor=transparent]-[backcolor=transparent]0a6f[backcolor=transparent]-[backcolor=transparent]4070[backcolor=transparent]-[backcolor=transparent]8c85[backcolor=transparent]-[backcolor=transparent]2956eda1b466[backcolor=transparent]&[backcolor=transparent]SignatureVersion[backcolor=transparent]=[backcolor=transparent]1.0[backcolor=transparent]&[backcolor=transparent]TemplateCode[backcolor=transparent]=[backcolor=transparent]SMS_71390007[backcolor=transparent]&[backcolor=transparent]TemplateParam[backcolor=transparent]=%[backcolor=transparent]7B[backcolor=transparent]%[backcolor=transparent]22customer[backcolor=transparent]%[backcolor=transparent]22[backcolor=transparent]%[backcolor=transparent]3A[backcolor=transparent]%[backcolor=transparent]22test[backcolor=transparent]%[backcolor=transparent]22[backcolor=transparent]%[backcolor=transparent]7D[backcolor=transparent]&[backcolor=transparent]Timestamp[backcolor=transparent]=[backcolor=transparent]2017[backcolor=transparent]-[backcolor=transparent]07[backcolor=transparent]-[backcolor=transparent]12T02[backcolor=transparent]%[backcolor=transparent]3A42[backcolor=transparent]%[backcolor=transparent]3A19Z[backcolor=transparent]&[backcolor=transparent]Version[backcolor=transparent]=[backcolor=transparent]2017[backcolor=transparent]-[backcolor=transparent]05[backcolor=transparent]-[backcolor=transparent]25
  2. [backcolor=transparent]HTTP[backcolor=transparent]/[backcolor=transparent]1.1
  3. [backcolor=transparent]Host[backcolor=transparent]:[backcolor=transparent] dysmsapi[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]com
  4. [backcolor=transparent]...

返回示例:
  1. [backcolor=transparent]HTTP[backcolor=transparent]/[backcolor=transparent]1.1[backcolor=transparent] [backcolor=transparent]200[backcolor=transparent] OK
  2. [backcolor=transparent]...
  3. [backcolor=transparent]<?[backcolor=transparent]xml version[backcolor=transparent]=[backcolor=transparent]'1.0'[backcolor=transparent] encoding[backcolor=transparent]=[backcolor=transparent]'UTF-8'[backcolor=transparent]?><[backcolor=transparent]SendSmsResponse[backcolor=transparent]><[backcolor=transparent]Message[backcolor=transparent]>[backcolor=transparent]OK[backcolor=transparent]<[backcolor=transparent]/Message><RequestId>E8534574-7381-4810-8F70-65B37BBA8970</[backcolor=transparent]RequestId[backcolor=transparent]><[backcolor=transparent]BizId[backcolor=transparent]>[backcolor=transparent]108374502347[backcolor=transparent]^[backcolor=transparent]1111325525761[backcolor=transparent]<[backcolor=transparent]/BizId><Code>OK</[backcolor=transparent]Code[backcolor=transparent]></[backcolor=transparent]SendSmsResponse[backcolor=transparent]>


2.2 短信Rest请求参数


如HTTP示例包中,请求的参数可以分两大块:系统参数 和 业务参数

系统参数


系统参数为POP协议的基本参数,有
参数KEY是否必填说明
AccessKeyId
Timestamp格式为:yyyy-MM-dd’T’HH:mm:ss’Z’;时区为:GMT
Format没传默认为JSON,可选填值:XML
SignatureMethod建议固定值:HMAC-SHA1
SignatureVersion建议固定值:1.0
SignatureNonce用于请求的防重放攻击,每次请求唯一,JAVA语言建议用:java.util.UUID.randomUUID()生成即可
Signature最终生成的签名结果值


业务参数

参数KEY是否必填说明
ActionAPI的命名,固定值,如发送短信API的值为:SendSms
VersionAPI的版本,固定值,如短信API的值为:2017-05-25
RegionIdAPI支持的RegionID,如短信API的值为:cn-hangzhou
PhoneNumbers具体见API文档描述
SignName具体见API文档描述
TemplateCode具体见API文档描述
[tr=rgb(239, 251, 255)][td]TemplateParam 否具体见API文档描述 OutId否具体见API文档描述

展开
收起
猫饭先生 2017-10-25 14:02:06 1606 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
阿里巴巴HTTP 2.0实践及无线通信协议的演进之路 立即下载
CDN助力企业网站进入HTTPS时代 立即下载
低代码开发师(初级)实战教程 立即下载