def decode_status(order): if order.get('product') == 'data': if order.get('back_result') is None and order.get('result') == '00000': return '充值中' else: return escape_data_result( order.get('back_result') or order.get('result')) else: return escape_fee_result( order.get('back_result') or order.get('result'))
def decode_status(order): if order.product == 'data': if order.back_result is None and order.result == '00000': return '充值中' else: return escape_data_result(order.back_result or order.result) elif order.product == 'sinopec': return escape_sinopec_result(order.back_result or order.result) else: return escape_fee_result(order.back_result or order.result)
def decode_status(order): if order['product'] == 'data': if order['back_result'] is None and order['result'] == '00000': return '充值中' else: return escape_data_result(order['back_result'] or order['result']) elif order['product'] == 'sinopec': return escape_sinopec_result(order['back_result'] or order['result']) else: return escape_fee_result(order['back_result'] or order['result'])
def post(self, path_args): user_id = self.current_user['partner_id'] prod = self.json_args['prod'] number = self.json_args['number'] downstream = self.application.config['downstream'][user_id] if 'master' in downstream: master_id = downstream['master'] else: master_id = user_id key = 'product:{master_id}:sinopec:{prod}'.format(master_id=master_id, prod=prod) product = self.master.hget(key, 'value') if product[0] is None: self.write_error(405) return if not re.match(r'\d{19}', number): self.write_error(405) return try: order_id = self.order_id() ORDER_FORMAT = 'product=sinopec&userid={userid}&price={price}&num=1&account_number={account_number}&spordertime={spordertime}&sporderid={sporderid}' back_url = self.application.config['connection'][ 'fuel_card_callback'] order = ORDER_FORMAT.format( userid=user_id, price=product, account_number=number, spordertime=datetime.now().strftime("%Y%m%d%H%M%S"), sporderid=order_id) sign = order + "&key=" + downstream['key'] requ_body = order + "&sign=" + to_md5( sign) + "&back_url=" + back_url url = 'http://{shard}/order.do'.format(shard=downstream['shard']) http_client = AsyncHTTPClient() request = HTTPRequest(url=url, method='POST', body=requ_body) response = yield http_client.fetch(request) if response.code == 200: resp = response.body.decode('utf8') print(resp) root = ET.fromstring(resp) result = root.find('resultno').text request_no = root.find('sporderid').text if result == '0': order_id = root.find('orderid').text msg = { 'status': 'ok', 'msg': '充值请求发送成功', 'sp_order_id': request_no, 'order_id': order_id } self.master.hmset('latest:%s' % user_id, { 'prod': prod, 'number': number }) else: msg = { 'status': 'fail', 'msg': '充值请求发送失败,错误原因:{info}({result})'.format( info=escape_fee_result(result), result=result), 'sporderid': request_no } except Exception as e: request_log.error("SINOPEC CHARGE EXCEPTION {0}".format(e)) request_log.exception("SINOPEC CHARGE EXCEPTION") msg = {'status': 'fail'} self.write(json.dumps(msg))
def post(self): args = self.json_args http_client = AsyncHTTPClient() try: db1 = self.application.glados_client.GLaDOS.order order_id = args['id'] order = yield db1.find_one(order_id) up_order_list = order.get('up_order', []) product = order.get('product') detail_list = [] for up_order in up_order_list: up_info = {'title': '上游订单'} content_list = [] up_info['content'] = content_list content_list.append({ 'k': '上游订单号', 'v': up_order.get('up_order_id') or '无' }) content_list.append({'k': '渠道', 'v': up_order.get('route')}) content_list.append({ 'k': '请求时间', 'v': str(up_order.get('up_req_time') or '暂无') }) content_list.append({ 'k': '返回时间', 'v': str(up_order.get('up_resp_time') or '暂无') }) content_list.append({ 'k': '回调时间', 'v': str(up_order.get('up_back_time') or '暂无') }) content_list.append({ 'k': '订单结果', 'v': up_order.get('up_result', '暂无') }) if up_order.get('up_back_result'): if product == 'fee': content_list.append({ 'k': '充值结果', 'v': escape_fee_result(up_order.get('up_back_result')) }) elif product == 'data': content_list.append({ 'k': '充值结果', 'v': escape_data_result(up_order.get('up_back_result')) }) else: content_list.append({'k': '充值结果', 'v': '暂无'}) detail_list.append(up_info) # 返回页面 if up_order.get('route') == 'machado': base_url = self.application.config['connection'][ 'forrestal_query'] base_url += '/cmcc_fee/query_order?requ_type=by_order_id&order_id=' + order_id data = yield get_route(base_url) if data.get('status') == 'ok': forrestal_order = data['data']['order_list'][0] card_info = {'title': '卡充信息', 'content': []} card_info['content'].append({ 'k': '手机', 'v': forrestal_order.get('mobile', '无') }) card_info['content'].append({ 'k': '卡号', 'v': forrestal_order.get('card_id', '无') }) card_info['content'].append({ 'k': '结果', 'v': decode_agent(forrestal_order.get('result')) }) detail_list.append(card_info) agent_index = 1 for agent in forrestal_order.get('agents'): agent_info = {'title': '拨打 #' + str(agent_index)} agent_info['content'] = content_list = [] content_list.append({ 'k': '话机号码', 'v': agent.get('agent') }) content_list.append({ 'k': '结果', 'v': decode_agent(agent.get('result')) }) content_list.append({ 'k': '时间', 'v': str(agent.get('tsp')) }) detail_list.append(agent_info) agent_index += 1 self.finish(json.dumps({'up_detail': detail_list})) except Exception: request_log.exception('QUERY CHAIN') self.send_error(500) finally: http_client.close()