Esempio n. 1
0
def pay_request(request):
    '''
    当面付请求逻辑
    '''
    num = int(request.POST.get('num', ''))
    context = {}
    if num < 1:
        info = {
            'title': '失败',
            'subtitle': '请保证金额大于1元',
            'status': 'error',
        }
        context['info'] = info
    else:
        out_trade_no = datetime.datetime.fromtimestamp(
            time.time()).strftime('%Y%m%d%H%M%S%s')
        try:
            # 获取金额数量
            amount = num
            # 生成订单
            trade = alipay.api_alipay_trade_precreate(
                subject=settings.ALIPAY_TRADE_INFO.format(amount),
                out_trade_no=out_trade_no,
                total_amount=amount,
                timeout_express='60s',
            )
            # 获取二维码链接
            code_url = trade.get('qr_code', '')
            request.session['code_url'] = code_url
            request.session['out_trade_no'] = out_trade_no
            request.session['amount'] = amount
            info = {
                'title': '请求成功!',
                'subtitle': '支付宝扫描下方二维码付款,付款完成记得按确认哟!',
                'status': 'success',
            }
            context['info'] = info
        except:
            res = alipay.api_alipay_trade_cancel(out_trade_no=out_trade_no)
            info = {
                'title': '糟糕,当面付插件可能出现问题了',
                'subtitle': '如果一直失败,请后台联系站长',
                'status': 'error',
            }
            context['info'] = info

    result = json.dumps(context, ensure_ascii=False)
    return HttpResponse(result, content_type='application/json')
Esempio n. 2
0
def pay_request(request):
    '''
    当面付请求逻辑
    '''
    num = int(request.POST.get('num', ''))
    context = {}
    if num < 1:
        info = {
            'title': '失败',
            'subtitle': '请保证金额大于1元',
            'status': 'error', }
        context['info'] = info
    else:
        out_trade_no = datetime.datetime.fromtimestamp(
            time.time()).strftime('%Y%m%d%H%M%S%s')
        try:
            # 获取金额数量
            amount = num
            # 生成订单
            trade = alipay.api_alipay_trade_precreate(
                subject=settings.ALIPAY_TRADE_INFO.format(amount),
                out_trade_no=out_trade_no,
                total_amount=amount,
                timeout_express='60s',)
            # 获取二维码链接
            code_url = trade.get('qr_code', '')
            request.session['code_url'] = code_url
            request.session['out_trade_no'] = out_trade_no
            request.session['amount'] = amount
            info = {
                'title': '请求成功!',
                'subtitle': '支付宝扫描下方二维码付款,付款完成记得按确认哟!',
                'status': 'success', }
            context['info'] = info
        except:
            res = alipay.api_alipay_trade_cancel(
                out_trade_no=out_trade_no)
            info = {
                'title': '糟糕,当面付插件可能出现问题了',
                'subtitle': '如果一直失败,请后台联系站长',
                'status': 'error', }
            context['info'] = info

    result = json.dumps(context, ensure_ascii=False)
    return HttpResponse(result, content_type='application/json')