Esempio n. 1
0
def generate_sem_sn(user_id=0, size=_SN_GEN_LEN):
    size = size if size is not None else _SN_GEN_LEN

    d = (datetime.utcnow() - _start).total_seconds()
    s = config.Biz.TX_SN_PREFIX + str(int(d)) + '-%d-' % user_id
    l = size - len(s)
    return s + strings.gen_rand_str(l)
Esempio n. 2
0
def generate_date_sn(user_id=0, size=_SN_MAX_LEN):
    # 8 + n + x + suffix
    size = size if size is not None else _SN_MAX_LEN

    dt = datetime.utcnow().strftime('%Y%m%d%H%M%S')
    s = dt + str(user_id)
    l = size - len(s) - len(config.Biz.TX_SN_NUM_SUFFIX)
    return s + strings.gen_rand_str(
        l, strings.string.ascii_lowercase) + config.Biz.TX_SN_NUM_SUFFIX
Esempio n. 3
0
def keys_gen():
    md5_key_str = strings.gen_rand_str(32)

    channel_pri_key = public_key.generate_key()
    channel_pub_key = channel_pri_key.gen_public_key()
    channel_pri_key_str = channel_pri_key.b64encoded_binary_key_data()
    channel_pub_key_str = channel_pub_key.b64encoded_binary_key_data()
    return jsonify(MD5_KEY=md5_key_str,
                   CHANNEL_PRI_KEY=channel_pri_key_str,
                   CHANNEL_PUB_KEY=channel_pub_key_str)
Esempio n. 4
0
File: payment.py Progetto: webee/pay
def pay_param(sn):
    params = {
        'sn': sn,
        'nonce_str': strings.gen_rand_str(32),
        '_url': zyt_pay.Payment.WEB_URL
    }

    params = _append_sign(params)
    logger.info("request zyt pay WEB: {0}".format(params))

    return params
Esempio n. 5
0
File: payment.py Progetto: webee/pay
def query_order(out_trade_no='', transaction_id='', app_config=None):
    app_config = app_config or config.AppConfig()

    params = {
        'appid': app_config.APPID,
        'mch_id': app_config.MCH_ID,
        'transaction_id': transaction_id,
        'out_trade_no': out_trade_no,
        'nonce_str': strings.gen_rand_str(32),
    }
    data = request(config.QUERY_ORDER_URL, params, app_config=app_config)
    if is_success_request(data, do_raise=True):
        return data
Esempio n. 6
0
def _generate_verification_code(source, user_id):
    verification_code = VerificationCode.query.filter_by(
        source=source, user_id=user_id).first()
    if verification_code is None:
        verification_code = VerificationCode(source=source, user_id=user_id)

    code = strings.gen_rand_str(6, string.digits)
    expire_at = datetime.utcnow() + timedelta(minutes=5)
    verification_code.code = code
    verification_code.expire_at = expire_at

    db.session.add(verification_code)

    return verification_code.code
Esempio n. 7
0
def add_sign_for_params(channel_name, params, sign_type=SignType.RSA):
    if params is None:
        return params

    channel = get_channel_by_name(channel_name)

    # 这里的主要作用是签名,只需要lvye_pri_key或md5_key
    signer = Signer('key', 'sign', channel.md5_key, config.LVYE_PRI_KEY, None)
    # 用来加密lvye_pub_key
    channel_pub_key = public_key.loads_b64encoded_key(channel.public_key)
    params['channel_name'] = channel_name
    params['sign_type'] = sign_type
    params['sign'] = signer.sign(params, sign_type)
    # 每次动态生成此密码
    lvye_aes_key = gen_rand_str(16)
    params['_lvye_pub_key'] = aes.encrypt_to_base64(config.LVYE_PUB_KEY,
                                                    lvye_aes_key)
    params['_lvye_aes_key'] = channel_pub_key.encrypt_to_base64(lvye_aes_key)

    return params
Esempio n. 8
0
File: bill.py Progetto: webee/pay
def download_bill(bill_date=None,
                  bill_type=config.BillType.ALL,
                  device_info='',
                  app_config=None):
    from api_access import _parse_data
    app_config = app_config or config.AppConfig()
    if bill_date is None:
        bill_date = times.today()

    params = {
        'appid': app_config.APPID,
        'mch_id': app_config.MCH_ID,
        'device_info': device_info,
        'nonce_str': strings.gen_rand_str(32),
        'bill_date': _date_to_str(bill_date),
        'bill_type': bill_type
    }

    data = request(config.DOWNLOAD_BILL_URL,
                   params,
                   app_config=app_config,
                   ret_raw_data=True,
                   log_resp=False)

    try:
        _ = _parse_data(data)
    except DataParsingError as _:
        pass

    lines = data.splitlines()
    header = lines[0]
    names = header.split(',')
    res = []
    for line in lines[1:-2]:
        values = line.lstrip('`').split(',`')
        res.append(values)
    stat_names = lines[-2].split(',')
    state_values = lines[-1].lstrip('`').split(',`')
    return names, res, stat_names, state_values
Esempio n. 9
0
def generate_sn():
    # FIXME: use localtime.
    s = datetime.now().strftime('%Y%m%d%H%M%S')
    l = _SN_MAX_LEN - len(s) - len(config.Biz.TX_SN_NUM_SUFFIX)
    return s + strings.gen_rand_str(l, strings.string.ascii_lowercase) + config.Biz.TX_SN_NUM_SUFFIX
Esempio n. 10
0
def gen_signature():
    return strings.gen_rand_str(32)
Esempio n. 11
0
File: payment.py Progetto: webee/pay
def prepay(source,
           trade_type,
           out_trade_no,
           total_fee,
           ip,
           body,
           time_start,
           detail='',
           fee_type='CNY',
           device_info='WEB',
           attach='',
           goods_tag='',
           product_id='',
           limit_pay='',
           openid='',
           app_config=None):
    notify_url = generate_absolute_url(
        url_for('weixin_pay_entry.pay_notify',
                source=source,
                app=app_config.APP_NAME))

    time_start = times.utc2gmt8(time_start)
    time_expire = times.utc2gmt8(
        times.from_now_offset(config.DEFAULT_ORDER_EXPIRATION_SECONDS))

    app_config = app_config or config.AppConfig()
    params = {
        'appid': app_config.APPID,
        'mch_id': app_config.MCH_ID,
        'device_info': device_info,
        'nonce_str': strings.gen_rand_str(32),
        'body': body[:32],
        'detail': detail[:8192],
        'attach': attach,
        'out_trade_no': out_trade_no,
        'fee_type': fee_type,
        'total_fee': total_fee,
        'spbill_create_ip': ip,
        'time_start': times.datetime_to_str(time_start),
        'time_expire': times.datetime_to_str(time_expire),
        'goods_tag': goods_tag,
        'notify_url': notify_url,
        'trade_type': trade_type,
        'product_id': product_id,
        'limit_pay': limit_pay,  # no_credit--指定不能使用信用卡支付
        'openid': openid,  # trade_type=JSAPI, 此参数必传,用户在商户appid下的唯一标识
    }
    data = request(config.UNIFIED_ORDER_URL, params, app_config=app_config)

    if is_success_request(data, do_raise=True):
        if trade_type == config.TradeType.APP:
            # prepare params
            params = {
                'appid': app_config.APPID,
                'partnerid': app_config.MCH_ID,
                'prepayid': data['prepay_id'],
                'package': 'Sign=WXPay',
                'noncestr': strings.gen_rand_str(32),
                'timestamp': str(int(times.timestamp())),
            }
            params = append_md5_sign(app_config.APP_NAME, params)
            return params
        elif trade_type == config.TradeType.NATIVE:
            return data['code_url']
        elif trade_type == config.TradeType.JSAPI:
            params = {
                'appId': app_config.APPID,
                'timeStamp': str(int(times.timestamp())),
                'nonceStr': strings.gen_rand_str(32),
                'package': 'prepay_id=%s' % data['prepay_id'],
                'signType': 'MD5',
            }
            params['paySign'] = append_md5_sign(app_config.APP_NAME,
                                                params,
                                                ret_sign=True)
            return params
        return data
Esempio n. 12
0
def generate_order_id(tx_id):
    # #->-, .->_
    d = (datetime.utcnow() - _start).total_seconds()
    s = '#' + str(tx_id) + '.' + str(int(d)) + '.'
    l = _SN_GEN_LEN - len(s)
    return s + strings.gen_rand_str(l)