def baseinfo(): if request.method == 'POST': json_data = request.get_data().decode('utf-8') try: try: # json_data = request.get_data().decode('utf-8') url_data = json.loads(json_data) sign = url_data.get('sign') except Exception as e: logger.exception('get sign Error:') logger.info(str(traceback.format_exc())) error_msg = {'msg': 'sign 获取失败'} return json.dumps(error_msg) else: my_sign = generateMD5( 'HZRESK001A20181122huichuanghuichuang666!') if my_sign == sign: config = { 'host': '127.0.0.1', 'port': 6379, 'db': 0, 'table': 'ts_order', 'password': '' } con_redis = redis.Redis(host=config['host'], port=config['port'], db=config['db'], password=config['password']) print(url_data.get('baseUrl')) print(url_data.get('operatorUrl')) redis_data = { 'reportUrl': url_data.get('reportUrl'), 'orderNo': url_data.get('orderNo'), 'operatorUrl': url_data.get('operatorUrl'), 'baseUrl': url_data.get('baseUrl') # 'resultUrl': url_data['callBackResult'] } con_redis.lpush(config['table'], json.dumps(redis_data)) logger.info('{0}...to redis Success'.format( url_data.get('orderNo'))) return json.dumps({'returnCode': 'SUCCESS'}) else: error_msg = {'msg': 'sign验证失败'} return json.dumps(error_msg) except Exception as e: logger.info("{0},programe Error....".format( str(json.loads(json_data).get('orderNo')))) logger.info(traceback.format_exc()) msg_data = { "returnCode": "FAIL", "errCode": " 1002 ", "errMsg": "联系管理员" } # send_mail('{0} 获取信息url时出错'.format(json.loads(json_data).get('orderNo'))) return json.dumps(msg_data)
def source_data(self, redis_data): order_data = json.loads(redis_data) # 订单号,推送接口,征信接口 try: # 获取数据 orderNo = order_data['orderNo'] reportUrl = order_data['reportUrl'] operatorUrl = order_data['operatorUrl'] baseUrl = order_data['baseUrl'] my_sign = generateMD5('HZRESK001A20181122huichuanghuichuang666!') try: # 合并数据 new_data = mergeData(orderNo, baseUrl, my_sign, reportUrl, operatorUrl) # 保存数据 logger.info('save {0} original data ...'.format( str(new_data['orderNo']))) save_data(new_data) logger.info('{0}-SUCCESS'.format(str(new_data['orderNo']))) except Exception as e: msg = '{0} 保存 数据失败 {1}'.format(str(order_data['orderNo']), datetime.datetime.now()) logger.info(msg) result_data = { "desc": '-1', "status": "内部错误", "orderNo": order_data['orderNo'], "mode_type": '', "comprehensive_score": "0" } save_score(result_data) # send_mail('msg') else: # 计算 try: model_type = 3 r_data = MyThread(rule_data, [ new_data, ]) p_data = MyThread(param_generate, [new_data, model_type]) r_data.start() p_data.start() r_data.join() p_data.join() logger.info('{0}-get ruleData:'.format( order_data['orderNo'])) ruleData = r_data.get_result() logger.info('{0}-get model_data:'.format( order_data['orderNo'])) model_data = p_data.get_result() # 规则得分入库入库 logger.info('{0}-save ruleData and model_data:'.format( order_data['orderNo'])) ths = Thread(target=saveRuleModelScore, args=(json.loads(model_data), ruleData)) ths.start() score = final_score(model_data, ruleData) result_data = { "merchantId": new_data['merchantId'], "appId": new_data['appId'], "channel": new_data['data']['channel'], "Time": datetime.datetime.now() } result_data.update(json.loads(score)) logger.info('{0}-save finally score...:'.format( order_data['orderNo'])) save_score(result_data) logger.info('{0}-save finally score SUCCESS:'.format( order_data['orderNo'])) except Exception as e: msg1 = '{0} param_generate or rule_data ERROR'.format( new_data['orderNo']) logger.info(msg1) result_data = { "merchantId": "", "appId": "", "desc": '-3', "status": "内部错误", "orderNo": order_data['orderNo'], "mode_type": '', "comprehensive_score": "0" } save_score(result_data) # send_mail(msg1) except Exception as e: # 返回模型分数 为 0 msg2 = '{0}-source_data Error:'.format(order_data['orderNo']) logger.info(msg2) logger.info(traceback.format_exc()) # 保存本地 error_msg = str(traceback.format_exc()).replace('"', "'").replace( '\n', '') error_msg_dict = { 'orderNo': order_data['orderNo'], "error_msg": str(error_msg), 'error_type': 2 } save_error(error_msg_dict) result_data = { "merchantId": "", "appId": "", "desc": '-2', "status": "内部错误", "orderNo": order_data['orderNo'], "mode_type": '', "comprehensive_score": "0" } save_score(result_data)
return str(base64.encodebytes(aes.encrypt(add_to_16(text))), encoding='utf8').replace('\n', '') # 揭秘 def text_decrypted(key, text): aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化加密器 return str( aes.decrypt(base64.decodebytes(bytes( text, encoding='utf8'))).rstrip(b'\0').decode("utf8")) from tools import generateMD5 if __name__ == '__main__': name = '1' idcard = '1' mobile = '1' tokenId = '' # 密码 appId = '' param = str("name=" + name + ',' + "idcard=" + idcard + ',' + "mobile=" + mobile) #name=1,idcard=1,mobile=1 print(param) tokenKey = generateMD5('http://api.tcredit.com/assessment/infernalProbe' + tokenId + param) text = 'abc123def456' # 待加密文本 print(encrypted_text(tokenId, text))