老师,远程调试的时候,我在网页端支付成功后,等待他自己跳转,是收到get请求的,但是我支付成功后,立即关闭网页,后台收不到post请求
class PayReturnView(View):
def get(self, request):
processed_dict = {}
for key, value in request.GET.items():
processed_dict[key] = value
sign = processed_dict.pop("sign", None)
pay = AliPay(
appid="2016092100558978",
app_notify_url="http://178.128.2.120:8001/userpay_return/",
app_private_key_path="./private_2048.txt",
alipay_public_key_path="./alipay_key.txt", # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
debug=True, # 默认False,
return_url="http://178.128.2.120:8001/userpay_return/"
)
verify_result = pay.verify(processed_dict, sign)
if verify_result is True:
# generated by merchant
out_trade_no = processed_dict.get("out_trade_no", None)
# generated by alipay
trade_no = processed_dict.get("trade_no", None)
trade_status = processed_dict.get("trade_status", None)
order = Order.objects.get(out_trade_no=out_trade_no)
order.pay_status = "success"
order.trade_no = trade_no
order.pay_time = datetime.now()
order.save()
orders = Order.objects.filter(user=request.user)
return render(request, 'usercenter_order.html', {
"current_page": "user_center",
"orders": orders
})
def post(self, request):
processed_dict = {}
for key, value in request.GET.items():
processed_dict[key] = value
sign = processed_dict.pop("sign", None)
pay = AliPay(
appid="2016092100558978",
app_notify_url="http://178.128.2.120:8001/userpay_return/",
app_private_key_path="./private_2048.txt",
alipay_public_key_path="./alipay_key.txt", # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
debug=True, # 默认False,
return_url="http://178.128.2.120:8001/userpay_return/"
)
verify_result = pay.verify(processed_dict, sign)
if verify_result is True:
# generated by merchant
out_trade_no = processed_dict.get("out_trade_no", None)
# generated by alipay
trade_no = processed_dict.get("trade_no", None)
trade_status = processed_dict.get("trade_status", None)
order = Order.objects.get(out_trade_no=out_trade_no)
order.pay_status = "success"
order.pay_time = datetime.now()
order.trade_no = trade_no
order.save()
return HttpResponse("success")
Django REST framework课程视频,RESTFul API前后端分离开发
了解课程