123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # -*- coding:UTF-8 -*-
- import requests,json
- import contants
- from print_log import printlog
- def notify_sp_cut_state(sp_code, progress, msg, ad_code_list):
- url = contants.get_sp_notify_url()
- if not ad_code_list:
- 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}
- printlog(str(data))
- content = http_request(url, data, False, 'get', False)
- printlog(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(str(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=None):
- """
- 生成参数
- """
- if params is None:
- 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.parse.urlencode(params_list)
|