云服务器

签名校验

<style>

}
p {

line-height: 36px;

}
/ 输入框 start /
input {

  width: 90% !important;

}
input[type=text]{

height: 36px;
font-size: 14px;
color: #2D3037;
padding-left: 15px;
border: 1px solid #BDC5D3;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
outline: none;
-webkit-transition: all .4s;
-moz-transition: all .4s;
-o-transition: all .4s;
transition: all .4s;

}
input[type=text]:hover{

border-color: #FF6666 !important;

}
input[type=text]:focus{

border-color: #FF6666 !important;
-webkit-box-shadow: 0px 0px 0px 2px #FFC2C2;
-moz-box-shadow: 0px 0px 0px 2px #FFC2C2;
-o-box-shadow: 0px 0px 0px 2px #FFC2C2;
box-shadow: 0px 0px 0px 2px #FFC2C2;

}

.table {

font-size: 14px;
margin: 20px 0 0 0;
width: 100%;
border-spacing: 0;
border-collapse: collapse;

}
.table thead tr th {

font-weight: bold;
color: #2D3037;
padding: 5px;
border-bottom: 1px solid #DBE1E8;

}
.table thead tr th svg {

color: #bdc5d3;

}
.table thead tr th a {

color: #2D3037;
text-decoration: none;

}
.table tbody tr:nth-child(1) td {

border-top: none;

}
.table tbody tr td {

color: #2D3037;
padding: 5px;
border-top: 1px solid #F0F2F5;
text-align: center;

}
.table tbody tr td .blue {

position: relative;
display: inline-block;
color: #20A0FF;
cursor: pointer;

}
.table tbody tr td a {

margin: 0px 3px;

}
.table tbody tr td.pl_32 {

padding-left: 32px;

}
.table tbody tr td.disk_id_td {

padding: 0px;

}
.table tbody tr td.disk_id_td > div {

width: 126px;
height: 56px;
line-height: 56px;
color: #50B0FF;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
word-break: break-all;

}
.table tbody tr td a {

color: #2D3037;
text-decoration: none;

}
.table tbody tr td a:hover {

color: #FF6666;

}
.table tbody tr td a.red {

color: #FF6666;

}
.table tbody tr td.tag_td {

width: 123px;

}
.table tbody tr td.tag_td .tag_name_prompt.hide {

display: none;

}
.table tbody tr td.tag_td .tag_name_prompt input {

width: 74px;
height: 22px;
outline: none;
padding-left: 4px;
border: 1px solid #BDC5D3;

}
.table tbody tr td.tag_td .tag_name_prompt input:focus {

border-color: #FF6666;

}
.table tbody tr td.tag_td > input {

width: 74px;
padding-left: 4px;
border: 1px solid #BDC5D3;
outline: none;

}
.table tbody tr td.tag_td > input:focus {

border-color: #FF6666;

}
.table tbody tr td.tag_td span {

display: inline-block;
max-width: 74px;
height: 20px;
line-height: 18px;
text-align: center;
padding: 0px 6px;
border: 1px solid #BDC5D3;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
border-radius: 2px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;

}
.table tbody tr td.tag_td span.hide {

display: none;

}
.table tbody tr td.tag_td svg {

font-size: 18px;
color: #5e6d81;

}
.table tbody tr td.tag_td svg.hide {

display: none;

}
.table tbody tr:last-child td {

border-bottom: 1px solid #F0F2F5;

}
.table-hover > tbody > tr:hover {

background-color: #F0F2F5;

}
.table > tbody > tr.active > td,
.table > tbody > tr.active > th,
.table > tbody > tr > td.active,
.table > tbody > tr > th.active,
.table > tfoot > tr.active > td,
.table > tfoot > tr.active > th,
.table > tfoot > tr > td.active,
.table > tfoot > tr > th.active,
.table > thead > tr.active > td,
.table > thead > tr.active > th,
.table > thead > tr > td.active,
.table > thead > tr > th.active {

background-color: #F0F2F5;

}
.table-hover > tbody > tr.active:hover > td,
.table-hover > tbody > tr.active:hover > th,
.table-hover > tbody > tr:hover > .active,
.table-hover > tbody > tr > td.active:hover,
.table-hover > tbody > tr > th.active:hover {

background-color: #F0F2F5;

}

button {
background-color: #FF4444;
border: 1px solid #FF4444;
height: 40px;
padding: 0px 36px;
font-size: 14px;
color: #FFFFFF;
border-radius: 4px;
outline: none !important;
user-select: none;
font-family: inherit;
font-size: inherit;
line-height: inherit;
-webkit-appearance: button;
cursor: pointer;
text-transform: none;
overflow: visible;
margin: 0;

}
</style>
<p>
本测试为用户提供了发送短信调用API时signature生成的校验,不做接口参数合法校验及发送测试。
</p>
<p>
关于短信API中signature验证机制请查看调用方式。
</p>
<p>
由于accessSecret不做参数明文传输,做加密使用,请先填写accessSecret。
</p>
<div>
<span style="padding-right: 15px;">accessSecret: </span>
<input id="accessSecret" type="text" style="width: 70% !important;" placeholder="请输入accessSecret">
</div>
<table class="table table-hover" data-selectable="selectable" data-row-selectable="true" data-page-size="10">

&lt;thead&gt;
    &lt;tr&gt;
        &lt;th&gt;key&lt;/th&gt;
        &lt;th&gt;value&lt;/th&gt;
        &lt;th&gt;是否使用&lt;/th&gt;
    &lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
    &lt;tr&gt;
        &lt;td&gt;accessId&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;accessId&quot; type=&quot;text&quot; placeholder=&quot;请输入accessId&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;accessIdCheck&quot; checked=&quot;&quot; disabled=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;timestamp&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;timestamp&quot; type=&quot;text&quot; placeholder=&quot;请输入timestamp&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;timestampCheck&quot; checked=&quot;&quot; disabled=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;nonce&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;nonce&quot; type=&quot;text&quot; placeholder=&quot;请输入nonce&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;nonceCheck&quot; checked=&quot;&quot; disabled=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;phone&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;phone&quot; type=&quot;text&quot; placeholder=&quot;请输入phone&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;phoneCheck&quot; checked=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;templateCode&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;templateCode&quot; type=&quot;text&quot; placeholder=&quot;请输入templateCode&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;templateCodeCheck&quot; checked=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;templateVars&lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;templateVars&quot; type=&quot;text&quot; placeholder=&quot;请输入templateVars,例如:{“code”:111111,“min”:5}&quot;&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input id=&quot;templateVarsCheck&quot; checked=&quot;&quot; type=&quot;checkbox&quot;&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;

</table>

<div style="width: 100%; margin-top: 20px; text-align: center;">

&lt;button type=&quot;button&quot; id=&quot;buildSignature&quot;&gt;生成 signature&lt;/button&gt;

</div>
<div style="width:100%; margin-top:20px;text-align: center;" id="paramsStr"></div>
<div style="width: 100%; margin-top: 20px; text-align: center;">

&lt;p&gt;&lt;/p&gt;

<span style="color:red;padding-right: 20px;">signature: </span>
<input id="signature" type="text" style="width: 70% !important;" placeholder="签名结果" readonly>
</div>
<script src="https://cache.yisu.com/www/js/crypto-js-4.0.0/crypto-js.js";></script>
<script type="text/javascript">
$(function(){

function sortDict(dict){
    var dict2={},
        keys = Object.keys(dict).sort();
    for (var i = 0, n = keys.length, key; i &lt; n; ++i) {
        key = keys[i];
        dict2[key] = dict[key];
    }
    return dict2;
}

function isEmpty(text) {
    if(text == &quot;&quot; || text == undefined || text == null){
        return true;
    }
    if(typeof text ===&quot;number&quot;) text = text.toString();
    if(typeof text ===&quot;string&quot;){
        text = text.replace(/(^\s*)|(\s*$)/g, &quot;&quot;);
        if(text == &quot;&quot;) return true;
    }
    return false;
}

$(&quot;#buildSignature&quot;).on(&quot;click&quot;, function() {
    var accessSecret = $(&quot;#accessSecret&quot;).val();
    if (accessSecret == &quot;&quot;) {
        $(&quot;#accessSecret&quot;).focus();
            $(&quot;#paramsStr&quot;).text(&quot;请输入accessSecret&quot;);
        return;
    }
    var accessId = $(&quot;#accessId&quot;).val();
    var timestamp = $(&quot;#timestamp&quot;).val();
    var nonce = $(&quot;#nonce&quot;).val();
    var templateCode = $(&quot;#templateCode&quot;).val();
    var phone = $(&quot;#phone&quot;).val();
    var templateVars = $(&quot;#templateVars&quot;).val().toString();
    if (isEmpty(accessId)) {
        $(&quot;#accessId&quot;).focus();
            $(&quot;#paramsStr&quot;).text(&quot;请输入accessId&quot;);
        return;
    }
    if (isEmpty(timestamp)) {
        $(&quot;#timestamp&quot;).focus();
            $(&quot;#paramsStr&quot;).text(&quot;请输入timestamp&quot;);
        return;
    }
    if (isEmpty(nonce)) {
        $(&quot;#nonce&quot;).focus();
            $(&quot;#paramsStr&quot;).text(&quot;请输入nonce&quot;);
        return;
    }

    var params = {
      &quot;accessId&quot;: accessId,
      &quot;nonce&quot;: nonce,
      &quot;timestamp&quot;: timestamp
    }
    if ($(&quot;#phoneCheck&quot;).is(&quot;:checked&quot;)) {
        params.phone = phone;
    }
    if ($(&quot;#templateCodeCheck&quot;).is(&quot;:checked&quot;)) {
        params.templateCode = templateCode;
    }
    if ($(&quot;#templateVarsCheck&quot;).is(&quot;:checked&quot;)) {
        try {
            templateVars = JSON.parse(templateVars)
        }
        catch (err) {
            $(&quot;#templateVars&quot;).focus();
            $(&quot;#paramsStr&quot;).text(&quot;templateVars格式不正确&quot;);
            return;
        }
        params.templateVars = JSON.stringify(templateVars);
    }
    sorted_params = sortDict(params);

    var params_str = &quot;&quot;;
    for(var key in sorted_params) {
        params_str += (key + &quot;=&quot; + sorted_params[key] + &quot;&amp;&quot;)
    }
    params_str = params_str.substring(0, params_str.length - 1);
    $(&quot;#paramsStr&quot;).text(&quot;拼接字符串为: &quot; + params_str);
    var signature = CryptoJS.HmacSHA1(params_str, accessSecret).toString(CryptoJS.enc.Base64);
    $(&quot;#signature&quot;).val(signature);
})

});
</script>