コード例 #1
0
    def post(self, request):
        """
        处理支付宝的notify_url
        """
        #存放post里面所有的数据
        processed_dict = {}
        #取出post里面的数据
        for key, value in request.POST.items():
            processed_dict[key] = value
        #把signpop掉,文档有说明
        sign = processed_dict.pop("sign", None)

        #生成一个Alipay对象
        alipay = AliPay(
            appid="2016102100734837",
            app_notify_url="http://127.0.0.1:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://127.0.0.1:8000/alipay/return/")

        #进行验证
        verify_re = alipay.verify(processed_dict, sign)

        # 如果验签成功
        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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                # 更新订单状态
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            #需要返回一个'success'给支付宝,如果不返回,支付宝会一直发送订单支付成功的消息
            return Response("success")
コード例 #2
0
ファイル: views.py プロジェクト: zyijia/mxshop
    def get(self, request):
        """
        处理支付宝的 return_url 返回
        :param request:
        :return:
        """

        processed_dict = {}
        # 获取 GET 中参数
        for key, value in request.GET.items():
            processed_dict[key] = value

        # 取出签名 sign
        sign = processed_dict.pop('sign', None)

        # 测试用例
        alipay = AliPay(
            # appid 在沙箱环境中就可以找到
            appid=settings.ALIPAY_APP_ID,
            app_notify_url=settings.ALIPAY_APP_NOTIFY_URL,
            # 我们自己商户的密钥
            app_private_key_path=settings.ALIPAY_PRI_KEY_PATH,
            # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥
            alipay_public_key_path=settings.ALIPAY_PUB_KEY_PATH,
            return_url=settings.ALIPAY_APP_NOTIFY_URL,
            # debug 为 true 时使用沙箱的 url。如果不是则用正式环境的 url,默认 False
            debug=True,
        )

        verify_ret = alipay.verify(processed_dict, sign)
        # 这里可以不做操作。因为不管发不发 return url。notify url 都会修改订单状态
        if verify_ret:
            order_sn = processed_dict.get('out_trade_no', None)
            trade_no = processed_dict.get('trade_no', None)
            # FIXME: 支付宝接口会先发起 post 请求,再响应 get 请求。而 returnurl 的返回参数中并不包含我们的支付状态,所以会导致原本被 post 请求写入的支付状态被 get 请求获取不到的默认值 none 覆盖为空
            # trade_status = processed_dict.get('trade_status', None)
            trade_status = processed_dict.get('trade_status', 'TRADE_SUCCESS')

            existed_orders = Order.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/#/app/home/member/order')
            # response.set_cookie('nextPath', 'pay', max_age=2)

            return response
        else:
            return redirect('index')
コード例 #3
0
def pay_notify(request):
    """ 支付成功后跳转的页面 """
    ali_pay = AliPay(
        appid=settings.ALI_APPID,
        app_notify_url=settings.ALI_NOTIFY_URL,
        app_private_key_path=settings.ALI_PRIVATE_KEY_PATH,
        alipay_public_key_path=settings.ALI_PUBLIC_KEY_PATH,
        return_url=settings.ALI_RETURN_URL,
    )
    if request.method == 'GET':
        # 只做跳转
        params = request.GET.dict()
        sign = params.pop('sign', None)
        status = ali_pay.verify(params, sign)
        if status:
            return HttpResponse('支付完成')
        return HttpResponse('支付失败')
    else:
        from urllib.parse import parse_qs
        body_str = request.body.decode('utf-8')
        post_data = parse_qs(body_str)
        post_dict = {}
        for k, v in post_data.items():
            post_dict[k] = v[0]
        sign = post_dict.pop('sign', None)
        status = ali_pay.verify(post_dict, sign)
        if status:
            current_time = datetime.datetime.now()
            out_trade_no = post_dict['out_trade_no']
            _object = models.Transaction.objects.filter(
                order=out_trade_no).first()
            _object.status = 2
            _object.start_time = current_time
            _object.end_time = current_time + datetime.timedelta(days=365 *
                                                                 _object.count)
            _object.save()
            return HttpResponse('success')
    return HttpResponse('error')
コード例 #4
0
    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)

        alipay = AliPay(
            appid=appid,
            app_notify_url="http://127.0.0.1:8080/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://127.0.0.1:8080/alipay/return/")

        verify_re = alipay.verify(processed_dict, sign)

        if verify_re is True:
            # 支付宝接口改版,同步跳转url中不带有trade_status参数,不更新订单状态,只做跳转
            order_sn = processed_dict.get('out_trade_no', None)
            trade_no = processed_dict.get('trade_no', None)
            trade_status = 'TRADE_SUCCESS'

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                order_goods = existed_order.goods.all()
                #销量增加
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                #更新数据库
                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=3)
            return response
        else:
            response = redirect("index")
            return response
コード例 #5
0
    def post(self, request):
        """
        处理支付宝的notify_url
        """
        # 存放post里面所有的数据
        processed_dict = {}
        # 取出post里面的数据
        for key, value in request.POST.items():
            processed_dict[key] = value
        # 把signpop掉,文档有说明
        sign = processed_dict.pop("sign", None)

        # 生成ALipay对象
        alipay = AliPay(
            appid=settings.APPID,
            app_notify_url=settings.APP_NOTIRY_URL,
            app_private_key_path=settings.APP_PRIVATE_KEY_PATH,
            alipay_public_key_path=settings.ALIPAY_PUBLIC_KEY_PATH,
            debug=settings.ALIPAY_DEBUG,  # 默认False,
            return_url=settings.RETURN_URL)
        # 进行验证
        verify_re = alipay.verify(processed_dict, sign)

        # 如果验签成功
        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', 'TRADE_SUCCESS')

            # 查询数据库中订单记录
            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                # 更新订单状态
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            # 需要返回一个'success'给支付宝,如果不返回,支付宝会一直发送订单支付成功的消息
            return Response("success")
コード例 #6
0
    def get(self, reqeust):
        """
        处理支付宝的return_url返回
        :param reqeust:
        :return:
        """
        """
        处理支付宝的return_url返回
        """
        processed_dict = {}
        # 1. 获取GET中参数
        for key, value in reqeust.GET.items():
            processed_dict[key] = value
        # 2. 取出sign
        sign = processed_dict.pop("sign", None)

        # 3. 生成ALipay对象
        alipay = AliPay(
            # appid在沙箱环境中就可以找到
            appid="2016092000553933",
            # 这个值先不管,在与vue的联调中介绍
            app_notify_url="http://39.108.225.222:8000/alipay/return/",
            # 我们自己商户的密钥
            app_private_key_path=private_key_path,
            # 支付宝的公钥
            alipay_public_key_path=ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            # debug为true时使用沙箱的url。如果不是用正式环境的url
            debug=True,  # 默认False,
            # 先不用管,后面vue解释
            return_url="http://39.108.225.222:8000/alipay/return/"
        )

        verify_re = alipay.verify(processed_dict, sign)

        if verify_re is True:
            order_sn = processed_dict.get('out_trade_no', None)
            trade_no = processed_dict.get('trade_no', None)

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            # 将success返回给支付宝,支付宝就不会一直不停的继续发消息了。
            response = redirect("/index/#/app/home/member/order")
            return response
        else:
            response = redirect("index")
            return response
コード例 #7
0
    def get(self, request):
        """
        处理支付宝的return_url返回
        """
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value
        sign = processed_dict.pop('sign', None)

        alipay = AliPay(
            appid="2016091700533013",
            app_notify_url="http://47.96.124.190:8001/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,
            debug=True,
            return_url="http://47.96.124.190:8001/alipay/return/")
        verify_re = alipay.verify(processed_dict, sign)

        # 如果验签成功
        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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                # 更新订单状态,填充支付宝给的交易凭证号。
                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)
            response = redirect("/index/#/app/home/member/order")
            return response
        else:
            response = redirect('index')
            return response
コード例 #8
0
ファイル: views.py プロジェクト: LOVE-Yourself/new_cssOnline
    def get(self, request):
        alipay = AliPay(
            appid="2016091100490098",
            app_notify_url="test.tuobaba.cn:5020/pay/notyfile_return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,
            # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="test.tuobaba.cn:5020/pay/alipay_return/")
        #sss = request.GET.get('trade_no','')
        #支付成功 跳转回来
        o = urlparse(request.get_full_path())
        query = parse_qs(o.query)
        processed_query = {}
        ali_sign = query.pop("sign")[0]
        for key, value in query.items():
            print('---??---->', key)
            processed_query[key] = value[0]
        s = alipay.verify(processed_query,
                          ali_sign)  #比对跳转回来的信息参数与之前发过去的信息参数(加密的sign)
        if s:
            #获取数据库里的记录
            trade_no = processed_query['trade_no']
            # order_status = processed_query['trade_status']
            order_status = 'TRADE_SUCCESS'
            order_sn = processed_query['out_trade_no']
            coachOrders = Coach_Orders.objects.filter(order_sn=order_sn)
            for coachOrder in coachOrders:
                coachOrder.trade_no = trade_no
                coachOrder.order_status = order_status
                coachOrder.pay_time = datetime.now()
                coachOrder.save()
                users = UserProfile.objects.filter(
                    Coach_Orders_id=coachOrder.id)
                for user in users:
                    user.order_name = coachOrder.coach_name
                    user.save()
                #改变教练的学生人数
                coachs = Coach.objects.filter(name=coachOrder.coach_name)
                for coach in coachs:
                    coach.students += 1
                    coach.save()
            resp = 'success'
        else:
            resp = {'code': 500, 'detail': 'postchengg'}

        #更改用户表教练名称

        return HttpResponse(json.dumps(resp), content_type='application/json')
コード例 #9
0
    def post(self, request):
        """
        处理支付宝的notify_url
        """
        # 存放post里面所有的数据
        processed_dict = {}
        # 取出post里面的数据
        for key, value in request.POST.items():
            processed_dict[key] = value
        # 把signpop掉,文档有说明
        sign = processed_dict.pop("sign", None)

        # 生成一个Alipay对象
        alipay = AliPay(
            appid="2016101800716810",
            app_notify_url="http://139.9.118.108:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://139.9.118.108:8000/alipay/return/")

        # 进行验证
        verify_re = alipay.verify(processed_dict, sign)

        # 如果验签成功
        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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                # 更新订单状态,填充支付宝给的交易凭证号。
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            # 将success返回给支付宝,支付宝就不会一直不停的继续发消息了。
            return Response("success")
コード例 #10
0
ファイル: views.py プロジェクト: zhangyqqwer/Dailyfresh-B2C
    def post(self, request):
        """
        处理支付宝的notify_url
        """
        # 1. 先将sign剔除掉
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        # 2. 生成一个Alipay对象
        alipay = AliPay(
            appid="2016091200490210",
            app_notify_url="http://115.159.122.64:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://115.159.122.64:8000/alipay/return/")

        # 3. 进行验签,确保这是支付宝给我们的
        verify_re = alipay.verify(processed_dict, sign)

        # 如果验签成功
        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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sales += order_good.goods_num
                    goods.save()

                # 更新订单状态,填充支付宝给的交易凭证号。
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            # 将success返回给支付宝,支付宝就不会一直不停的继续发消息了。
            return Response("success")
コード例 #11
0
    def get(self, request):
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016101200666258",
            app_notify_url="http://127.0.0.1:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://127.0.0.1:8000/alipay/return/"
        )

        verify_re = alipay.verify(processed_dict, sign)

        if verify_re is True:
            order_sn = processed_dict.get('out_trade_no', None)
            trade_no = processed_dict.get('trade_no', None)
            total_amount = processed_dict.get('total_amount',None)
            trade_status = processed_dict.get('trade_status','Picking')

            userprofile = UserProfile.objects.filter(username = self.request.user)
            for i in range(len(userprofile)):
                userprofile[i].integral += float(total_amount)
                userprofile[i].save()



            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                # existed_order.total_amount = total_amount
                existed_order.pay_time = datetime.now()
                existed_order.save()

            return HttpResponseRedirect('http://127.0.0.1:8080/userOrder')
        else:
            return HttpResponse('支付失败')
コード例 #12
0
    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)

        alipay = AliPay(
            appid="2016101000652864",
            app_notify_url="http://projectsedus.com/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://47.92.87.172:8000/")

        verify_re = alipay.verify(processed_dict, sign)

        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:
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            # return Response("success")
            response = redirect("index")
            response.set_cookie("nextPath", "pay", max_age=2)
            return response
        else:
            response = redirect("index")
            return response
コード例 #13
0
ファイル: views.py プロジェクト: youngguo2/Mxshop
    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)

        alipay = AliPay(
            appid="2016102300747529",
            app_notify_url="http://140.143.127.148/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://140.143.127.148:8000/alipay/return/")

        verify_re = alipay.verify(processed_dict, sign)

        if verify_re:
            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)  # filter返回一个数组
            # 修改售卖数
            for existed_order in existed_orders:
                order_goods = existed_order.goods.all()  # 外键不需要objects.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()
            # 修改订单状态
            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)  # 进入个人订单页面
        else:
            response = redirect('index')
        return response
コード例 #14
0
ファイル: views.py プロジェクト: LIMr1209/AtguiguShop
    def get(self, request):
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value
        # 得到签名
        sign = processed_dict.pop("sign", None)

        alipay = AliPay(

            appid=os.environ.get('APPID'),  # APPID
            # 异步通知,回调这个路径,通知自己的服务器
            app_notify_url="http://127.0.0.1:8000/alipay/return",
            app_private_key_path=app_private_key_path,  # 应用私钥
            alipay_public_key_path=alipay_public_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            # 同步通知,通知自己的服务器
            return_url="http://127.0.0.1:8000/alipay/return"
        )
        # 验证 签名
        verify_result = alipay.verify(processed_dict, sign)
        print(verify_result)

        if verify_result:
            # 交易号
            trade_no = processed_dict.get("trade_no")
            # 订单号
            order_sn = processed_dict.get("out_trade_no")
            # 支付状态
            pay_status = processed_dict.get("pay_status", "TRADE_SUCCESS")
            # 查询是否有订单
            orders = OrderInfo.objects.filter(order_sn=order_sn)

            for order in orders:
                # 具体订单的交易号
                order.trade_no = trade_no

                # 修改订单的状态,成功
                order.pay_status = pay_status

                # 支付成功的时间
                order.pay_time = datetime.now()

                # 保存状态
                order.save()
            response = redirect('index')
            response.set_cookie('nextPath', 'pay', max_age=2)
            return response
コード例 #15
0
    def post(self, request):
        """
        处理nofify消息,异步请求
        :param request:
        :return:
        """
        from datetime import datetime
        from rest_framework.response import Response
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value
        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016091500513709",
            app_notify_url="http://localhost:8001/alipay/return/",
            app_private_key_path=privat_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://47.92.87.172:8000/")

        verify_re = alipay.verify(processed_dict, sign)
        if verify_re:
            order_sn = processed_dict["out_order_no"]
            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:
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            from django.shortcuts import redirect
            response = redirect("index")
            response.set_cookie("nexPath", "pay", max_age=2)
            return response
        else:
            response = redirect("index")
            return response
コード例 #16
0
    def get(self, request):
        '''
        处理支付宝的return_url返回
        :param request:
        :return:
        '''
        # 处理回调数据,跟之前的sign做比对
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value
        sign = processed_dict.pop('sign', None)

        # 创建一个支付对象
        alipay = AliPay(
            appid="2016093000631244",
            app_notify_url="http://120.78.170.188:8001/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://120.78.170.188:8001/alipay/return/")

        # 进行回调参数的验证
        verify_re = alipay.verify(processed_dict, sign)

        # 这里可以不做操作。因为不管发不发return url。notify url都会修改订单状态。
        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', "TRADE_SUCCESS")

            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()

            # 支付宝会异步的给我们发送支付成功消息,需要回复success字符串
            response = redirect('index')
            response.set_cookie('nextPath', 'pay1',
                                max_age=10)  # 前端vue项目会识别到这些值做出相应操作
            return response
        else:
            # 支付信息被篡改的情况下,直接跳转到首页
            response = redirect('index')
            return response
コード例 #17
0
    def post(self, request):
        """
        支付宝异步调用返回
        :param request:
        :return:
        """

        # 将支付宝post的数据保存到字典中
        processed_dict = {}
        for key,value in request.POST.items():
            processed_dict[key] = value

        # 将sign从字典中移除
        sign = processed_dict.pop('sign')

        alipay = AliPay(
            appid="2016082100304253",
            app_notify_url="http://123.206.229.93:8000/alipay/return/",
            app_private_key_path=alipay_private_key,
            alipay_public_key_path=alipay_pub_key,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://123.206.229.93:8000/alipay/return/"  # 支付宝付款完成后返回的url
        )

        # 使用alipay_public_key为字典重新生成sign,与上面取出的的sign做比较,看数据是否有被修改
        verify_re = alipay.verify(processed_dict, sign)

        # 两个签名一致,数据完整,进行本地订单状态的修改
        if verify_re is True:
            order_sn = processed_dict.get('out_trade_no')
            trade_no = processed_dict.get('trade_no')
            trade_status = processed_dict.get('trade_status')

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                # 更新销量
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.pay_status = trade_status
                existed_order.save()
            # 向支付宝返回success
            return Response('success')
コード例 #18
0
    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)

        alipay = AliPay(
            appid="",
            app_notify_url="http://127.0.0.1:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://127.0.0.1:8000/alipay/return/")

        # 对以上信息进行验证,验证支付是否有效
        verify_re = alipay.verify(processed_dict, sign)

        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()

            # 一旦我们返回了success,支付宝则不会再重复发送success

            response = redirect('index')
            response.set_cookie('nextPath', 'pay', max_age=2)
            return response
        else:
            response = redirect('index')

            return response
コード例 #19
0
    def post(self, request):
        """
        处理支付宝的notify_url
        :param request:
        :return:
        """
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016091000482340",
            app_notify_url="http://111.231.88.94:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,
            debug=True,
            return_url="http://111.231.88.94:8000/alipay/return/",
        )

        verify_result = alipay.verify(processed_dict, sign)
        # 如果验签成功
        if verify_result 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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                # 更新订单状态,填充支付宝给的交易凭证号。
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

        # 将success返回给支付宝,支付宝就不会一直不停的继续发消息了。
        return Response("success")
コード例 #20
0
    def get(self, request):
        '''
        处理支付宝的return_url
        通过GET请求返回部分支付信息
        '''
        processed_dict = {}
        # 1. 获取GET中参数
        for key, value in request.GET.items():
            processed_dict[key] = value
        # 2. 取出sign
        sign = processed_dict.pop("sign", None)

        # 3. 生成ALipay对象
        alipay = AliPay(
            appid="2016092700609030",  # 沙箱的APPID
            app_notify_url=notify_url,
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url=return_url)

        verify_re = alipay.verify(processed_dict, sign)

        # 这里可以不做操作。因为不管发不发return url。notify url都会修改订单状态。
        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')
            # # 设置cookie让前端进行路由判断,max_age:取一次失效
            # response.set_cookie('nextPath', 'pay', max_age=2)
            response = redirect("/index/#/app/home/member/order")
            return response
        else:
            # 验证失败
            response = redirect('index')
            return response
コード例 #21
0
ファイル: views.py プロジェクト: vlctt/YDX
    def post(self, request):
        """
        处理支付宝的notify_url
        :param request:
        :return:
        """
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)
        alipay = AliPay(
            appid="2016091100485762",
            app_notify_url="http://47.104.201.172/fights/pay/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://47.104.201.172/fights/pay/")
        #print(processed_dict)
        verify_re = alipay.verify(processed_dict, sign)
        if verify_re is True:
            order_id = processed_dict.get('out_trade_no', None)
            trade_no = processed_dict.get('trade_no', None)
            trade_status = processed_dict.get('trade_status', "")
            existed_orders = Order.objects.filter(order_id=order_id)
            #print("post" + trade_status)
            for existed_order in existed_orders:
                order_details = OrderDetail.objects.filter(order=existed_order)
                for order_detail in order_details:
                    course = order_detail.course
                    if course:
                        # 加入到我的课程
                        existed_course = UserCourse.objects.filter(
                            course=course, user=existed_order.user)
                        if not existed_course:
                            usercourse = UserCourse()
                            usercourse.course = course
                            usercourse.user = existed_order.user
                            usercourse.save()

                existed_order.is_pay = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            return HttpResponse("success")
コード例 #22
0
    def get(self, request):
        """
        处理支付宝的return_url返回
        """
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value
        sign = processed_dict.pop("sign", None)
        alipay = AliPay(
            appid="2016080900200120",
            app_notify_url="http://111.230.186.193:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://111.230.186.193:8000/alipay/return/")

        verify_re = alipay.verify(processed_dict, sign)

        if verify_re is True:
            # 订单号
            order_sn = processed_dict.get('out_trade_no', None)
            # 支付宝交易号
            trade_no = processed_dict.get('trade_no', None)

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods.goods
                    goods.sold_num += order_good.goods_num
                    goods_cs = order_good.goods
                    goods_cs.goods_num -= order_good.goods_num
                    goods_cs.save()
                    goods.save()
                existed_order.pay_status = "TRADE_SUCCESS"
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            response = redirect("http://111.230.186.193:8000/index#/success")
            return response
        else:
            response = redirect("http://111.230.186.193:8000/index#/success")
            return response
コード例 #23
0
ファイル: views.py プロジェクト: bbright3493/python_real_war
    def post(self, request):
        """
        支付宝返回的notify_url
        :param request:
        :return:
        """
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016091400509243",
            app_notify_url="http://www.zhutaosong.top:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://www.zhutaosong.top:8000/alipay/return/")
        verify_re = alipay.verify(processed_dict, sign)

        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:
                try:
                    intergral = UserIntergral.objects.get(user=request.user)
                except:
                    intergral = UserIntergral()
                    intergral.user = request.user
                print(request.user)
                intergral.grade = int(intergral.grade) + int(
                    existed_order.order_mount * 100)
                intergral.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.datetime.now()
                existed_order.save()

            return HttpResponse("success")
コード例 #24
0
    def get(self, request):
        processed_dict = {}
        for key, value in request.GET.items():
            processed_dict[key] = value
        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016101100663368",  # 设置签约的appid
            app_notify_url=ali_return_url,  # 异步支付通知url
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=
            True,  # 默认False,                                  # 设置是否是沙箱环境,True是沙箱环境
            return_url=ali_return_url,  # 同步支付通知url
        )

        verify_re = alipay.verify(processed_dict, sign)

        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', 'TRADE_SUCCESS')

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            response = redirect(
                "http://127.0.0.1:8080/#/app/home/member/order")
            return response
        else:
            response = redirect("index")
            return response
コード例 #25
0
ファイル: views.py プロジェクト: lhsheild/MxShop
    def post(self, request):
        """
        处理notify_url返回
        :param request:
        :return:
        """
        processed_dict = {}
        for k, v in request.POST.items():
            processed_dict[k] = v

        sign = processed_dict.pop('sign', None)

        alipay = AliPay(
            appid='2016092800616929',
            app_notify_url='http://113.16.255.12:11032/alipay/return',
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_key_path,
            debug=True,
            return_url='http://113.16.255.12:11032/alipay/return')

        verify_re = alipay.verify(processed_dict, sign)
        print(processed_dict)

        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)
            print(trade_status)

            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                # 修改商品售卖数量
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

                from rest_framework.response import Response
            return Response('success')
コード例 #26
0
ファイル: views.py プロジェクト: JamY/Shopping
    def post(self, request):
        """
        处理支付宝的notify_url
        :param request:
        :return:
        """
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016092000558805",
            # app_notify_url="http://132.232.148.220:8000/alipay/return/",
            app_notify_url="http://127.0.0.1:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            # return_url="http://132.232.148.220:8000/alipay/return/"
            return_url="http://127.0.0.1:8000/alipay/return/"
        )

        verify_re = alipay.verify(processed_dict, sign)

        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)
            trade_status = "TRADE_SUCCESS"
            # 销量修改
            existed_orders = OrderInfo.objects.filter(order_sn=order_sn)
            for existed_order in existed_orders:
                order_goods = existed_order.goods.all() # OrderInfo取OrderGoods反向取的方法
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            return Response("success")
コード例 #27
0
ファイル: views.py プロジェクト: luzhisheng/mklearn
    def post(self, request):
        """
		处理支付宝的 notify_url
		"""

        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016091100485730",
            app_notify_url="http://192.168.153.153:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://192.168.153.153:8000/alipay/return/")

        # 支付宝返回的数据验证
        verify_re = alipay.verify(processed_dict, sign)

        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:

                # 销量修改
                order_goods = existed_order.goods.all()
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()

                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()

            return Response("success")
コード例 #28
0
    def post(self, request):
        """
        处理支付宝的notify_url
        :param request:
        :return:
        """
        processed_dict = {}
        # 获取GET参数
        for key, value in request.POST.items():
            processed_dict[key] = value
        # 取出sign
        sign = processed_dict.pop("sign", None)
        # 生成ALipay对象
        alipay = AliPay(
            appid="2016102400748880",
            app_notify_url="http://127.0.0.1:8000/alipay/return/",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://127.0.0.1:8000/alipay/return/")

        verify_re = alipay.verify(processed_dict, sign)

        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:
                # 订单商品项
                order_goods = existed_order.goods.all()
                # 商品销量增加订单中数值
                for order_good in order_goods:
                    goods = order_good.goods
                    goods.sold_num += order_good.goods_num
                    goods.save()
                # 更新订单状态
                existed_order.pay_status = trade_status
                existed_order.trade_no = trade_no
                existed_order.pay_time = datetime.now()
                existed_order.save()
            # 返回一个success状态给支付宝,如果不返回,支付宝会一直发送订单支付成功的消息
            return Response("success")
コード例 #29
0
ファイル: views.py プロジェクト: wocswang/JyShop
    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)


        alipay = AliPay(
            appid=appid_path,
            app_notify_url=app_notify_url_path,
            app_private_key_path=private_key_path,
            alipay_public_key_path=ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            return_url=return_url_path
        )

        verify_re = alipay.verify(processed_dict, sign)
        #print(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=3)
            return response

        else:
            response = redirect("index")
            return response
コード例 #30
0
    def get(self, request):
        """
        处理支付宝的return_url返回
        """
        processed_dict = {}
        # 1. 获取GET中参数
        for key, value in request.GET.items():
            processed_dict[key] = value
        # 2. 取出sign
        sign = processed_dict.pop("sign", None)

        # 3. 生成ALipay对象
        alipay = AliPay(
            appid="2016102700769971",
            # app_notify_url=None,
            app_notify_url="http://127.0.0.1:8000/trade/return",
            app_private_key_path=private_key_path,
            alipay_public_key_path=
            ali_pub_key_path,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            debug=True,  # 默认False,
            # return_url=None
            return_url="http://127.0.0.1:8000/trade/return")
        print(1)
        verify_re = alipay.verify(processed_dict, sign)
        print(verify_re)
        # 这里可以不做操作。因为不管发不发return url。notify url都会修改订单状态。
        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', "TRADE_SUCCESS")
            print(processed_dict)
            print(trade_status)
            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/#/app/home/member/order")
            return response

        else:
            response = redirect("index")
            return response