V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
kangsgo
V2EX  ›  Python

Django 支付宝异步接收不到请问能帮我看一下么

  •  
  •   kangsgo · 2018-06-12 19:54:54 +08:00 · 1446 次点击
    这是一个创建于 2116 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我的代码如下:

    @login_required(login_url='/accounts/login/')
    @csrf_exempt
    def apliy_check_pay(request):
        alipay=AliPay(
            appid=ALIPAY_APPID,
            app_notify_url=set_url,
            app_private_key_path=os.path.join(settings.BASE_DIR, "app/app_private_key.pem"),
            alipay_public_key_path=os.path.join(settings.BASE_DIR, "app/alipay_public_key.pem"),
            sign_type="RSA2",
            debug=True,
        )
        if request.method == 'POST':
            mydata=request.POST.dict()
            signature = mydata.pop("sign")
            success=alipay.verify(mydata,signature)
            if success:
                order_sn=mydata['out_trade_no']
                trade_no=mydata['trade_no']  
                myfunding=Funding.objects.filter(number=order_sn)
                existed_orders=myfunding.update(
                        fudingpaid=True,
                        number=str(order_sn),
                        trade_no=str(trade_no),
                )
                return HttpResponse('支付成功')
        if request.method == 'GET':
            params=request.GET.dict()	
            #test=request.GET.get('trade_status')	
            sign=params.pop('sign',None)
            print(sign)
            status=alipay.verify(params,sign)
            if status:
                order_sn=params['out_trade_no']
                trade_no=params['trade_no']
                myfunding=Funding.objects.filter(number=order_sn)
                existed_orders=myfunding.update(
                        fudingpaid=True,
                        number=str(order_sn),
                        trade_no=str(trade_no),
                )
                return HttpResponse('支付成功')
            return HttpResponse('支付失败')
        else:
            return  HttpResponseRedirect(reverse('accounts:payment_funding'))
    

    GET 是可以 GET 到的,是 POST 哪里写错了么?

    使用的 github 上该封装 https://github.com/fzlee/alipay/blob/master/README.zh-hans.md

    kangsgo
        1
    kangsgo  
    OP
       2018-06-12 20:07:21 +08:00
    另外 GET 状态下是没有'trade_status'标签的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3121 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:56 · PVG 18:56 · LAX 03:56 · JFK 06:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.