# 簽名規則
**短說OSX**與開發者之間進行接口交互請求,都會包含簽名參數,鏈接中簽名參數的生成,都是通過MD5生成的簽名參數,以確保請求安全。
### 1.MD5簽名原理
md5簽名原理如下:
將請求參數和appSecret封裝成Map集合,按照**參數名**(Key)進行升序排列,將排序后Map集合的參數值(value)拼裝成字符串進行MD5簽名。其中appSecret在簽名中的順序取決于他在所有參數名中的順序。
例: `appKey:testappkey , appSecret:testsecret`
參數列表:`{appKey=testappkey,endtimestamp=1405495206}`
簽名原串:`testappkeytestsecret1405495206`
簽名后字符串:`fc89ad8645fe705f024edfc00c02aeee`
簽名url示例:<http://(domain)?endtimestamp=1405495206&appKey=testappKey&sign=fc89ad8645fe705f024edfc00c02aeee>
#### 注意:
\> 1.簽名驗證時,如無特殊說明,必須遍歷request請求中的所有參數進行簽名驗證。 > 短說向開發者發起的請求,也會帶上簽名,開發者可在提供的api中進行簽名驗證,確保請求來源可信。
### 2.簽名規則測試用例
為了方便開發者對簽名方法進行測試驗證,下面舉例說明簽名規則和簽名方法。
1.以免登陸地址參數請求簽名參數為例:url=" [http://osxfenew.demo.opensns.cn/#/autoLogin?&user\_token=14359234985&token=23453654fsdgjk&endtimestamp=1520559858&appKey=testappKey&sign=3fdde881d58af54792f2e3198244f3a2&redirect=https%3a%2f%2fosxfenew.demo.opensns.cn%2f%23%2fpackageA%2fforum-detail%2fnormal%3ffid%3d44](http://osxfenew.demo.opensns.cn/#/autoLogin?&user_token=14359234985&token=23453654fsdgjk&endtimestamp=1520559858&appKey=testappKey&sign=3fdde881d58af54792f2e3198244f3a2&redirect=https%3a%2f%2fosxfenew.demo.opensns.cn%2f%23%2fpackageA%2fforum-detail%2fnormal%3ffid%3d44) "
2.其中密鑰appSecret的值為:appSecret=testappSecret。
3.獲取請求鏈接中所有請求參數封裝成Map集合 :{appKey=testappKey ; user\_token=14359234985(開發者平臺用戶唯一標識) ;token=23453654fsdgjk(請求單次有效唯一標識,開發者服務端在用戶信息獲取接口中校驗請求合法性); endtimestamp=1520559858} ;
4.把appSecret加入參數列表集合后如下:
{ appKey=testappKey, appSecret=testappSecret, user\_token=14359234985 , endtimestamp=1520559858, token=23453654fsdgjk }
5.把Map集合按照**參數名升序**排序之后如下:
{ appKey=testappKey, appSecret=testappSecret, endtimestamp=1520559858 ,token=23453654fsdgjk, user\_token=14359234985 }
6.根據規則,把排序后參數列表的參數值拼裝成簽名源串如下:
strs= testappKeytestappSecret152055985823453654fsdgjk14359234985
7.把上面拼裝成的參數源串加密后獲得的簽名如下: sign=MD5(strs)= 3fdde881d58af54792f2e3198244f3a2
##### 說明:
\> OSX短說采用appKey、appSecret的鍵值對形式作為密鑰對,而非采用單一secret的形式,主要是為了后續多應用模式留下入口。廣大開發者們不必糾結
## 簽名驗證工具
為方便開發同學理解簽名規則,可以使用下面的短說OSX簽名工具頁面進行驗證簽名。地址如下:[簽名校驗工具](https://osxbe.demo.opensns.cn/commonapi/index/checkTokenSign)