package com.bc_chat.bc_base.http

import com.zhaohaoting.framework.utils.md5.MD5
import java.util.*

/**
 * author：Created by zhaohaoting on 2019/3/25
 * email：526309416@qq.com
 * desc：加密
 */
object Encryption {
    fun encryption(params: MutableMap<String, Any?>): MutableMap<String, Any?> {
        val encryptionParams: TreeMap<String, Any?> = TreeMap(params)
        val currentTime = System.currentTimeMillis() / 1000
        encryptionParams["time"] = currentTime
        val encryption = StringBuilder()
        encryption.append(currentTime)
        encryption.append("9549195224")
        val entries = encryptionParams.entries
        val iterator = entries.iterator()
        while (iterator.hasNext()) {
            val next = iterator.next()
            encryption.append("#")
            encryption.append(next.value)
        }
        val encryptionMD5 = MD5.getStringMD5(encryption.toString())
        params["sign"] = encryptionMD5
        params["time"] = currentTime
        return params
    }
}