推荐学习书目
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 · Jun 12, 2018 · 2267 views
    This topic created in 2892 days ago, the information mentioned may be changed or developed.

    我的代码如下:

    @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
       Jun 12, 2018
    另外 GET 状态下是没有'trade_status'标签的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3384 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    ♥ Do have faith in what you're doing.