• 6.订单支付回调接口


    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
     
  • 相关阅读:
    三层框架(原始版)
    Java虚拟机之内存区域
    JDK和JRE的区别
    cookie和session区别与联系
    DAO、Service、Controller及View层级结构梳理
    JavaWeb-四大域对象复习
    Mybatis-实现逆向代理
    Springboot-实现热部署
    排序算法-冒泡排序
    【ERROR 1064 (42000)】MySQL中使用mysqladmin或set修改root密码时提示语法错误
  • 原文地址:https://www.cnblogs.com/gaodenghan/p/13957943.html
Copyright © 2020-2023  润新知