明道云企业签名示例

集成 API代码块加密  收藏
5 / 1611
明道云企业签名

客户直接工作表管理明道云后台的汇报关系。此处需要 node 与 python 的签名示例具体参考如下

* nodejs 算法示例
var crypto = require('crypto');
var _ = require('lodash');
function getSignature(appKey, secretKey) {
    var date = new Date();
    var timestamp = date.getTime();
    var tempdata = {
        "AppKey": appKey,
        "SecretKey": secretKey,
        "Timestamp": timestamp.toString()
    };
    var signstr = '';
    _(tempdata).keys().sort().each(function(key) {
        signstr = signstr + '&' + key + '=' + tempdata[key];
    });
    signstr = signstr.substring(1);
    return {
        'sign': base64(sha256(signstr)),
        'timestamp': timestamp.toString(),
        'signstr': signstr  //查看变量拼接是否正确
    };
}
function sha256(s) {
    var hash = crypto.createHash('sha256');
    hash.update(s, 'utf8');
    return hash.digest('hex').toLowerCase();
}
function base64(s) {
    var result = new Buffer.from(s, 'utf8');
    return result.toString('base64');
}
output = getSignature(input.appkey, input.secretkey);
* Python 示例
import hashlib
import base64
import time
def getSignature(appkey, appsecret):
    t = int(round((time.time()) * 1000))
    dict={"AppKey":appkey,"SecretKey":appsecret,"Timestamp":str(t)}
    dict_sort = sorted(dict.items(), key = lambda k: k[0], reverse = False)
    signstr = ''
    for key, value in dict_sort:
        signstr = signstr + '&' + key + '=' + value
    signstr = signstr[1: ]
    sha = hashlib.sha256()
    sha.update(signstr.encode("utf-8"))
    sign = str(base64.b64encode(sha.hexdigest().encode("utf-8")), "utf-8")
    return {'timestamp':str(t),'sign':sign,'signstr':signstr}

output = getSignature(input['appkey'], input['appsecret'])
*php 示例
function getSignature($appKey, $secretKey) {
 	$timestamp =getMillisecond();
    $tempdata = array(
        "AppKey"=> $appKey,
        "SecretKey"=> $secretKey,
        "Timestamp"=> strval($timestamp)
    );
    $signstr = '';
	$keys=array_keys($tempdata);
	sort($keys);
	foreach ($keys as $value){
        $signstr = $signstr.'&'.$value.'='.$tempdata[$value];
	}
    $signstr = substr($signstr,1);
    return array(
        'sign'=> base64_encode(hash("sha256", $signstr)),
        'timestamp'=> strval($timestamp),
        'signstr'=> $signstr#查看变量拼接是否正确
    );
}
function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    return $t2 .  ceil( ($t1 * 1000) );
}

echo json_encode(getSignature("appkey","appsecret"));
* 其他

C# Java go 参考:https://www.showdoc.com.cn/mingdao/15539798

image.png

  1. 明道云企业签名算法

  2. 汇报关系接口