Service implement api or sdk of 3rd party.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
634 B

'use strict';
const md5 = require('md5');
class Common {
static sortDict(obj) { //dict按key排序
return Object.keys(obj).sort().reduce(function(result, key) {
result[key] = obj[key];
return result;
}, {});
}
static sign(params, token) { //对参数做MD5签名
return md5( JSON.stringify(Common.sortDict(params)) + token );
}
static isPhoneNumber(number) {
return /^1[3-9][0-9]{9}$/i.test(number);
}
static isVerifyCode(code) {
return /^[0-9]{4}$/i.test(code);
}
}
exports.default = Common;