• python调用接口查询 顺丰单号 物流信息


    爱查快递 查询 顺丰单号 物流信息

    Query.sign = function() {
        function t(t) {
            var e, i, s, a, r = -1;
            for (e = 0,
            s = t.length; s > e; e += 1) {
                for (a = 255 & (r ^ t[e]),
                i = 0; 8 > i; i += 1)
                    1 == (1 & a) ? a = a >>> 1 ^ o : a >>>= 1;
                r = r >>> 8 ^ a
            }
            return -1 ^ r
        }
        function e(t, i) {
            var s, o, r;
            if ("undefined" != typeof e._x1l0o && i && t || (e._x1l0o = -1,
            t)) {
                for (s = e._x1l0o,
                o = 0,
                r = t.length; r > o; o += 1)
                    s = s >>> 8 ^ a[255 & (s ^ t[o])];
                return e._x1l0o = s,
                -1 ^ s
            }
        }
        function i(t) {
            var e, i, s, a, o, r = typeof t, n = 16, l = 0;
            if ("string" !== r && "number" !== r)
                return NaN;
            if (!(e = (t = (t + "").replace(/s/g, "").split(".")[0]).length))
                return NaN;
            if (n || (n = 10),
            "number" != typeof n || 2 > n || n > 36)
                return NaN;
            for (i = t.split("").reverse(),
            s = 0; e > s; s++)
                (o = (a = i[s]).charCodeAt(0)) >= 97 && (a = o - 87),
                l += Math.floor(a) * Math.pow(n, s);
            return l
        }
        var s, a = [], o = i("edb" + i(15900));
        return function() {
            var t, e, i;
            for (e = 0; 256 > e; e += 1) {
                for (t = e,
                i = 0; 8 > i; i += 1)
                    1 & t ? t = o ^ t >>> 1 : t >>>= 1;
                a[e] = t >>> 0
            }
        }(),
        (s = function(i, s) {
            i = "string" == typeof i ? function(t) {
                return Array.prototype.map.call(t, (function(t) {
                    return t.charCodeAt(0)
                }
                ))
            }(i + document.URL) : i;
            return ((s ? t(i) : e(i)) >>> 0).toString(16)
        }
        ).direct = t,
        s.table = e,
        s
    }(),
    
    # coding=utf-8
    '''
    爱查快递 查询 顺丰单号 物流信息
    快递100
    '''
    
    import requests, time, random, json
    import hashlib
    import js2py
    
    
    cx = '''
    function t(t) {
        var e, i, s, a, r = -1;
        for (e = 0,
        s = t.length; s > e; e += 1) {
            for (a = 255 & (r ^ t[e]),
            i = 0; 8 > i; i += 1)
                1 == (1 & a) ? a = a >>> 1 ^ o : a >>>= 1;
            r = r >>> 8 ^ a
        }
        return -1 ^ r
    }
    function e(t, i) {
        var s, o, r;
        if ("undefined" != typeof e._x1l0o && i && t || (e._x1l0o = -1,
        t)) {
            for (s = e._x1l0o,
            o = 0,
            r = t.length; r > o; o += 1)
                s = s >>> 8 ^ a[255 & (s ^ t[o])];
            return e._x1l0o = s,
            -1 ^ s
        }
    }
    function i(t) {
        var e, i, s, a, o, r = typeof t, n = 16, l = 0;
        if ("string" !== r && "number" !== r)
            return NaN;
        if (!(e = (t = (t + "").replace(/s/g, "").split(".")[0]).length))
            return NaN;
        if (n || (n = 10),
        "number" != typeof n || 2 > n || n > 36)
            return NaN;
        for (i = t.split("").reverse(),
        s = 0; e > s; s++)
            (o = (a = i[s]).charCodeAt(0)) >= 97 && (a = o - 87),
            l += Math.floor(a) * Math.pow(n, s);
        return l
    }
    var s, a = [], o = i("edb" + i(15900));
    // return function() {
    //     var t, e, i;
    //     for (e = 0; 256 > e; e += 1) {
    //         for (t = e,
    //         i = 0; 8 > i; i += 1)
    //             1 & t ? t = o ^ t >>> 1 : t >>>= 1;
    //         a[e] = t >>> 0
    //     }
    // }(),
    function sign(i, s) {
        // var t = "SF1017195166769:15391588061440585https://www.ickd.cn/shunfeng.html",
        i = "string" == typeof i ? function(t) {
            return Array.prototype.map.call(t, (function(t) {
                return t.charCodeAt(0)
            }
            ))
        }(i + 'https://www.ickd.cn/shunfeng.html') : i;
        return ((s ? t(i) : e(i)) >>> 0).toString(16)   // a5faf921
    };
    
    
    // var dstr = 'SF1017195166769:1539';
    // var timestr = '1588061440585';
    // var astr = dstr + timestr;
    // var result = sign(astr, timestr);
    // console.log(result);
    '''
    
    
    def random_pc_ua():
        # 只要谷歌浏览器
        ua_list = [
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7 ",
            "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.55 Safari/534.3 ",
        ]
        return random.choice(ua_list)
    
    
    def ai_cha(waybill, phone):
        '''
        爱查快递
        :return:
        '''
        timestr = str(int(float('%.3f' % time.time()) * 1000))  # '1588061440585'
        astr = waybill + ':' + phone + timestr
        print('astr = ', astr)
        context = js2py.EvalJs()
        context.execute(cx)
        result_tk = context.sign(astr, timestr)
        print('tk = ', result_tk)
    
        # url = 'https://biz.trace.ickd.cn/shunfeng/SF1017195166769:1539?mailNo=SF1017195166769%3A1539&tk=238ed3a1&tm=1588043698617&callback=_jqjsp&_1588043698617='
        # url = f'https://biz.trace.ickd.cn/shunfeng/{waybill}:{phone}?mailNo={waybill}%3A{phone}&tk=238ed3a1&tm={timestr}&callback=_jqjsp&_{timestr}='
        url = f'https://biz.trace.ickd.cn/shunfeng/{waybill}:{phone}?mailNo={waybill}%3A{phone}&tk={result_tk}&tm={timestr}&callback=_jqjsp&_{timestr}='
        headers = {
            'user-agent': random_pc_ua(), #'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
        }
        res = requests.get(url=url, headers=headers, timeout=5)
        # print(res.text)
        # print('-->', res.status_code)
        data_json = json.loads(res.text.replace('_jqjsp(', '').replace('});', '}') )
        # print('data_json = ', data_json)
        if 'update' in data_json.keys() and 'cache' in data_json.keys():
            for d in data_json['data']:
                print(d)
    
        else:
            ai_cha(waybill, phone)
    
    # ***********************************************************************************************************************************
    
    def kuai_di_100(waybill, phone):
        # url = 'https://www.kuaidi100.com/query?type=shunfeng&postid=SF1007703287911&id=1&valicode=&temp=0.5434366773989916&phone=1539'
        tempstr = round(random.uniform(0, 1), 19)
        print('tempstr = ', tempstr, len(str(tempstr)))
        url = f'https://www.kuaidi100.com/query?type=shunfeng&postid={waybill}&id=1&valicode=&temp={tempstr}&phone={phone}'
        headers = {
            'user-agent': random_pc_ua(),
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Connection": "keep-alive",
            "Host": "www.kuaidi100.com",
            "Referer": "https://www.kuaidi100.com/all/sf.shtml",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-origin",
        }
        res = requests.get(url=url, headers=headers, timeout=5)
        # print(res.text)
        print('-->', res.status_code)
        data_json = json.loads(res.text.replace('_jqjsp(', '').replace('});', '}') )
        for d in data_json['data']:
            print(d)
    
    if __name__ == '__main__':
        waybill = 'SF1017195166769'
        # waybill = 'SF1007703287911'
        phone = '1539'
        # ai_cha(waybill, phone)
        kuai_di_100(waybill, phone)
    
        # from urllib.parse import unquote, quote
        #
        # print(unquote('%b3%c9%b6%bc'))
        # print(quote('成都'))
    
  • 相关阅读:
    查看mysql日志
    Redis配置和常用命令
    任务
    如何让maven 将工程依赖的jar 复制到WEB-INF/lib 目录下
    Tomcat8安装, 安全配置与性能优化(转)
    Web.xml详解(转)
    php精度比较函数bccomp
    php找到字符数组里最左匹配长度的字符(最长公共前缀匹配算法)
    PHP实现curl post和get
    Jquery 跨Dom窗口操作
  • 原文地址:https://www.cnblogs.com/gqv2009/p/13186398.html
Copyright © 2020-2023  润新知