Esempio n. 1
0
 def ent_get_generate_headers(self):
     partnerId = "wulian_app"
     partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
     time_now = time.time()
     time_now = int(round(time_now * 1000))
     # 生成有序的字典
     result_data = OrderedDict()
     get_data = sorted(self.data)
     # print(get_data)
     for k in get_data:
         result_data[k] = self.data[k]
     # print(result_data)
     data_new = parse.urlencode(result_data)
     # print(data_new)
     data_list = [
         partnerId, '&', data_new, '&', partnerkey, '&',
         str(time_now)
     ]
     data_str = ''.join(data_list)
     sign_data = sha1.str_encrypt(data_str.encode("utf8"))
     sign_data = sign_data.lower()
     headers = {
         "Content-Type": "application/json",
         "WL-PARTNER-ID": "wulian_app",
         "WL-TIMESTAMP": str(time_now),
         "WL-SIGN": sign_data,
         "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb"
     }
     return headers
Esempio n. 2
0
def getHeader(data):
    partnerId = "wulian_app"
    partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
    t = time.time()
    nowtime = int(round(t * 1000))  # 获取毫秒级时间戳  # 获取get的header
    # 字典类型的data升序排序
    ordict = OrderedDict()
    da = sorted(data)
    for i in da:
        ordict[i] = data[i]
    # urlencode函数,可以把key-value这样的键值对转换成我们想要的格式,返回的是a=1&b=2这样的字符串
    dataNow = parse.urlencode(ordict, encoding="utf-8")
    sign = partnerId + "&" + dataNow + "&" + partnerkey + "&" + str(nowtime)
    # 或者这么写
    # data_list = [partnerId, '&', dataNow, '&', partnerkey, '&', str(nowtime)]
    # sign = ''.join(data_list)
    sign = sha1.str_encrypt(sign.encode("utf-8")).lower()
    header = {
        "Content-Type": "application/json",
        "WL-PARTNER-ID": "wulian_app",
        "WL-TIMESTAMP": str(nowtime),
        "WL-SIGN": sign,
        "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb"
    }
    return header
Esempio n. 3
0
    def apiHeader(self, index, inf, token):
        partnerId = "wulian_app"
        partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
        # 当前时间戳(毫秒)
        t = time.time()
        now = str(int(round(t * 1000)))

        if index == 0:
            # get参数,将各个接口中的参数按照名升序排序,通过"&"拼接起来
            getParam = inf["data"]
            getParam = sorted(getParam.items(),
                              key=lambda item: item[0])  # 升序排序
            getParam = parse.urlencode(getParam, encoding="utf-8")  # 通过"&"拼接起来
            getParam = parse.unquote(getParam, encoding="utf-8")
            sign = partnerId + "&" + getParam + "&" + partnerkey + "&" + now
            # print ("sign:"+sign)

        elif index == 1:
            # post参数,request的body就是各个接口中的参数
            postParam = json.dumps(inf["data"])  # 把字典转换为字符串
            sign = partnerId + "&" + postParam + "&" + partnerkey + "&" + now

        sign = sign.encode("utf-8")
        sign1 = sha1.str_encrypt(sign).lower()
        header = {
            "Content-Type": "application/json",
            "WL-PARTNER-ID": "wulian_app",
            "WL-TIMESTAMP": now,
            "WL-SIGN": sign1,
            "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb",
            "WL-TOKEN": token
        }
        return header
Esempio n. 4
0
def get_generate_headers(data):
    partnerId = "wulian_app"
    partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
    time_now = time.time()
    #urlencode函数,可以把key-value这样的键值对转换成我们想要的格式,返回的是a=1&b=2这样的字符串
    data_new = parse.urlencode(data)
    data_list = [partnerId, '&', data_new, '&', partnerkey, '&', str(time_now)]
    data_str = ''.join(data_list)
    sign_data = sha1.str_encrypt(data_str.encode("utf8"))
    sign_data = sign_data.lower()

    headers = {"Content-Type": "application/json", "WL-PARTNER-ID": "wulian_app", "WL-TIMESTAMP": str(time_now), \
               "WL-SIGN": sign_data,"WL-TID" : "a50b0fff867a8ab8f252bb65f321e6bb"}

    return headers
Esempio n. 5
0
def post_generate_headers(data):
    partnerId = "wulian_app"
    partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
    time_now = time.time()

    data_new = json.dumps(data)  # 将字典形式的数据转化为字符串
    data_list = [partnerId, '&', data_new, '&', partnerkey, '&', str(time_now)]
    data_str = ''.join(data_list)
    sign_data = sha1.str_encrypt(data_str.encode("utf8"))
    sign_data = sign_data.lower()
    headers = {
        "Content-Type": "application/json",
        "WL-PARTNER-ID": "wulian_app",
        "WL-TIMESTAMP": str(time_now),
        "WL-SIGN": sign_data,
        "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb"
    }
    return headers
Esempio n. 6
0
    def change_phone_number(self):
        url_token = "https://iot.wuliancloud.com:443/sso/login/byphone"  # 测试的接口url
        data = {
            "phone": "18120135777",
            "phoneCountryCode": "86",
            "password": "******",
            "terminalId": "a50b0fff867a8ab8f252bb65f321e6bb"
        }  # 接口数据
        headers = post_generate_headers(data)
        r = requests.post(url=url_token, json=data, headers=headers)  # 发送请求
        hjson = json.loads(r.text)
        token = hjson['data']['token']
        #print (token)

        url = "https://iot.wuliancloud.com:443/api/user/phone/update"  # 测试的接口url
        partnerId = "wulian_app"
        partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
        time_now = time.time()
        data_recover = {
            "phone": "13675124538",
            "phoneCountryCode": "86",
            "authCode": "123456"
        }  # 接口数据

        data_new = json.dumps(data_recover)
        data_list = [
            partnerId, '&', data_new, '&', partnerkey, '&',
            str(time_now)
        ]
        data_str = ''.join(data_list)
        #print(data_str)
        sign_data = sha1.str_encrypt(data_str.encode("utf8"))
        sign_data = sign_data.lower()
        headers = {"Content-Type": "application/json", "WL-PARTNER-ID": "wulian_app", "WL-TIMESTAMP": str(time_now), \
                   "WL-SIGN": sign_data, "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb", "WL-TOKEN": token}
        #print (headers)

        r = requests.post(url=url, json=data_recover, headers=headers)  # 发送请求
        #print(r.text)
        return r


# changephonenumber = Change_phone_number()
# changephonenumber.change_phone_number()
Esempio n. 7
0
    def api_get_generate_headers(self, token):
        partnerId = "wulian_app"
        partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
        time_now = time.time()
        time_now = int(round(time_now * 1000))
        # 生成有序的字典
        result_data = OrderedDict()
        get_data = sorted(self.data)
        # print(get_data)
        for k in get_data:
            result_data[k] = self.data[k]
        # print(result_data)
        data_new = parse.urlencode(result_data)
        data_new = parse.unquote(data_new)  # 解码,处理特殊字符

        if not data_new:
            data_list = [
                partnerId, '&', data_new, partnerkey, '&',
                str(time_now)
            ]
        else:
            data_list = [
                partnerId, '&', data_new, '&', partnerkey, '&',
                str(time_now)
            ]

        data_str = ''.join(data_list)
        # print(data_str)  #加密前的字符串
        sign_data = sha1.str_encrypt(data_str.encode("utf8"))
        sign_data = sign_data.lower()
        # print(sign_data)  #签名后的数据
        # token = get_token.test_get_token()
        # get_return = iot_get_return()
        # token = get_return["data"]['token']
        headers = {
            "Content-Type": "application/json",
            "WL-PARTNER-ID": "wulian_app",
            "WL-TIMESTAMP": str(time_now),
            "WL-SIGN": sign_data,
            "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb",
            "WL-TOKEN": token
        }
        return headers
Esempio n. 8
0
def apiPostHeader(data, token):
    partnerId = "wulian_app"
    partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
    t = time.time()
    nowtime = int(round(t * 1000))  # 获取毫秒级时间戳  # 获取get的header
    # 将data序列化为json字符串
    dataNow = json.dumps(data)
    sign = partnerId + "&" + dataNow + "&" + partnerkey + "&" + str(nowtime)
    signed = sha1.str_encrypt(sign.encode("utf8")).lower()
    # print(signed)
    header = {
        "Content-Type": "application/json",
        "WL-PARTNER-ID": "wulian_app",
        "WL-TIMESTAMP": str(nowtime),
        "WL-SIGN": signed,
        "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb",
        "WL-TOKEN": token
    }
    return header
    def change_phone_password(self):
        url_token = "https://iot.wuliancloud.com:443/sso/login/byphone"  # 测试的接口url
        data = {
            "phone": "18168020465",
            "phoneCountryCode": "86",
            "password": "******",
            "terminalId": "a50b0fff867a8ab8f252bb65f321e6bb"
        }  # 接口数据
        headers = post_generate_headers(data)
        r = requests.post(url=url_token, json=data, headers=headers)  # 发送请求
        hjson = json.loads(r.text)
        token = hjson['data']['token']

        url = "https://iot.wuliancloud.com:443/api/user/updatepass"  # 测试的接口url
        partnerId = "wulian_app"
        partnerkey = "fb1bbde01c9a4d45d82d5f5107b1f4dd7c105af06c928ce14878cdda03874dcc"
        time_now = time.time()

        data_recover = {
            "password": "******",
            "newpassword": "******"
        }  # 接口数据

        data_new = json.dumps(data_recover)
        data_list = [
            partnerId, '&', data_new, '&', partnerkey, '&',
            str(time_now)
        ]
        data_str = ''.join(data_list)
        #print(data_str)
        sign_data = sha1.str_encrypt(data_str.encode("utf8"))
        sign_data = sign_data.lower()
        headers = {"Content-Type": "application/json", "WL-PARTNER-ID": "wulian_app", "WL-TIMESTAMP": str(time_now), \
                   "WL-SIGN": sign_data, "WL-TID": "a50b0fff867a8ab8f252bb65f321e6bb", "WL-TOKEN": token}
        #print (headers)

        r = requests.post(url=url, json=data_recover, headers=headers)  # 发送请求
        print(r.text)
        return r


# c=Change_phone_password()
# c.change_phone_password()