今日頭條文章js生成cp和as引數轉換為php和python演算法【原創】
阿新 • • 發佈:2018-11-05
今日頭條js生成cp和as引數轉換為php和python演算法 【原創】
cp 和 as 引數實際是對當前時間戳的加密後得到的
JS !function(t) { var i = {}; i.getHoney = function() { var t = Math.floor((new Date).getTime() / 1e3) , i = t.toString(16).toUpperCase() , e = md5(t).toString().toUpperCase(); if (8 != i.length) return { as: "479BB4B7254C150", cp: "7E0AC8874BB0985" }; for (var s = e.slice(0, 5), o = e.slice(-5), n = "", a = 0; 5 > a; a++) n += s[a] + i[a]; for (var l = "", r = 0; 5 > r; r++) l += i[r + 3] + o[r]; return { as: "A1" + n + i.slice(-3), cp: i.slice(0, 3) + l + "E1" } } , t.ascp = i }(window, document),
1. php 演算法實現參考
function getAsCp() { $as = ''; $cp = ''; $time = time(); $key = strtoupper(dechex($time)); $md5Key = strtoupper(md5($time)); if (8 !== strlen($key)) { $as = '479BB4B7254C150'; $cp = '7E0AC8874BB0985'; } else { $md5KeyAsc5 = substr($md5Key, 0, 5); $md5KeyDesc5 = substr($md5Key, -5); $as = ''; $cp = ''; for ($i = 0; $i < 5; $i ++) { $as .= $md5KeyAsc5[$i] . $key[$i]; $cp .= $key[$i + 3] . $md5KeyDesc5[$i]; } $as = 'A1' . $as . substr($key, -3); $cp = substr($key, 0, 3) . $cp . 'E1'; } return array($as, $cp); }
2. python演算法實現參考
def getASCP(): t = int(math.floor(time.time())) e = hex(t).upper()[2:] m = hashlib.md5()m.update(str(t).encode(encoding='utf-8')) i = m.hexdigest().upper() if len(e) != 8: AS ='479BB4B7254C150' CP = '7E0AC8874BB0985' return AS,CP n = i[0:5] a = i[-5:] s = '' r = '' for o inrange(5): s += n[o] + e[o] r += e[o + 3] + a[o] AS = 'A1' + s + e[-3:] CP = e[0:3] + r + 'E1' return AS,CP