注册送短信

DEMO: ShortURL/Put - 更新短网址

var request = require('request');
var crypto = require('crypto');
var appid = "input your appid";
var appkey = "input your appkey";
var api = "https://service.mysubmail.com/shorturl";



​ //生成加密签名
​ function BuildSignature(params){
​ var sorted = [];
​ for(var key in params) {
​ sorted[sorted.length] = key;
​ }
​ sorted.sort();
​ var tempDict = {};
​ for(var i = 0; i < sorted.length; i++) {
​ tempDict[sorted[i]] = params[sorted[i]];
​ }
​ var signStr = "";
​ for(var key in tempDict) {
​ signStr += key + '=' + tempDict[key] + '&';
​ }
​ signStr = signStr.substring(0, signStr.length-1);
​ signStr = appid + appkey + signStr + appid + appkey;
​ var md5sum = crypto.createHash('md5');
​ md5sum.update(signStr);
​ return md5sum.digest('hex');
​ }

​ //无加密示例
​ request({
​ url: api,
​ method: 'PUT',
​ form: {
​ appid:appid,
​ signature:appkey,
​ url : "https://www.mysubmail.com/mail",
​ short_url : "https://suburl.cn/4eHaXL",
​ }
​ }, function optionalCallback(err, httpResponse, body) {
​ if (err) {
​ return console.error(err);
​ }
​ console.log(body);
​ });

//加密示例

request({
    uri: "https://api.mysubmail.com/service/timestamp",
    method: 'GET'
}, function(error, response, body) {
    var result = JSON.parse(body);
    var requestParams = {}
    requestParams['timestamp'] = result["timestamp"];
    requestParams['sign_type'] = "md5";
    requestParams['appid'] = appid;
    requestParams['signature'] = BuildSignature(requestParams);
    requestParams['url'] = "https://www.mysubmail.com/mail";
    requestParams['short_url'] = "https://suburl.cn/TqvXzL";
    
    request({
        url: api, 
        method: 'PUT',
        form: requestParams
    }, function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error(err);
        }
        console.log(body);
    });
});