1.订单支付回调接口
1.1 goods/urls.py
中添加路由
urlpatterns = [
path('peyment/', views.PayMentView.as_view()), # /goods/peyment/
]
1.2 goods/views.py
中写视图函数
from user.models import Vip
import datetime
from course.models import UserCourse
class PayMentView(APIView):
permission_classes = (AllowAny,)
def post(self, request):
# 1. 获取了支付宝返回的数据
data = request.data
# 2.修改订单信息为已支付状态
sign = data.pop('sign')
"""
"sign": "Sv......kEoobbA==",
"""
order = Orders.objects.get(order_id=data['out_trade_no'])
order.trade_no = data['trade_no']
order.pay_time = data['timestamp']
order.status = 2
order.save()
# 3. 处理用户购买课程流程
# 3.1 给 UserCourse 表增加 购买课程
# goods = order.goods
user = order.user
course = order.goods.course
UserCourse.objects.create(user=user,course=course)
return Response({"code": 0, "msg": "购买成功"})
http://127.0.0.1:8888/payment/callback/?
charset=utf-8&
out_trade_no=SYL2020110906171516885&
method=alipay.trade.page.pay.return&
total_amount=44.00&
sign=TzUZHR7Txk%2FjA9b%2BP5qASqoYpUB2QcZPYleTdFJu%2FBMlZvmh%2FwGg6sSHE02S2unNeYH77I8ojnqfatty47crle9ApjiuRNc8Gcr8vadvQbN693tu1stS1ouuw3UuqNYB4adJWCIPTNSFq%2Fq%2B3wO0Mq0G4aULjTNT2OcZNeQP2PgCUGGRdmeBnsVylvjxsIdGeJVA8JEK3ZYHdGCfBDuXiqE5CAKiVWy%2FLyWXPde6QpsO9vUkmyV3L5iByUbL3%2B11Yoz7PNzaYpVT0wxwfX9bYcVYjE4frbSLgLoEccNcKRC3Pro%2BhgAjP7TJGBe1MdrEMZ17pReC2GVhfYUrf7XT3A%3D%3D&
trade_no=2020110922001428980501074538&
auth_app_id=2016101800716047&version=1.0&
app_id=2016101800716047&
sign_type=RSA2&
seller_id=2088102180143385&
timestamp=2020-11-09%2014%3A17%3A39