def get_pay_info(self): # 获取支付信息 sign = self.create_sign(self.pay_data) self.pay_data['sign'] = sign xml_data = self.dict_to_xml(self.pay_data) headers = {'Content-Type': 'application/xml'} response = Http.post(self.unified_order_url, xml_data, headers, return_json=False) if response: wx_result = self.xml_to_dict(response) if wx_result.get('return_code') == 'FAIL': self.process_login_error(wx_result['return_msg']) if wx_result.get('result_code') == 'FAIL': self.process_login_error(wx_result['err_code']) else: prepay_id = wx_result.get('prepay_id') pay_sign_data = { 'appId': self.pay_data.get('appid'), 'timeStamp': str(int(time.time())), 'nonceStr': self.pay_data.get('nonce_str'), 'package': 'prepay_id={0}'.format(prepay_id), 'signType': 'MD5' } pay_sign = self.create_sign(pay_sign_data) pay_sign_data.pop('appId') pay_sign_data['paySign'] = pay_sign return pay_sign_data else: raise Exception()
def get_close_info(self): sign = self.create_sign(self.pay_data) self.pay_data['sign'] = sign xml_data = self.dict_to_xml(self.pay_data) headers = {'Content-Type': 'application/xml'} response = Http.post(self.close_order_url, xml_data, headers, return_json=False) if response: wx_result = self.xml_to_dict(response) if wx_result.get('return_code') == 'FAIL': self.process_login_error(wx_result['return_msg']) else: return wx_result else: raise Exception()