帮我吧文档:签名认证

帮我吧im客户端动态签名规则说明

注: 此规则仅当后台开启客户端动态签名项才生效。

1. URL必传参数:

  • signature 签名token
  • timestamp 13位时间戳
  • nonce 随机数

2. 签名规则说明: - 对除signature外的全部参数签名,先字典升序后hash :

sha1(private_key,timestamp,nonce,param1...)
  • private_key: 私钥(在后台设置中生成和重置)
  • timestamp 时间戳1小时内有效
  • 其余参数根据实际需要传递
  • 中文参数UTF-8编码,必须urlencode

3. 签名代码示例(PHP版)

<?php
 
/**
 * 签名类
 * Class Signature
 */
 
class Signature{
    private $nonce;
    private $timestamp;
    private $private_key = 'aef2l3gze982ew';
 
    public function __construct()
    {
        $this->nonce = time();
        $this->timestamp = $this->getUnixMicroTime();
    }
 
    //获取13位时间戳
    protected function getUnixMicroTime() {
        $time = microtime(1);
        return floor($time * 1000);
    }
 
    //生成签名
    public function makeSignature(array $params){
        $params['private_key'] = $this->private_key;
        $params['timestamp'] = $this->timestamp;
        $params['nonce'] = $this->nonce;
        $tmpArr = array_values($params);
        sort($tmpArr, SORT_STRING);
        return $tmpStr = sha1(implode($tmpArr));
    }
}
 
//参数需要根据实际情况传递 
$params = [
    'vendorID'=>128789,
    'uid'=>'u2_128789_1234567890' //如过您使用的是api方式对接自定义字段(authaccount)导入第三方系统账号时,uid 格式是 u6_vendorID_{第三方系统账号} 
];
 
$signObj = new Signature();
$signature =  $signObj->makeSignature($params);

4. 最终生成的带签名的url链接示例:

https://www.bangwo8.com/osp2016/chat/pc/index.php?vendorID=128789&uid=u2_128789_1234567890&timestamp=1566385123983&nonce=862739&signature=588370c3a10858fde89e16cc26ea775e0f87129c


页面工具