class AlipayView(APIView):
def get(self, request):
"""
处理支付宝的return_url返回
:param request:
:return:
"""
processed_dict = {}
for key, value in request.GET.items():
processed_dict[key] = value
sign = processed_dict.pop("sign", None)
server_ip = "149.129.53.199"
alipay = AliPay(
appid = "2016101400687743",
# app_notify_url="http://127.0.0.1:8000/alipay/return/",
app_notify_url = "http://" + server_ip + ":8000/alipay/return/",
app_private_key_path = private_key_path,
alipay_public_key_path = ali_pub_key_path, # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
debug = True, # 默认False,
return_url = "http://" + server_ip + ":8000/alipay/return/"
)
verify_re = alipay.verify(processed_dict, sign)
#这里我们可以调试看一下,如果verify_re为真,说明验证成功
if verify_re is True:
order_sn = processed_dict.get('out_trade_no', None)#订单号
trade_no = processed_dict.get('trade_no', None)#支付宝交易号
trade_status = processed_dict.get('trade_status', None)#交易状态
existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
for existed_order in existed_orders:
existed_order.pay_status = trade_status #更新交易状态
existed_order.trade_no = trade_no
existed_order.pay_time = datetime.now()
existed_order.save()
response = redirect("index")
response.set_cookie("nextPath","pay", max_age=2)
return response
else:
response = redirect("index")
return response
老师,请问get请求中是不是并没有trade_status,我们的trade_status更新是依赖异步的POST请求,进行的更新?
登录后可查看更多问答,登录/注册
Django REST framework课程视频,RESTFul API前后端分离开发
了解课程