我的代码如下:
@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
1
kangsgo OP 另外 GET 状态下是没有'trade_status'标签的
|