Beispiel #1
0
def wechat_h5_pay(pay_record, ordername, clientip):
    amount, orderid, appid = pay_record.amount, pay_record.id, pay_record.appid
    url = 'https://cebwhaop.koolyun.com/apmp/rest/v2/'
    data = gen_pay_params(amount, orderid, ordername, _NOTIFY_URL, clientip,
                          appid)
    sign = sign_string(data)
    appkey = 'HYM17002P-K6'  # 扫码的appkey没有-k6
    params = {"params": '%s' % data}
    headers = {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
        "x-appkey": appkey,
        "x-apsignature": sign
    }
    d = requests.post(url, data=params, headers=headers)
    _LOGGER.info(d.content)
    try:
        resp_data = json.loads(d.text[1:-1])
        h5_url = resp_data.get('mwUrl')
        originid = resp_data.get('transId')
        save_originid(pay_record.id, originid)
    except Exception:
        _LOGGER.exception("guangda h5 pay error")
        raise err.SystemError()
        h5_url = None
    try:
        if d.status_code == 200 and h5_url:
            return {'status': 0, 'url': h5_url}
        else:
            raise err.SystemError(resp_data.data.get('errorMsg'))
    except Exception, e:
        _LOGGER.exception(e)
        raise err.SystemError()
Beispiel #2
0
def withdraw_query():
    data = request.get_json(force=True) or {}
    check_sign(data)
    try:
        appid = data['appid']
        order_code = data['orderCode']
        # appid_detail = get_appid_detail(appid, real_pay=REAL_PAY.KEDA)
        trans_time = data.get('transTime', None)
        appid_detail = get_appid_detail(appid)  # , real_pay=REAL_PAY.KEDA)
    except KeyError as e:
        raise err.RequestParamError(u"缺少%s" % str(e))
    except Exception:
        _LOGGER.exception('withdraw query error')
        raise err.SystemError()
    if appid_detail.real_pay == REAL_PAY.KEDA:
        if appid_detail.paymenttype != 'D0':
            raise err.OnlyD0SupportWithdraw()
        result = keda.query_d0_withdraw(appid_detail.custid, order_code)
        if result['error'] == -1:
            raise err.SystemError(result['message'])
        else:
            _data = result['data']
            _data['orderMoney'] = str(Decimal(_data['orderMoney']) / 100)
            return {'status': 0, 'data': _data}
    if appid_detail.real_pay == REAL_PAY.SAND:
        if not trans_time:
            raise err.SystemError("transTime arg missing")
        result = sand.query_d0_withdraw(appid_detail.custid, order_code,
                                        trans_time)
        if result['respCode'] != '0000':
            raise err.SystemError(result['respDesc'])
        else:
            return result
Beispiel #3
0
def alipay_h5_pay(pay_record, ordername, return_url):
    appid, pay_type, amount, pay_id = pay_record.appid, pay_record.pay_type, pay_record.amount, pay_record.id
    appid_detail = get_appid_detail(appid, pay_type)
    alipay_appid = get_cached_random_alipay_appid()
    alipay_id, pub_key, notify_url = alipay_appid.aliappid, alipay_appid.public_key, alipay_appid.notify_url
    if not appid_detail or not alipay_id:
        raise err.AppIDWrong()
    alipay = AliPay(
        appid=alipay_id,
        app_notify_url="http://p.51paypay.net/pay/404/",
        app_private_key_path=open("static/private.key").read(),
        alipay_public_key_path=pub_key,
        sign_type="RSA2",  # RSA 或者 RSA2
        debug=False  # 默认False
    )
    order_string = alipay.api_alipay_trade_wap_pay(out_trade_no=str(pay_id),
                                                   total_amount=float(amount),
                                                   subject=ordername,
                                                   return_url=return_url,
                                                   notify_url=notify_url)
    mid_url = 'https://openapi.alipay.com/gateway.do?' + order_string
    pay_request = requests.get(mid_url, allow_redirects=False)
    real_url = pay_request.headers.get('Location')
    if real_url:
        return {'status': 0, 'pay_url': real_url}
    else:
        raise err.SystemError()
Beispiel #4
0
def qr_pay(pay_record, order_info=None):
    url = 'http://115.182.112.96/trans-api/trans/api/back.json'
    appid, pay_type, amount, pay_id = pay_record.appid, pay_record.pay_type, pay_record.amount, pay_record.id
    appid_detail = get_account_appid(appid, pay_type)
    trans_pay_type = _TRANS_PAY_TYPE[pay_type]
    if not appid_detail:
        raise err.AppIDWrong()
    custid = appid_detail.custid
    data = {
        'version': '1.0.0',
        'transType': 'SALES',
        'productId': trans_pay_type,
        'merNo': custid,
        'orderDate': tz.ts_to_local_date_str(tz.now_milli_ts()),
        'orderNo': int(time.time()),
        'notifyUrl': 'http://p.51paypay.net/api/v1/pay/wanhong/callback',
        'transAmt': int(amount * 100),
        'commodityName': order_info,
    }
    sign = generate_sign(data)
    data['signature'] = sign
    resp = requests.post(url, data=data)
    resp_data = json.loads(resp.text)
    respCode = resp_data.get('respCode')
    codeUrl = resp_data.get('codeUrl')
    if respCode == '0000':
        return {'status': 0, 'qrCode': codeUrl}
    else:
        respDesc = resp_data.get('respDesc')
        raise err.SystemError(respDesc)
Beispiel #5
0
 def post():
     if not admin:
         raise err.PermissionError('Not allowed')
     params = request.get_json()
     withdraw_id = params.get('withdraw_id')
     status = params.get('status')
     record = controller.update_withdraw(withdraw_id, status)
     if record:
         return {'result': 'success'}
     else:
         raise err.SystemError('record not found')
Beispiel #6
0
def wechat_sdk_pay(pay_record, wechatid, ordername):
    appid, pay_id, amount = pay_record.appid, pay_record.id, pay_record.amount
    url = 'https://cebwhaop.koolyun.com/apmp/rest/v2/'
    custid = pay_record.real_custid
    data = {
        'action': 'wallet/trans/appSale',
        'version': '2.0',
        'reqTime': datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
        'appId': wechatid,
        'reqId': pay_id,
        'custId': custid,
        'orderDesc': ordername,
        'totalAmount': int(amount * 100),
        'notifyUrl': _NOTIFY_URL,
        'acquirerType': 'wechat',
    }
    data = '[%s]' % json.dumps(data)
    sign = sign_string(data)
    params = {'params': '%s' % data}
    headers = {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
        "x-appkey": 'HYM17002P-K6',
        "x-apsignature": sign
    }
    try:
        resp = requests.post(url, data=params, headers=headers)
        text = resp.text
        _LOGGER.info(text)
        resp_data = json.loads(text[1:-1])
        originid = resp_data.get('transId')
        save_originid(pay_record.id, originid)
        payinfo = resp_data.get('payInfo')
    except Exception as e:
        _LOGGER.exception('get wechat app pay error')
        raise err.SystemError()
    if payinfo:
        return json.loads(payinfo)
    else:
        raise err.SystemError()
Beispiel #7
0
def qr_pay(pay_record, order_info=None):
    appid, pay_type, amount, pay_id = pay_record.appid, pay_record.pay_type, pay_record.amount, pay_record.id
    acquirer_type = convert_accquire_type(pay_type)
    url = 'https://cebwhaop.koolyun.com/apmp/rest/v2/'
    custid = pay_record.real_custid
    _LOGGER.info('custid: %s' % custid)
    data = {
        "action": "wallet/trans/csbSale",
        "version": "2.0",
        "reqTime": datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
        "reqId": pay_id,
        "custId": custid,
        "totalAmount": int(amount * 100),
        "acquirerType": acquirer_type,
        "notify_url": _NOTIFY_URL
    }
    data = '[%s]' % json.dumps(data)
    sign = sign_string(data)
    params = {'params': '%s' % data}
    headers = {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
        "x-appkey": 'HYM17002P',
        "x-apsignature": sign
    }
    try:
        resp = requests.post(url, data=params, headers=headers, timeout=3)
        text = resp.text
        _LOGGER.info(text)
        resp_data = json.loads(text[1:-1])
        qrCode = resp_data.get('qrCode')
        originid = resp_data.get('transId')
        save_originid(pay_record.id, originid)
    except Exception as e:
        _LOGGER.exception('get guangda qrCode error')
        raise err.SystemError()
    if qrCode:
        return {'status': 0, 'qrCode': qrCode}
    else:
        raise err.SystemError()
Beispiel #8
0
 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')
Beispiel #9
0
def qr_pay(pay_record, order_info):
    """
    response:
    {"message":"您的支付宝支付未激活","error":-1,"success":false}
    """
    appid, pay_type, amount, pay_id = pay_record.appid, pay_record.pay_type, pay_record.amount, pay_record.id
    appid_detail = get_appid_detail(appid, pay_type)
    if not appid_detail:
        raise err.AppIDWrong()
    custid = appid_detail.custid
    banklinknumber = appid_detail.banklinknumber
    paymenttype = appid_detail.paymenttype
    data = {
        'bankLinkNumber': banklinknumber,
        'orderInfo': order_info,
        'orderMoney': int(amount * 100),
        'orderCode': pay_id,
        'notifyUrl': _NOTIFY_URL,
        'paymentType': paymenttype
    }
    if pay_type == PAY_TYPE.WECHAT_QR:
        url = 'http://116.62.100.174/Bank/mobile/zhBank/placeOrder'
        data['tradeType'] = 'NATIVE'
        data['productId'] = '101'
    elif pay_type in (PAY_TYPE.ALIPAY_QR, PAY_TYPE.ALIPAY_H5):
        url = 'http://116.62.100.174/Bank/mobile/zhBank/aliScanPay'
        data[
            'limitPay'] = 'pcredit,pcreditpayInstallment,creditCard,creditCardExpress,creditCardCartoon,credit_group'
    else:
        raise ValueError('not support pay type')
    k = pyDes.des(_KEY,
                  pyDes.ECB,
                  "\0\0\0\0\0\0\0\0",
                  pad=None,
                  padmode=pyDes.PAD_PKCS5)
    d = base64.b64encode(k.encrypt(json.dumps(data)))

    resp = requests.post(url,
                         json={
                             'officeCode': _OFFICECODE,
                             'merchantcode': custid,
                             'date': d
                         },
                         timeout=3)
    resp_data = json.loads(resp.text)
    if resp_data['error'] == 0:
        orginid = resp_data['data']['platformTradeCode']
        save_originid(pay_record.id, orginid)
        return {'status': 0, 'qrCode': resp_data['data']['picURL']}
    else:
        raise err.SystemError(resp_data['message'])
Beispiel #10
0
def submit_pay():
    def check_payamount(s):
        if int(float(s)) % 10 == 0 and abs(
                int(float(s)) - float(s)) < 0.0099999999999999999999:
            return False
        return True

    # raise err.SystemError('支付宝渠道维护,请使用其他方式支付.')
    query_dct = request.get_json(force=True) or {}
    _LOGGER.info('submit_pay: %s' % query_dct)
    check_sign(query_dct)
    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()
Beispiel #11
0
def alipay_traffic_pay(amount, orderid):
    alipay = AliPay(
        appid="2017112300109792",
        app_notify_url="http://p.51paypay.net/pay/404/",
        app_private_key_path=open("static/private.key").read(),
        alipay_public_key_path=open("static/public.key").read(),
        sign_type="RSA2",  # RSA 或者 RSA2
        debug=False  # 默认False
    )
    order_string = alipay.api_alipay_trade_wap_pay(
        out_trade_no=orderid,
        total_amount=amount,
        subject='流量充值',
        return_url='http://www.51paypay.net/',
        notify_url="http://p.51paypay.net/admin/service/alipay/pay_callback")
    mid_url = 'https://openapi.alipay.com/gateway.do?' + order_string
    pay_request = requests.get(mid_url, allow_redirects=False)
    real_url = pay_request.headers.get('Location')
    if real_url:
        return real_url
    else:
        raise err.SystemError()
Beispiel #12
0
        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()
    finally:
        orm.session.rollback()

    pay_handler = _PAY_HANDLER[appid_detail.real_pay]
    # 支付宝扫码付线下要一元以上
    if pay_type == PAY_TYPE.ALIPAY_QR and amount < Decimal('1'):
        raise err.MiniAmount()
    if pay_type == PAY_TYPE.WECHAT_H5:
        result = pay_handler.wechat_h5_pay(pay_record, ordername, clientip)
    elif pay_type == PAY_TYPE.ALIPAY_REAL_H5:
        result = pay_handler.alipay_h5_pay(pay_record, ordername, return_url)
    elif pay_type in (PAY_TYPE.WECHAT_QR, PAY_TYPE.QQ_QR, PAY_TYPE.ALIPAY_QR,
                      PAY_TYPE.ALIPAY_H5):
        result = pay_handler.qr_pay(pay_record, order_info)
        if pay_type == PAY_TYPE.ALIPAY_H5 and 'qrCode' in result: