| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | 
							- #-*- coding:utf-8 -*-
 
- from ssat_sdk.utils.LoggingUtil import printLog
 
- from ssat_sdk.device_manage import ScbcCopyKey
 
- from ssat_sdk.sat_environment import getOtaParamUrl_dict
 
- import urllib
 
- import urllib2
 
- import json
 
- import requests
 
- # HTTP协议传参时的自动化测试标识,string型,每次请求必带的参数,KEY为type
 
- SAT_TYPE = "1"
 
- class OtaClient():
 
-     def __init__(self):
 
-         # 各服务器getParam接口
 
-         self.getParamDict = getOtaParamUrl_dict()
 
-         # self.getParamDict = {
 
-         #     "CN": "https://cn.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "NA": "https://na.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "LA": "https://la.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "ME": "https://me.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "EU": "https://eu.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "AP": "https://ap.ota.qhmoka.com/ota-services/strategy/getParam",
 
-         #     "TEST": "https://test.uc.qhmoka.com/ota-services/strategy/getParam"
 
-         #     }
 
-         # http request中统一使用的headers
 
-         self.headers = {
 
-             "Content-Type": "application/json"
 
-         }
 
-     def postRequest(self, url, post_data, headers):
 
-         response = requests.post(url, data=post_data, headers=headers)
 
-         printLog("response:%s" % response)
 
-         printLog("response.status_code:%s" % response.status_code)
 
-         printLog("response.text:%s" % response.text)
 
-         if response.status_code != 200:
 
-             printLog("OtaClient.postRequest()", u"Response结果码异常。")
 
-             return False, response
 
-         else:
 
-             return True, response
 
-     def getAppKey(self, area):
 
-         appKeys = []
 
-         url = ""
 
-         if 1:
 
-             try:
 
-                 url = self.getParamDict[area]
 
-             except Exception, e:
 
-                 printLog("OtaClient.addUserId()", u"无法通过传入的area获取url地址。%s"%e)
 
-                 return False
 
-         # 测试服务器地址
 
-         if 0:
 
-             url = "https://test.uc.qhmoka.com/ota-services/strategy/getParam"
 
-         post_dict = {
 
-             "type": SAT_TYPE,
 
-             "area": area
 
-         }
 
-         post_data = json.dumps(post_dict)
 
-         result, response = self.postRequest(url, post_data, self.headers)
 
-         if result is False:
 
-             return False, appKeys
 
-         resDict = json.loads(response.text)
 
-         if int(resDict['code']) != 1000:
 
-             result = False
 
-         else:
 
-             result = True
 
-             appKeys = resDict['data']['appKeys']
 
-         printLog("OtaClient.getAppKey()", u"请求返回信息:%s" % resDict['msg'])
 
-         return result, appKeys
 
-     def httpAddUserId(self, area, appKey, clientType, projectId, checkVersion, version, userId):
 
-         url = ""
 
-         if 1:
 
-             try:
 
-                 url = self.getParamDict[area]
 
-             except Exception, e:
 
-                 printLog("OtaClient.addUserId()", u"无法通过传入的area获取url地址。%s"%e)
 
-                 return False
 
-         # 测试服务器地址
 
-         if 0:
 
-             url = "https://test.uc.qhmoka.com/ota-services/strategy/getParam"
 
-         post_dict = {
 
-             "type": SAT_TYPE,
 
-             "area": area,
 
-             "appKey": appKey,
 
-             "clientType": clientType,
 
-             "projectId": projectId,
 
-             "checkVersion": checkVersion,
 
-             "version": version,
 
-             "userId": userId
 
-         }
 
-         post_data = json.dumps(post_dict)
 
-         result, response = self.postRequest(url, post_data, self.headers)
 
-         if result is False:
 
-             return False
 
-         resDict = json.loads(response.text)
 
-         if int(resDict['code']) != 1000:
 
-             result = False
 
-         else:
 
-             result = True
 
-         printLog("OtaClient.addUserId()", u"请求返回信息:%s" % resDict['msg'])
 
-         return result
 
-     def httpGetUserId(self, deviceId, clientType, mac, forFormal=True):
 
-         # 测试环境:
 
-         testRoot = "http://test.dsp.server.qhmoka.com"
 
-         # 正式环境:
 
-         formalRoot = "https://dsp.server.qhmoka.com"
 
-         # 登录的账号密码
 
-         userName = "auto"
 
-         password = "123456"
 
-         if forFormal is True:
 
-             loginUrl = formalRoot + "/login"
 
-         else:
 
-             loginUrl = testRoot + "/login"
 
-         token = ScbcCopyKey.HTTPLogin(loginUrl, userName, password, 1)
 
-         # token长度不为0, 表示成功获取token值;
 
-         if token.__len__():
 
-             print u"login token = ", token
 
-             userId = ScbcCopyKey.HTTPGetUserId("http://test.dsp.server.qhmoka.com/api/automation/getUserId", token,
 
-                                                clientType, deviceId, mac.replace('-', ':'))
 
-             # userId == -1表示获取失败;
 
-             return userId
 
-     def getDeviceId(self):
 
-         return ScbcCopyKey.GetDeviceId()
 
-     def getClientType(self):
 
-         return ScbcCopyKey.GetClientType()
 
-     def getMAC(self):
 
-         return ScbcCopyKey.GetMAC()
 
- if __name__ == '__main__':
 
-     pass
 
 
  |