1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- # -*- coding:UTF-8 -*-
- import requests
- import json
- import contants
- from PrintLog import PrintLog
- def notify_sp_cut_state(sp_code, progress, msg, ad_code_list):
- url = contants.get_sp_notify_url()
- if ad_code_list != 'null':
- data = {"sp_code": sp_code, "msg": msg, "progress": progress, "ad_code_list": ad_code_list}
- else:
- data = {"sp_code": sp_code, "msg": msg, "progress": progress}
- print(data)
- content = http_request(url, data, False, 'get', False)
- print(content)
- def notify_sp_cut_success(sp_code, progress, msg, ad_code_list, check_package_info):
- url = contants.get_sp_notify_url()
- if ad_code_list != 'null':
- data = {"sp_code": sp_code, "msg": msg, "progress": progress, "ad_code_list": ad_code_list,
- "check_package_info": check_package_info}
- else:
- data = {"sp_code": sp_code, "msg": msg, "progress": progress, "check_package_info": check_package_info}
- print(data)
- content = http_request(url, data, False, 'get', False)
- print(content)
- def notify_cut_state(gcp_code, progress, msg):
- url = contants.get_notify_url()
- PrintLog(msg)
- data = {"gcp_code": gcp_code, "msg": msg, "progress": progress}
- content = http_request(url, data, False, 'get', False)
- PrintLog(content)
- def http_request(url, data, is_https=False, method='post', is_json_type=False):
- try:
- headers = dict()
- if is_json_type is True:
- content_type = 'application/json; charset=UTF-8'
- else:
- content_type = 'application/x-www-form-urlencoded; charset=UTF-8'
- if is_https is True:
- url = 'https://%s' % url
- else:
- url = 'http://%s' % url
- headers['Content-Type'] = content_type
- post_data = set_params(data) if is_json_type is False else json.dumps(data)
- if method == 'post':
- result = requests.post(url, data=post_data, headers=headers, verify=False)
- else:
- result = requests.get(url + '?' + post_data, headers=headers, verify=False)
- content = result.text
- if not content:
- return False
- return content
- except Exception as e:
- return False
- def set_params(params={}):
- """
- 生成参数
- """
- import urllib
- if not isinstance(params, dict):
- raise Exception("You must pass in a dictionary!")
- params_list = []
- for k, v in params.items():
- if isinstance(v, list) and v:
- if isinstance(v[0], dict):
- params_list.append((k, json.dumps(v)))
- else:
- params_list.extend([(k, x) for x in v])
- elif isinstance(v, dict):
- params_list.append((k, json.dumps(v)))
- else:
- params_list.append((k, v))
- return urllib.urlencode(params_list)
|