前言
独立站上线之前,要对接好支付系统,这样客户才能通过网站购买商品,完成整个流程。
流程图
关键函数(python)
md5加密
def _sign_acquire(self, data):
'''
组织签名字符串
'''
unsigned_string = "{}&{}&{}&{}&{}".format(data['CurrencyType'], data['MerchantNo'], data['ProxyChannelType'], data['TransData'], self._md5_key)
logger.debug(unsigned_string)
sign = self._sign(unsigned_string)
logger.debug(sign)
# 获得最终的订单信息字符串
return sign
def _sign(self, s):
"""
生成签名字符串
"""
h = hashlib.md5()
h.update(s.encode(encoding='utf-8'))
digested = h.hexdigest()
#logging.warning(digested)
提交数据
def _fetch(self, url, data_json):
"""
post 提交数据
"""
headers = {'Content-Type': 'application/json;charset=UTF-8'}
#logger.debug(url)
req = urllib.request.Request(url, data=json.dumps(data_json).encode(), headers=headers)
try:
resp = urllib.request.urlopen(req, timeout=30)
except urllib.error.HTTPError as e:
resp = e
#logger.debug(resp.read().decode())
raw_dict = json.loads(resp.read().decode())
return raw_dict
评论 (0)