def get_public_wechat_qr_status(): orderid = request.args['orderid'] pay_record = get_pay(orderid) if not pay_record: raise err.ParamError('invalid orderid') return {'pay_status': pay_record.pay_status}
def post(self): """ required: response: {} or error """ card_name = request.form.get('card_name', '') bank_name = request.form.get('bank_name', '') card_number = request.form.get('card_number', '') subbank_name = request.form.get('subbank_name', '') card_type = int(request.form.get('card_type', 0)) extend = request.form.get('extend', '') if not card_name or not bank_name or not card_number or not subbank_name: raise err.ParamError('missing arguments') account_id = g.user['id'] data = { 'accountid': account_id, 'card_name': card_name, 'bank_name': bank_name, 'subbank_name': subbank_name, 'card_number': card_number, 'card_type': card_type, 'extend': extend } create_bankcard_info(account_id, data) return {}
def create_order(): try: data = json.loads(request.data) print data recharge_type = data.get("recharge_type") amount = float(data['amount'] * 100) except Exception as e: raise err.ParamError(e) if recharge_type not in ['QQ', 'qq', 'alipay']: raise err.ParamError('recharge_type error') if amount < 1: raise err.ParamError('充值金额太小') result = create_recharge_order(recharge_type, int(amount), g.user['id']) return result
def check_jinjian_sign(data, appid, signature): from copy import deepcopy data = deepcopy(data) data['appid'] = appid appkey = get_jinjian_appkey(appid) calculated_sign = generate_sign(data, appkey) if signature.lower() != calculated_sign: _LOGGER.info("sign: %s, calculated sign: %s", signature, calculated_sign) raise err.ParamError('sign not pass')
def pay_status(): """ 查询流量充值定单状态 """ try: order_id = long(request.args.get("order_id")) except Exception as e: raise err.ParamError("order_id error %s" % e) trans = db.get_transaction_by_rechargeid(order_id) if not trans: raise err.NoOrderID('no order id %s' % order_id) return {"status": trans.status}
def check_params( params, required_params, # 必须值 default_param_dct=None, # 默认值 param_type_dct=None, # 参数类型,GET一般需要强制转换 param_validfunc_dct=None): # 参数合法判定 """验证传入参数有效性,注意这里会对params做in-place修改 """ params = params or {} if not params and required_params: raise_with_traceback(err.ParamError('missing all')) for param in required_params: if param not in params: raise_with_traceback(err.ParamError('missing %s' % param)) if default_param_dct: for param in default_param_dct: if param not in params: params[param] = default_param_dct[param] if param_type_dct: for field, t in param_type_dct.iteritems(): if field in params: try: if t is basestring: t = smart_unicode params[field] = t(params[field]) except Exception: raise_with_traceback( err.ParamError('param %s type wrong' % field)) if param_validfunc_dct: for field, func in param_validfunc_dct.iteritems(): if field in params: try: assert func(params[field]) except AssertionError: raise_with_traceback( err.ParamError('param %s illegal' % field))
def create_app_manage(appname, app_type, pay_type, account_id): for t in pay_type: if t not in PAY_TYPE.values(): raise err.ParamError('pay_type') appid = redis_cache.appid_generator() app_manage = AppManage() app_manage.accountid = account_id app_manage.appid = appid app_manage.appname = appname app_manage.app_type = app_type app_manage.pay_type = json.dumps(pay_type) app_manage.valid = VALID_STATUS.AUDIT app_manage.save()
def post(): if not admin: raise err.PermissionError('Not allowed') params = request.get_json() daifu_ids = params.get('list') status = int(params.get('status', 1)) record = controller.update_daifu_records(daifu_ids, status) if status not in (DAIFU_STATUS.PERMITED, DAIFU_STATUS.REFUSED): raise err.ParamError('status invalid') if record: return {'result': 'success'} else: raise err.SystemError('record not found')
def post(self): """ check client input auth code required: phone, auth_code response: {} or error """ appname = request.form.get('name', '') app_type = request.form.get('app_type', '') pay_type = request.form.get('pay_type', '') try: pay_type = json.loads(pay_type) except Exception as e: raise err.ParamError('pay_type') account_id = g.user['id'] create_app_manage(appname, app_type, pay_type, account_id) return {}
def create_daifu_record(daifu_data): try: mchid = daifu_data['accountid'] amount = daifu_data['amount'] bank_name = daifu_data['bank_name'] bank_city = daifu_data['bank_city'] bank_account_name = daifu_data['bank_account_name'] bank_account_no = daifu_data['bank_account_no'] card_type = daifu_data['card_type'] bank_province = daifu_data['bank_province'] bank = daifu_data['bank'] status = DAIFU_STATUS.READY fee = DAIFU_FEE daifu_type = DAIFU_TYPE.YSEPAY except Exception, e: raise err.ParamError(e)
def sand_agent_pay(): query_dct = request.get_json(force=True) or {} _LOGGER.info('sand agent pay: %s' % query_dct) check_sign(query_dct) try: amount = str(query_dct['amount']) appid = query_dct['appid'] order_code = query_dct['orderCode'] acc_attr = query_dct['accAttr'] acc_type = query_dct['accType'] acc_no = query_dct['accNo'] acc_name = query_dct['accName'] pay_mode = query_dct['payMode'] trans_time = query_dct['transTime'] appid_detail = get_appid_detail(appid, real_pay=REAL_PAY.SAND) except Exception, e: _LOGGER.exception('sand agent pay error! %s' % e) raise err.ParamError(e)
def daifu_apply(): accountid = g.user['id'] post_data = json.loads(request.data) daifu_list = post_data['list'] total_amount = 0.00 for data in daifu_list: if [ 'amount', 'bank_name', 'bank_city', 'bank_account_no', 'bank_account_name', 'account_type', 'card_type' ] >= data.keys(): raise err.ParamError('params not valid') if float(data['amount']) <= 2: raise err.ResourceInsufficient(u"代付金额必须大于2元") total_amount += float(data['amount']) appid, account_balance = get_balance_by_accountid(accountid) if account_balance and total_amount >= account_balance: raise err.ResourceInsufficient("提现金额不足%s" % total_amount) controller.create_daifu_records(daifu_list, accountid) return {}
def post(self): if not g.user['id'] in ADMIN_MCH_ID: raise err.PermissionError("权限不对") for key in request.form: if key not in ['real_pay', 'mch_name', 'phone', 'appname', 'app_type', 'pay_type', 'service_fee', 'pay_fee', 'trans_fee', 'withdraw_fee', 'extend', 'bank_name', 'balance_type', 'card_number', 'balance_name', 'bank_city', 'card_name', 'bank_no', 'userid_card']: raise err.ParamError(key) print 'post a management', request.form phone = request.form.get('phone') appname = request.form.get('appname') if db.get_user_by_phone(phone): raise err.Issue("手机号重复%s" % phone) if db.get_appmanage_by_name(appname): raise err.Issue("产品名重复%s" % appname) db.create_merchant(request.form) return {}
def list_merchant_jinjians(): """ 列出商户进件信息 """ accountid = g.user['id'] merchant_id = request.args.get('id') if merchant_id: jinjian = db.get_jinjian_by_appmanageid(merchant_id) if not jinjian: raise err.Issue(merchant_id) # 这个错误有问题 return { "info": controller.parse_jinjian_info(jinjian), "status": jinjian.status, "updated_at": tz.utc_to_local_str(jinjian.updated_at) } begin_at = request.args.get('begin_at') end_at = request.args.get('end_at') bank_name = request.args.get("bank_name") mch_name = request.args.get("mch_name") mch_short_name = request.args.get("mch_shortName") appname = request.args.get('appname') app_type = request.args.get('app_type') appid = request.args.get('appid') page = request.args.get('page', 1) page = int(page) size = request.args.get('size', 10) size = int(size) if bank_name not in ['', 'd0', 'd1', 'd0,d1']: raise err.ParamError(bank_name) if bank_name == 'd0,d1': bank_name = '' valid, status = '', '' return controller.get_app_manage(accountid, page, size, appid, app_type, valid, status, bank_name, begin_at, end_at, mch_name, mch_short_name, appname, bank_name.upper())
try: appid = query_dct['appid'] wechatid = query_dct.get('wechatid') pay_type = int(query_dct.get('payType')) appid_detail = get_appid_detail(appid, pay_type, polling=False) except Exception, e: _LOGGER.exception('create pay error!') raise err.SystemError() if not appid_detail: raise err.AppIDWrong() if not appid_detail.valid: raise err.AppidInvalid() orderid = query_dct['orderid'] amount = Decimal(query_dct['amount']) if not check_payamount(amount): raise err.ParamError('amount should not be divided by 10') notify_url = query_dct['notifyUrl'] ordername = query_dct.get('subject') clientip = query_dct.get('clientip') order_info = query_dct.get('orderInfo') return_url = query_dct.get('returnUrl') description = query_dct.get('description') try: pay_record = create_pay_record(orderid, appid_detail.accountid, appid, pay_type, amount, notify_url, description) except IntegrityErrors: raise err.DuplicateOrderID() except Exception as e: _LOGGER.exception('db error') raise err.SystemError()
def otp_verify(): account_id = g.user['id'] otp = request.form.get('otp') if not otp or len(otp) != 6: raise err.ParamError('otp') return otp_check(account_id, otp)