Esempio n. 1
0
    def get(self, request):
        order_id = request.GET.get('order_id')
        money = request.GET.get('money')
        # 业务逻辑处理
        try:
            # 调用支付宝流程
            alipay_client_config = AlipayClientConfig()  # 创建配置对象
            alipay_client_config.server_url = settings.ALIPAY_URL  # 网关
            alipay_client_config.app_id = settings.ALIPAY_APPID  # APPID
            alipay_client_config.app_private_key = settings.APP_PRIVATE_KEY  # 应用私钥
            client = DefaultAlipayClient(
                alipay_client_config=alipay_client_config)  # 使用配置创建客户端
            model = AlipayTradePagePayModel()  # 创建网站支付模型
            model.out_trade_no = order_id  # 商户订单号码
            model.total_amount = str(1)  # 支付总额
            model.subject = '订单标题'  # 订单标题
            model.body = '订单描述'  # 订单描述
            model.product_code = 'FAST_INSTANT_TRADE_PAY'  # 与支付宝签约的产品码名称,目前只支持这一种。
            model.timeout_express = '30m'  # 订单过期关闭时长(分钟)
            pay_request = AlipayTradePagePayRequest(
                biz_model=model)  # 通过模型创建请求对象
            pay_request.notify_url = settings.ALIPAY_NOTIFY_URL  # 设置回调通知地址(POST)
            # pay_request.notify_url = None  # 设置回调通知地址(POST)
            pay_request.return_url = settings.ALIPAY_RETURN_URL  # 设置回调通知地址(GET)
            # pay_request.return_url = None  # 设置回调通知地址(GET)

            response = client.page_execute(pay_request,
                                           http_method='GET')  # 获取支付链接
            pay_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

            return HttpResponseRedirect(response)  # 重定向到支付宝支付页面
        except Exception as e:
            print(e)
            return JsonResponse({'code': 201, 'message': '支付失败,请重新支付'})
Esempio n. 2
0
 def post(self, request):
     money = request.data.get('money')
     if not money.isdigit():
         return Response('错误,只能是数字')
     money = int(money)
     client = alipayclient()
     """
     页面接口示例:alipay.trade.page.pay
     """
     # 对照接口文档,构造请求对象
     model = AlipayTradePagePayModel()
     import time
     model.out_trade_no = 'pay' + str(time.time())
     model.total_amount = money
     model.subject = "测试"
     model.body = "支付宝测试"
     model.product_code = "FAST_INSTANT_TRADE_PAY"
     request = AlipayTradePagePayRequest(biz_model=model)
     # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
     # get请求 用户支付成功后返回的页面请求地址
     request.return_url = "http://127.0.0.1:8002/alipay_handler"
     # post请求 用户支付成功通知商户的请求地址
     request.notify_url = "http://127.0.0.1:8002/alipay_handler"
     response = client.page_execute(request, http_method="GET")
     print("alipay.trade.page.pay response:" + response)
     return redirect(response)
Esempio n. 3
0
 def post(self, request):
     # 得到阿里支付的实例化对象
     client = ali_pay()
     # 为API生成一个模板对象 初始化参数用的
     model = AlipayTradePagePayModel()
     # 订单号
     model.out_trade_no = "pay" + str(time.time())
     # 金额
     model.total_amount = 8888
     # 商品标题
     model.subject = "测试"
     # 商品详细内容
     model.body = "支付宝测试"
     # 销售产品码,与支付宝签约的产品码名称
     model.product_code = "FAST_INSTANT_TRADE_PAY"
     # 实例化一个请求对象
     request = AlipayTradePagePayRequest(biz_model=model)
     # get请求 用户支付成功后返回的页面请求地址
     request.return_url = "http://140.143.63.45:8888/alipay_handler"
     # post请求 用户支付成功通知商户的请求地址
     request.notify_url = "http://140.143.63.45:8888/alipay_handler"
     # 利用阿里支付对象发一个获得页面的请求 参数是request
     response = client.page_execute(request, http_method="GET")
     # print(response)
     return redirect(response)
Esempio n. 4
0
 def trade_page_pay(self):
     page_pay = AlipayTradePagePayModel()
     page_pay.out_trade_no = 91922212229232131
     page_pay.product_code = 'FAST_INSTANT_TRADE_PAY'
     page_pay.total_amount = 10
     page_pay.subject = '测试'
     request = AlipayTradePagePayRequest(biz_model=page_pay)
     request.return_url = 'http://139.199.123.96:8000/alipay/return/'
     request.notify_url = 'http://139.199.123.96:8000/alipay/return/'
     response = self.client.page_execute(request, http_method="GET")
     print("alipay.trade.page.pay response:" + response)
     return response
Esempio n. 5
0
def get_pay(out_trade_no, total_amount, return_url):
    model = AlipayTradePagePayModel()
    model.out_trade_no = out_trade_no
    model.total_amount = str(total_amount)
    model.subject = "测试"
    model.body = "支付宝测试"
    model.product_code = "FAST_INSTANT_TRADE_PAY"

    request = AlipayTradePagePayRequest(biz_model=model)

    request.notify_url = return_url + '?t=' + out_trade_no
    request.return_url = return_url + '?t=' + out_trade_no
    response = client.page_execute(request, http_method="GET")
    return response
Esempio n. 6
0
    def post(self, request):
        # 获得支付宝客户端
        client = AlipayView.sign()
        # 构造请求参数
        model = AlipayTradePagePayModel()
        model.out_trade_no = order_id
        model.total_amount = str(order.total_price)
        model.subject = "天天生鲜订单支付"
        model.timeout_express = str(settings.ALIPAY_TIMEOUT_MINUTE) + 'm'

        pay_request = AlipayTradePagePayRequest(biz_model=model)
        url = 'http://121.40.139.86:8000' + reverse('order:alipay_result')
        pay_request.notify_url = url  # 支付后回调地址
        pay_url = client.page_execute(pay_request, http_method='GET')  # 获取支付链接
        return JsonResponse({'res': 0, 'msg': '正在支付中...', 'url': pay_url})
Esempio n. 7
0
    def get_pay_url(cls, order_id, total_amount):
        # 获取内容
        with open(ALIPAY_KEY_PATH) as f:
            alipay_public_key = f.read()

        with open(APP_KEY_PRIVATE_PATH) as f:
            app_private_key = f.read()

        #  设置配置,包括支付宝网关地址、app_id、应用私钥、支付宝公钥;
        config = AlipayClientConfig()
        config.server_url = settings.SERVER_URL
        config.app_id = settings.APP_ID
        config.app_private_key = app_private_key
        config.alipay_public_key = alipay_public_key

        # 得到
        client = DefaultAlipayClient(alipay_client_config=config)
        model = AlipayTradePagePayModel()
        model.out_trade_no = order_id
        model.total_amount = str(total_amount)
        model.subject = "天天生鲜-%s" % order_id
        model.product_code = "FAST_INSTANT_TRADE_PAY"
        model.body = '天天生鲜'
        request = AlipayTradePagePayRequest(biz_model=model)
        # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url
        response_url = client.page_execute(request, http_method="GET")
        return response_url
Esempio n. 8
0
 def __init__(self):
     # 得到阿里支付的实例化对象
     self.client = alipayconfig()
     # 为API生成一个模版对象,初始化参数用的
     self.model = AlipayTradePagePayModel()
     # 实例化一个请求对象
     self.request = AlipayTradePagePayRequest(biz_model=self.model)
Esempio n. 9
0
def alipay_trade_page(order):
    """
    页面接口示例:alipay.trade.page.pay,--统一收单下单
    """
    client = alipay_base_config()
    # 对照接口文档,构造请求对象
    model = AlipayTradePagePayModel()
    # 必填
    model.out_trade_no = order.order_id
    model.total_amount = str(order.total_price)
    model.subject = "天天生鲜测试"
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    # 选填中有些必填
    settle_detail_info = SettleDetailInfo()
    settle_detail_info.amount = str(order.total_price)  # 必填
    settle_detail_info.trans_in_type = "userId"  # 必填
    settle_detail_info.trans_in = settings.ALIPAY_UID  # 必填
    settle_detail_infos = list()
    settle_detail_infos.append(settle_detail_info)
    settle_info = SettleInfo()
    settle_info.settle_detail_infos = settle_detail_infos
    model.settle_info = settle_info

    # 与银行有关
    # sub_merchant = SubMerchant()
    # sub_merchant.merchant_id = "2088301300153242"
    # model.sub_merchant = sub_merchant

    request = AlipayTradePagePayRequest(biz_model=model)
    # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
    response = client.page_execute(request, http_method="GET")
    return response
Esempio n. 10
0
 def create_trade(self, price, trade_no, buyer_id="1", subject="商品名"):
     """
     :param buyer_id: 用户id
     :param price: 商品总价格
     :param trade_no: 唯一订单号
     :param subject: 商品名称
     :return: 支付宝跳转链接地址
     """
     # 构造请求参数对象
     model = AlipayTradeCreateModel()
     # 商家唯一订单号
     model.out_trade_no = trade_no
     # product_code 必须这么写
     model.product_code = "FAST_INSTANT_TRADE_PAY"
     # 订单价格
     model.total_amount = price
     # 商品名称
     model.subject = subject
     # 用户 id
     model.buyer_id = buyer_id
     # return model
     request = AlipayTradePagePayRequest(biz_model=model)
     try:
         # 获得支付宝支付地址
         response_url = self.ALIPAY_client.page_execute(request,
                                                        http_method="GET")
     except Exception as e:
         response_url = None
         print('err', e)
     return response_url
Esempio n. 11
0
    def post(self, request):
        '''订单支付'''
        # 判断用户登录
        user = request.user
        if not user.is_authenticated:
            return JsonResponse({'res': 0, 'errmsg': '用户未登陆'})

        # 接收参数
        order_id = request.POST.get('order_id')

        # 校验参数
        if not order_id:
            return JsonResponse({'res': 1, 'errmsg': '参数不完整'})

        try:
            order = OrderInfo.objects.get(order_id=order_id,
                                          user=user,
                                          pay_method=3,
                                          order_status=1)
        except OrderInfo.DoesNotExist:
            return JsonResponse({'res': 2, 'errmsg': '无效的订单id'})

        """
        设置配置,包括支付宝网关地址、app_id、应用私钥、支付宝公钥等,其他配置值可以查看AlipayClientConfig的定义。
        """
        alipay_client_config = AlipayClientConfig()
        alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'
        alipay_client_config.app_id = '2016100100641374'
        app_private_key = ''
        with open(os.path.join(settings.BASE_DIR, 'apps/order/app_private_key.pem'), 'r') as f:
            for line in f:
                app_private_key += line
        alipay_client_config.app_private_key = app_private_key
        alipay_public_key = ''
        with open(os.path.join(settings.BASE_DIR, 'apps/order/alipay_public_key.pem'), 'r') as f:
            for line in f:
                alipay_public_key += line
        alipay_client_config.alipay_public_key = alipay_public_key
        """
        得到客户端对象。
        注意,一个alipay_client_config对象对应一个DefaultAlipayClient,定义DefaultAlipayClient对象后,alipay_client_config不得修改,如果想使用不同的配置,请定义不同的DefaultAlipayClient。
        logger参数用于打印日志,不传则不打印,建议传递。
        """
        client = DefaultAlipayClient(alipay_client_config=alipay_client_config, logger=logger)

        total_pay = order.transit_price + order.total_price
        total_pay = round(float(total_pay), 2)
        model = AlipayTradePagePayModel()
        model.out_trade_no = order_id
        model.total_amount = total_pay
        model.subject = "天天生鲜{0}".format(order_id)
        model.product_code = "FAST_INSTANT_TRADE_PAY"

        request = AlipayTradePagePayRequest(biz_model=model)
        response = client.page_execute(request, http_method="GET")
        # 访问支付页面
        return JsonResponse({'res': 3, 'response': response})
Esempio n. 12
0
 def post(self, request):
     """生成支付宝自带页面的API"""
     # 实例化阿里支付的对象
     client = aliPay()
     # 为API生成一个模板对象
     model = AlipayTradePagePayModel()
     model.out_trade_no = 'LuffyCityPayment' + str(time.time())  # 订单号
     model.total_amount = request.data.get("total_amount", None)  # 金额
     model.subject = request.data.get("subject", None)  # 商品标题
     model.body = request.data.get("body", None)  # 商品详细内容
     # 实例化一个请求对象
     request = AlipayTradePagePayRequest(biz_model=model)
     # get请求 用户支付成功后返回的页面请求地址
     request.return_url = "http://localhost:8080/shopping-cart"
     # post请求 用户支付成功通知商户的请求地址
     request.notify_url = "http://127.0.0.1:8000/alipay_handler"
     # 利用阿里支付对象发一个获得页面的请求 参数是request
     response = client.page_execute(request, http_method="GET")
     return redirect(response)
Esempio n. 13
0
def getAlipayUrl(request):
    token = request.POST['token']

    user_token = Token.objects.filter(key=token)
    if len(user_token) == 0:
        return Response('nologin')

    user = user_token[0].user
    article_id = request.POST['article_id']
    article = Article.objects.get(id=article_id)

    nowtime = datetime.datetime.now()
    new_payorder = PayOrder(belong=article, belong_user=user)
    new_payorder.order = str(nowtime.year) + str(
        random.randrange(10000000, 99999999))
    # print(new_payorder.order)
    new_payorder.price = '9.9'
    # new_payorder.save()

    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = settings.ALIPAY_URL
    alipay_client_config.app_id = settings.ALIPAY_APPID
    alipay_client_config.app_private_key = settings.APP_PRIVATE_KEY
    alipay_client_config.alipay_public_key = settings.ALIPAY_PUBLIC_KEY

    client = DefaultAlipayClient(alipay_client_config=alipay_client_config)
    model = AlipayTradePagePayModel()
    model.out_trade_no = new_payorder.order
    model.total_amount = new_payorder.price
    model.subject = "打赏订单:" + new_payorder.order + '/' + new_payorder.price + '元'
    model.product_code = 'FAST_INSTANT_TRADE_PAY'
    model.timeout_express = '5m'

    # 发送请求
    pay_request = AlipayTradePagePayRequest(biz_model=model)
    pay_request.notify_url = settings.ALIPAY_NOTIFY_URL
    pay_request.return_url = settings.ALITAY_RETURN_URL
    response = client.page_execute(pay_request, http_method='GET')
    print(response)

    pay_link = response
    return Response({'pay_link': pay_link})
Esempio n. 14
0
    def get(self,order_id):
        order = MovieOrder.query.get(order_id)
        total_price = order.o_price
        flight = Flight.query.get(order.o_flight_id)
        movie = Movie.query.get(flight.f_movie_id)

        # Alipay Client
        alipay_client_config = AlipayClientConfig()
        alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'

        alipay_client_config.app_id = ALIPAY_APPID
        alipay_client_config.app_private_key = ALIPAY_PRIVATE_KEY
        alipay_client_config.alipay_public_key = ALIPAY_PUBLIC_KEY
        client = DefaultAlipayClient(alipay_client_config=alipay_client_config)

        model = AlipayTradePagePayModel()
        model.out_trade_no = "pay2018050200005262"
        model.total_amount = total_price
        model.subject = movie.showname
        model.body = order.o_seat
        model.product_code = "FAST_INSTANT_TRADE_PAY"

        pay_request = AlipayTradePagePayRequest(biz_model=model)
        pay_request.notify_url = 'https://ruoxianer.github.io/'
        pay_request.return_url = 'https://ruoxianer.github.io/'

        # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
        response = client.page_execute(pay_request, http_method="GET")
        # print("alipay.trade.page.pay response:" + response)
        data = {
            'msg':'ok',
            'status':HTTP_OK,
            'data':{
                'pay_url':response,
                'order_id':order_id
            }
        }
        return data
Esempio n. 15
0
def create_token_params(config: GatewayConfig,
                        token_config: TokenConfig) -> dict:
    # params = {}
    # customer_id = token_config.customer_id
    # if customer_id and config.store_customer:
    #     params["customer_id"] = customer_id
    model = AlipayTradePagePayModel()
    model.out_trade_no = "202005020000226"
    model.total_amount = 50
    model.subject = "测试"
    model.body = "支付宝测试"
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    request = AlipayTradePagePayRequest(biz_model=model)
    return request
Esempio n. 16
0
def generate_ali_pay_url(order):
    client = ali_pay()
    model = AlipayTradePagePayModel()
    # 订单id
    model.out_trade_no = order.pk
    # 订单总价格
    model.total_amount = 88.00
    # 商品标题
    model.subject = "测试订单"
    # 商品详情
    model.body = "肯德基订餐"
    # 商品码
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    # 实例化一个请求对象
    request = AlipayTradePagePayRequest(biz_model=model)
    # get请求,用户支付成功后返回的页面地址
    request.return_url = None
    # post请求,用户支付成功后通知商户的请求地址
    request.notify_url = None
    # 利用阿里支付对象发一个获得页面的请求,参数是request
    response = client.page_execute(request, http_method="GET")
    print("alipay.trade.app.pay response:" + response)
    return response
Esempio n. 17
0
    def post(self, request):
        money = request.data.get('money')
        try:
            if isinstance(money, str):
                money = float('%.2f' % float(money))

        except Exception as e:
            print(e)
            return Response('错误,只能是数字')
        print(money)
        client = alipayclient()

        """
        页面接口示例:alipay.trade.page.pay
        """
        # 对照接口文档,构造请求对象
        model = AlipayTradePagePayModel()
        import time
        model.out_trade_no = 'pay' + str(time.time())
        model.total_amount = money
        model.subject = "测试"
        model.body = "支付宝测试"
        model.product_code = "FAST_INSTANT_TRADE_PAY"
        request = AlipayTradePagePayRequest(biz_model=model)
        # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段

        # get请求 用户支付成功后返回的页面请求地址
        request.return_url = "http://127.0.0.1:8000/api/v1/pay/alipay_handler"
        # request.return_url = "http://localhost:8080/Order"

        # post请求 用户支付成功通知商户的请求地址
        request.notify_url = "http://127.0.0.1:8000/api/v1/pay/alipay_handler"

        # request.notify_url = "http://localhost:8080/Order"
        response = client.page_execute(request, http_method="GET")
        # print("alipay.trade.page.pay response:" + response)
        return redirect(response)
Esempio n. 18
0
def response_page_pay(trade_no: str, price) -> str:
    '''
    处理电脑页面的支付请求,返回跳转到支付宝的页面地址

    :传入参数: trade_no: 字符串格式的订单号 price: 价格

    :返回: 字符串格式的支付地址
    '''
    model = AlipayTradePagePayModel()
    model.subject = "course"
    model.total_amount = price
    model.out_trade_no = trade_no
    model.body = "Courses"
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    request = AlipayTradePagePayRequest(biz_model=model)
    return CLIENT.page_execute(request, http_method="GET")
Esempio n. 19
0
def get_url_request():
    app_alipay_sanbox_private_path = r'C:\Users\jerry\Desktop\app_private_key.pem'
    alipay_sanbox_public_path = r'C:\Users\jerry\Desktop\alipay_public_key.pem'

    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = "https://openapi.alipaydev.com/gateway.do"
    alipay_client_config.app_id = "20160923420591565"
    alipay_client_config.app_private_key = get_key(
        app_alipay_sanbox_private_path)
    alipay_client_config.alipay_public_key = get_key(alipay_sanbox_public_path)

    alipay_client_config.charset = 'utf-8'

    client = DefaultAlipayClient(alipay_client_config=alipay_client_config)

    model = AlipayTradePagePayModel()
    model.out_trade_no = "pay201805020000227"
    model.total_amount = 50
    model.subject = "test"
    model.body = "alipaytest"
    model.product_code = "FAST_INSTANT_TRADE_PAY"

    # settle_detail_info = SettleDetailInfo()
    # settle_detail_info.amount = 50
    # settle_detail_info.trans_in_type = "userId"
    # settle_detail_info.trans_in = "2088302300165605"
    #
    # settle_detail_infos = list()
    # settle_detail_infos.append(settle_detail_info)
    #
    # settle_info = SettleInfo()
    # settle_info.settle_detail_infos = settle_detail_infos
    #
    # model.settle_info = settle_info
    #
    #
    # sub_merchant = SubMerchant()
    # sub_merchant.merchant_id = "208830234153246"
    #
    # model.sub_merchant = sub_merchant

    request = AlipayTradePagePayRequest(biz_model=model)

    response = client.page_execute(request, http_method="GET")
    return response
Esempio n. 20
0
def get_payment_page(request, houseid):
    # https://opendocs.alipay.com/apis/api_1/alipay.trade.page.pay
    model = AlipayTradePagePayModel()
    # 产品订单号
    model.out_trade_no = '202003051646520001'
    # 订单总金额
    model.total_amount = 200
    # 订单主题
    model.subject = '租房订金'
    # model.body = '支付宝测试'
    # 销售产品码,与支付宝签约的产品码名称。 注:目前仅支持FAST_INSTANT_TRADE_PAY
    model.product_code = 'FAST_INSTANT_TRADE_PAY'
    # 结算详细信息
    settle_detail_info = SettleDetailInfo()
    settle_detail_info.amount = 200
    # 结算收款方的账户类型
    settle_detail_info.trans_in_type = 'cardAliasNo'
    # 结算收款方
    settle_detail_info.trans_in = '6216603100004601162'
    settle_detail_infos = list()
    settle_detail_infos.append(settle_detail_info)
    # 结算信息
    settle_info = SettleInfo()
    settle_info.settle_detail_infos = settle_detail_infos
    model.settle_info = settle_info
    # sub_merchant = SubMerchant()
    # sub_merchant.merchant_id = '2088102180149774'
    # model.sub_merchant = sub_merchant
    request = AlipayTradePagePayRequest(biz_model=model)
    url = alipay_client.page_execute(request, http_method='GET')
    # 此处应该补充生成交易流水的代码 ---> Model
    # 将用户信息、房源信息、交易编号、交易金额、交易时间、交易状态、……写入数据库

    # 还需要一个设计一个接口作为接收通知的接口其中包括对订单交易结果的查询
    # 最后还要更新之前的交易流水信息
    # request = AlipayTradeQueryRequest(biz_model=model)
    # content = alipay_client.page_execute(request)
    return DefaultResponse(data={'url': url})
Esempio n. 21
0
def alipay(request):
    total_price = request.GET.get('total_price')

    # Alipay Client
    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'

    alipay_client_config.app_id = ALIPAY_APPID
    alipay_client_config.app_private_key = ALIPAY_PRIVATE_KEY
    alipay_client_config.alipay_public_key = ALIPAY_PUBLIC_KEY
    client = DefaultAlipayClient(alipay_client_config=alipay_client_config)

    model = AlipayTradePagePayModel()
    model.out_trade_no = "pay201805020000526"
    model.total_amount = total_price
    model.subject = "测试"
    model.body = "支付宝测试"
    model.product_code = "FAST_INSTANT_TRADE_PAY"

    request = AlipayTradePagePayRequest(biz_model=model)
    # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
    response = client.page_execute(request, http_method="GET")
    # print("alipay.trade.page.pay response:" + response)
    return redirect(response)
Esempio n. 22
0
def StartCaolouyaqian():

    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = ''
    alipay_client_config.app_id = ''
    alipay_client_config.app_private_key = ''
    alipay_client_config.alipay_public_key = ''
    client = DefaultAlipayClient(alipay_client_config)

    # 构造请求参数对象
    model = AlipayTradePagePayModel()
    model.out_trade_no = "20150320010101002"
    model.product_code = 'FAST_INSTANT_TRADE_PAY'
    model.total_amount = "88.88"
    model.subject = "Iphone6 16G"
    request = AlipayTradePagePayRequest(biz_model=model)

    # 执行API调用
    try:
        response_content = client.page_execute(request)
        print(response_content)
        return response_content
    except Exception as e:
        print(traceback.format_exc())
Esempio n. 23
0
    def payorders(self, order_id, total_amount):
        model = AlipayTradePagePayModel()
        model.product_code = 'FAST_INSTANT_TRADE_PAY'
        model.total_amount = str(total_amount)
        model.subject = '天天生鲜订单支付-天天艹楼雅倩'
        model.out_trade_no = order_id

        request = AlipayTradePagePayRequest(biz_model=model)
        response_content = self.client.page_execute(request, http_method='GET')
        if not response_content:
            return "caolouyaqianshibai"

        # response = AlipayTradePagePayResponse()
        # response.parse_response_content(response_content)
        # # 响应成功的业务处理
        # if response.is_success():
        #     # 如果业务成功,可以通过response属性获取需要的值
        #     print("get response trade_no:" + response.trade_no)
        # # 响应失败的业务处理
        # else:
        #     # 如果业务失败,可以从错误码中可以得知错误情况,具体错误码信息可以查看接口文档
        #     print(response.code + "," + response.msg + "," + response.sub_code + "," + response.sub_msg)

        return response_content
Esempio n. 24
0
def alipy(request, order_num, total):
    # 导入配置类
    alipy = AlipayClientConfig()
    # 支付宝的网关
    alipy.server_url = 'https://openapi.alipaydev.com/gateway.do'
    # 商家APPID
    alipy.app_id = '2016092000556084'
    # 支付宝的私钥
    alipy.app_private_key = 'MIIEpgIBAAKCAQEAzfsgTn6BAcTMRg4P5cbtcNgN0kQLkOVA2DGhrY+nIcXkzL5IjDdR85ck/dIslv/TeESyHbF48ssS9CiBS6YUASiDa1bDv5A94GWos4FgFM4a8fKx4fc2QXhSY4rG+zIJAVSctwKnDTt0S8VtycS7GBu9uTAthLz4wZKNQexi1W6dSLkj7SDlYapR2zlmF+3NSB8ID52k7cQuPFR+tJSa0SMt0Q6w1kzjJmPDBW8tNo2lqGq9OguefZz4+wnGacaTjzB+e/P1Ni5oIc8L9JJyXfu3qUTop1QgogIOjCRAtM4Rp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LYqRsozgpNuZfwQ8Z/AoGBALb+uPBKRsaxC1q6jkL0MaeGNiCqO+StLCVMoFbTjatSrmw2wt386Qo0DYii+cS1KIXFixZJuw1m3vm4WR5JgoRj477xNVJTUFb/A/GMCLcum9IajLnuD+aqdV3vpGmpQdECsi1sbTMalcjaFozbZLkaJIB5akpfl//A+5UIbRbk'
    # 支付宝的公钥
    alipy.alipay_public_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzfsgTn6BAcTMRg4P5cbtcNgN0kQLkOVA2DGhrY+nIcXkzL5IjDdR85ck/dIslv/TeESyHbF48ssS9CiBS6YUASiDa1bDv5A94GWos4FgFM4a8fKx4fc2QXhSY4rG+zIJAVSctwKnDTt0S8VtycS7GBu9uTAthLz4wZKNQexi1W6dSLkj7SDlYapR2zlmF+3NSB8ID52k7cQuPFR+tJSa0SMt0Q6w1kzjJmPDBW8tNo2lqGq9OguefZz4+wnGacaTjzB+e/P1Ni5oIc8L9JJyXfu3qUTop1QgogIOjCRAtM4RpQIp+GIGs72kljnosPqlUfn8kjBo9Ndj7SfzDoBpcQIDAQAB'
    # 设置默认的客户端配置
    client = DefaultAlipayClient(alipay_client_config=alipy)
    # 订单号
    order_num = order_num

    if order_num == "":
        return HttpResponse("请确认订单号正确")

    # 判断用户的登录状态
    user_id = request.session.get("uid")
    if user_id == None:
        return redirect("/users/user_login")

    # 查询当前用户购买的订单
    order_info = Order.objects.filter(order_num=order_num,
                                      user_id=user_id).get()

    # 判断此订单是否有效
    # print(order_info)
    # return HttpResponse("1")
    if not order_info:
        return HttpResponse("订单有误")

    # 请求数据交易层模型
    model = AlipayTradePagePayModel()
    # 订单号
    model.out_trade_no = order_info.order_num
    # 订单的金额
    model.total_amount = total
    # 标题
    model.subject = "测试支付金额"
    # 订单描述
    model.body = "这是一个巨款订单"
    # 销售的产品码
    model.product_code = "FAST_INSTANT_TRADE_PAY"

    # 交易请求
    qingqiu = AlipayTradePagePayRequest(biz_model=model)

    # 发送上一步的请求  第一个参数是qingqiu  第二个是发送的方式
    # localhost:8000/cart/aliapy?2343243243&111
    # 回调地址
    #qingqiu.return_url = "http://47.107.229.163/cart/return_url/"
    qingqiu.return_url = "http://127.0.0.1:8000/cart/return_url/"
    xiangying = client.page_execute(qingqiu, http_method="GET")

    # print(xiangying)

    # return  HttpResponse(1)
    return redirect(xiangying)
Esempio n. 25
0
def do_place_order(request):
    address_id = request.POST.get('address', 0)
    if address_id == 0:
        return HttpResponse('请选择收货地址!')

    user_id = request.session.get('U_userid', 0)

    if user_id == 0:
        return HttpResponseRedirect('/user/login')

    # 根据收货地址的ID查询详情
    address_info = user_address.objects.filter(id=address_id,
                                               users_id=user_id).first()
    if address_info == None:
        return HttpResponse('请选择收货地址!')

    # 查询购物车内所有的数据,计算金额
    car_list = car.objects.filter(users_id=user_id)

    if not car_list:
        return HttpResponse('请选择商品!')

    total_money = 0
    manage_id = 0
    manage_name = ''
    goods_name_all = ''
    for cart in car_list:
        total_money += cart.number * int(cart.goods.goods_xprice)
        manage_id = cart.goods.manager_id  #多个商品,最后一个覆盖前边的商品
        manage_name = cart.goods.manager.shop_name
        goods_name_all += cart.goods.goods_name
        goods_info = GoodsInfo.objects.filter(id=cart.goods_id).first()
        if goods_info.goods_count < cart.number:
            return message(goods_info.goods_name +
                           "库存不足,请重新选择<a href='%s'>返回购物车</a>" %
                           (reverse('user:car_list')))

    #库存减少
    for cart in car_list:
        goods_info = GoodsInfo.objects.filter(id=cart.goods_id).first()
        goods_info.goods_count -= cart.number
        result = GoodsInfo.objects.filter(id=cart.goods_id).update(
            goods_count=goods_info.goods_count)
    if result:
        # 创建订单
        orderObj = orders()
        orderObj.order_code = '20181010' + str(random.randint(100000, 999999))
        orderObj.money = total_money
        orderObj.users_id = user_id
        orderObj.address = address_info.address
        orderObj.contacts = address_info.name
        orderObj.phone = address_info.phone
        orderObj.manage_id = manage_id
        orderObj.save()
        # 订单详情表
        for cart in car_list:
            orderinfoObj = order_info()
            orderinfoObj.order_id = orderObj.id
            orderinfoObj.number = cart.number
            orderinfoObj.goods_id = cart.goods_id
            orderinfoObj.price = cart.goods.goods_xprice
            orderinfoObj.save()

        # 重定向到首页
        alipay_client_config = AlipayClientConfig()
        alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'  #
        #手动设置
        alipay_client_config.app_id = '2016092100561600'
        alipay_client_config.app_private_key = 'MIIEpgIBAAKCAQEA6KVS4YuG3pFvhbQHtBLjsgWXNe/Xjg2CVCc4+SfiwMeakR/O5IqZqVPThEl9allFyEHPFK7Anofebe+OO0BdYdGfCSrW0R+B85lEfH5YL2ggy9yCWB3GPiffA6B+UM2nO8HRMs1ulcpUPosCfzIucJUgX1IQZxJmAyTHmXzSoJVtY/1WbpLsP/zQgp+cUkfFi3CFDGxz6ex3w1U2q9SxemiQvUYbnn1EC3Yv3E0APloRrsAm+XIvPKLMacSbfHcZJw9EcaF3uNfNYtKzHGObigAzF1EEZlRbwG5LeOQ/iPJvbLilMyefFamuwgCZDBDTVQmHwA9QrjWjHUdeLZyW6QIDAQABAoIBAQCTZXtXbwEqLlbMDT38NyOP/L7K64RUefaivp74LO8bWNtzKwX4AmBMydFvNOiC4sC1mgxLfFSJnGeum2Iv5B3GBfuO4Vds81twLSEZByt0DbMJtlHW5jZd1wES2TJum31i/O9AEqwHt0McxRH16KNHrRPvkJzX0O5U+46CjnUcS5rZXir/OSDHwcN/cBxGqNhaEVsSSsWME8YOsfhCrVlKgI3vfW8UrEp/KociczM+N9wH0NbUlDgo2J9WuvH6/QyYkrLyO4KY5Bs05odS3wn+SoItOMEL8qROQ1iF9b2H5zYc7Ahd1kDBKGTSLVMw5iXUGBons0+eUCUoveiQF3+hAoGBAPcczgsFo9YuR1QSAjh2BsM9BEG2FAn5/xg4HzJoHEtd8fM4MAnwCGECWkzvNE866OaFs743ReQga9Nds4eI5Cg8019m1XAifzvxLaAK+nkotO+fz/8cNKrwS9pYFXNq2XRVph05r+Z/sSfMUUt4IecfTwj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eOQ/iPJvbLilMyefFamuwgCZDBDTVQmHwA9QrjWjHUdeLZyW6QIDAQAB'
        """
        得到客户端对象。
        注意,一个alipay_client_config对象对应一个DefaultAlipayClient,定义DefaultAlipayClient对象后,alipay_client_config不得修改,如果想使用不同的配置,请定义不同的DefaultAlipayClient。
        logger参数用于打印日志,不传则不打印,建议传递。
        """
        client = DefaultAlipayClient(alipay_client_config=alipay_client_config)
        """
        页面接口示例:alipay.trade.page.pay
        """
        # 对照接口文档,构造请求对象
        model = AlipayTradePagePayModel()
        model.out_trade_no = orderObj.order_code
        model.total_amount = total_money
        model.subject = "Qshop-" + manage_name
        model.body = goods_name_all
        model.product_code = "FAST_INSTANT_TRADE_PAY"
        request = AlipayTradePagePayRequest(biz_model=model)
        request.return_url = 'http://39.105.195.67:80/user/return_url/'
        # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
        response = client.page_execute(request, http_method="GET")
        # print("alipay.trade.page.pay response:" + response)
        # 清空购物车
        car.objects.filter(users_id=user_id).delete()
        return HttpResponseRedirect(response)
    else:
        return HttpResponse('操作有误!')
Esempio n. 26
0
def do_place_order(request):
    address_id = request.POST.get('address', 0)
    if address_id == 0:
        return HttpResponse('请选择收货地址')

    user_id = request.session.get('U_userid', 0)
    if user_id == 0:
        return HttpResponseRedirect('/user/login')
    # 根据收货地址的ID 查询详细信息
    address_info = user_address.objects.filter(id=address_id,
                                               users_id=user_id).first()  #
    if address_info == None:
        return HttpResponse('请选择收货地址')

    # 查询购物车内所有的数据,计算金额
    car_list = car.objects.filter(users_id=user_id)

    if not car_list:  #
        return HttpResponse('请选择要结算的商品')

    total_money = 0  # 计算总金额
    manage_id = 0
    manage_name = ''
    goods_name_all = ''
    for cart in car_list:
        total_money += cart.number * int(cart.goods.goods_xprice)
        manage_id = cart.goods.manager_id  # 多个商品 最后一个覆盖前边的结果
        goods_name_all += cart.goods.goods_name
        goods_info = GoodsInfro.objects.filter(id=cart.goods_id).first()
        if goods_info.goods_count < cart.number:
            return message(goods_info.goods_name +
                           "库存不足,请重新选择<a href='%s'>返回购物车</a>" %
                           (reverse('user:car_list')))

    # 创建订单
    orderObj = orders()
    orderObj.order_code = '20181010' + str(random.randint(100000, 999999))
    orderObj.money = total_money
    orderObj.users_id = user_id
    # orderObj.add_time = user_id
    orderObj.address = address_info.address
    orderObj.phone = address_info.phone
    orderObj.contacts = address_info.name
    orderObj.manage_id = manage_id
    orderObj.save()
    # 订单详情表
    for cart in car_list:
        orderinfoObj = order_info()
        orderinfoObj.order_id = orderObj.id
        # orderObj.order=orderObj
        orderinfoObj.number = cart.number
        orderinfoObj.goods_id = cart.goods_id
        orderinfoObj.price = cart.goods.goods_xprice
        orderinfoObj.save()
    # 清空购物车
    car.objects.filter(users_id=user_id).delete()
    # 支付
    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'  #
    alipay_client_config.app_id = '2016092100561606'
    alipay_client_config.app_private_key = 'MIIEowIBAAKCAQEAvAQeli6bj2kPQBlZmqic8bbfPo29J9XIE/NQM1QhcFU/lAcZpleGm38Y+9XnpUN3k2cxIn49GZTTwsSJ0kX6SSBWLkGZOs3RpaLsrgOtkuT1DIXzvoTDe5Q88Hf/5XQJ3GStJnn1ZRnBqokzRUExbTUnuSW+nQftl6Bv/Xh4Ov5L6GPDfesbTG8SQsZYibXREmvoB7cpcQuz8Ci7MJanDASU3aUHTh2jOe27F3F4cPRDE8XNjoDPcW4CqViXwNZvBXH6phNEzFmDpPcPWSp7U5lFI+29BuBx9AJdhii+DNgKR3iongQf206qlhpzotqE1jv6Cztu4g4l/CsAtH7a8QIDAQABAoIBAEuBYAMx/njuWRiF1a09j6GmrirB4zfvK6WPbiLe43roUVsSKuPZfI5P0Wm5coi0+n1w0JOonML8OLqcETknrybU3KdA4tdxtoLNVj1f7sHyPtLjrIpTaOnlE0ADAPpVymv+5mZwTfNnD5Z7+OIUF1RjJ2u8U7teZrUg0ji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BIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvAQeli6bj2kPQBlZmqic8bbfPo29J9XIE/NQM1QhcFU/lAcZpleGm38Y+9XnpUN3k2cxIn49GZTTwsSJ0kX6SSBWLkGZOs3RpaLsrgOtkuT1DIXzvoTDe5Q88Hf/5XQJ3GStJnn1ZRnBqokzRUExbTUnuSW+nQftl6Bv/Xh4Ov5L6GPDfesbTG8SQsZYibXREmvoB7cpcQuz8Ci7MJanDASU3aUHTh2jOe27F3F4cPRDE8XNjoDPcW4CqViXwNZvBXH6phNEzFmDpPcPWSp7U5lFI+29BuBx9AJdhii+DNgKR3iongQf206qlhpzotqE1jv6Cztu4g4l/CsAtH7a8QIDAQAB'
    """
    得到客户端对象。
    注意,一个alipay_client_config对象对应一个DefaultAlipayClient,定义DefaultAlipayClient对象后,alipay_client_config不得修改,如果想使用不同的配置,请定义不同的DefaultAlipayClient。
    logger参数用于打印日志,不传则不打印,建议传递。
    """
    client = DefaultAlipayClient(alipay_client_config=alipay_client_config)
    """
    页面接口示例:alipay.trade.page.pay
    """
    # 对照接口文档,构造请求对象
    model = AlipayTradePagePayModel()
    model.out_trade_no = orderObj.order_code
    model.total_amount = total_money
    #标题
    model.subject = "智能硬件购物商城"
    #订单描述
    model.body = goods_name_all
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    request = AlipayTradePagePayRequest(biz_model=model)
    request.return_url = 'http://127.0.0.1:8000/user/return_url/'
    # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
    response = client.page_execute(request, http_method="GET")
    print("alipay.trade.page.pay response:" + response)
    return HttpResponseRedirect(response)
Esempio n. 27
0
def do_place_order(request):
    # 获取用户id,并验证
    user_id = request.session.get('u_id', 0)
    if user_id == 0:
        return HttpResponseRedirect(reverse('user:login'))

    # 获取用户选择的地址的id,并验证
    address_id = request.POST.get('address_id', 0)
    if address_id == 0:
        return HttpResponse('收货地址无效')

    # 通过地址id和用户id(防止获取地址时,用户不在线,所以加上用户id),
    # 获取地址信息的对象,并验证
    addressinfoobj = AddressInfo.objects.filter(id=address_id).first()
    if addressinfoobj is None:
        return HttpResponse('地址无效')

    orderinfoobj = OrderInfo()
    order_code = '20181010' + str(random.randint(100000, 999999))
    orderinfoobj.order_code = order_code
    total_money = 0
    manager_id = 0
    goods_name_all = ''
    # 循环获取该用户购物车商品的对象
    for carobj in Car.objects.filter(user_id=user_id):
        # 计算总的钱
        s_goods_money = carobj.number * int(carobj.goods.goods_xprice)
        total_money += s_goods_money

        goods_name_all += carobj.goods.goods_name

        # 获取商家id,由于在循环里面,所以获取的是最后一个商家的eid
        manager_id = carobj.goods.manager_id
        # 获取每个商品对象,来判断用户购买数量是否大于库存
        goods_obj = GoodsInfo.objects.filter(id=carobj.goods_id).first()
        # print(carobj.number)
        if carobj.number > goods_obj.goods_count:
            return message(goods_obj.goods_name +
                           '库存不足,请重新选择。<a href="%s">点击返回购物车</a>' %
                           (reverse('user:car_list')))

    orderinfoobj.money = total_money
    orderinfoobj.manage_id = manager_id
    orderinfoobj.user_id = user_id
    orderinfoobj.address = addressinfoobj.address
    orderinfoobj.save()

    ordergoodsobj = OrderGoodsInfo()
    for carobj2 in Car.objects.filter(user_id=user_id):
        # 循环次数等于商品种类,所以,
        # 每循环一次,就在订单商品信息表里面添加一条数据
        s_goods_money = carobj2.number * int(carobj2.goods.goods_xprice)
        ordergoodsobj.order_id = orderinfoobj.id
        ordergoodsobj.goods_id = carobj2.goods_id
        ordergoodsobj.number = carobj2.number
        ordergoodsobj.price = s_goods_money
        ordergoodsobj.save()

    # 信息确认并保存完成后,清空购物车
    Car.objects.filter(user_id=user_id).delete()
    """
     设置配置,包括支付宝网关地址、app_id、应用私钥、支付宝公钥等,其他配置值可以查看AlipayClientConfig的定义。
     """
    # 修改配置文件的参数
    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = 'https://openapi.alipaydev.com/gateway.do'
    alipay_client_config.app_id = '2016092100561552'
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QXT6wQ0cBPtMCgYEAuDnW8wNC5ZtihStpHymCDLeln1S/hebcncadxg/xAFdf7dXRltKCcrN3/L2aQr6YXSyVZGoxT1HCgVXvflgkV7pLe52G3ekm7M7lTNhe1XyDHCH5O9iKstbxjXkBz8b7zYaMA4zlH81yR4JfXXhPbQ1d4k13auKQk6PsaDmH1fkCgYEAjeZ1gr9X/fabS1NoYbgs/354HIsC9Uva/H79cPVDqNisOVkK9exbDyOeZUqxWskHSgdgc5ZjkIFxqDY74hFkitVGUWguDyw+zLyXaCff+FOIKv+Ivt/Smu1qVWI1S4kJE/WUmntELLSQr7qrCWmcqqCHZ9HyH3185CO+D8KxZfkCgYAuweBzWLR2al7DWZtFdWR3XDw+MepoWS2OmCyH2Ek11zeUC0crZMHpxoWlB5f3ABrN3URzbUGSsdslZtjBdDqN6s6Dl+7Iu7wgdV60JDBrS6gqnNYRXRdresckQ2goqbACX9AXSHAM57bRJKkYy1mlwAwlJBywlsmlKq3Tqbcw4w=='
    alipay_client_config.alipay_public_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArw4+bgGlsoU52PjJmzVdjSw+r1ApgbPL8cJnEfnkBMZ6BaKFQYioZk1+XufCBJcDN0acIyNI1RYs0zMxbmP+0nFVqoXVFt0kjjIBYnlBVJ9imL/krb0/DaM7uLAoIWdKGlKCuj+3QqlrFI6S8MUBN059eEXsKuscWojbBSUJsuMeJ0UyBZZK74J1quFYfESdjdamti+CaFgOfzzqFyTcvyBqamSTpajy+BK836kaDia76/hNBPlHlwB8CAiZ9kK/XahmE1boCP0ay5s66T7BOstD3CZFzD8JvmtKyOYV/nNa82sQBK1VDxLcaO2g761hIcqa68AM3uANMs1mj4dq6wIDAQAB'
    """
    得到客户端对象。
    注意,一个alipay_client_config对象对应一个DefaultAlipayClient,定义DefaultAlipayClient对象后,alipay_client_config不得修改,如果想使用不同的配置,请定义不同的DefaultAlipayClient。
    logger参数用于打印日志,不传则不打印,建议传递。
    """
    # 根据配置文件生成 客户端对象
    client = DefaultAlipayClient(alipay_client_config=alipay_client_config)
    """
    页面接口示例:alipay.trade.page.pay
    """
    # 对照接口文档,构造请求对象
    model = AlipayTradePagePayModel()
    model.out_trade_no = orderinfoobj.order_code
    model.total_amount = total_money
    model.subject = "支付测试"
    model.body = goods_name_all
    model.product_code = "FAST_INSTANT_TRADE_PAY"
    request = AlipayTradePagePayRequest(biz_model=model)
    request.return_url = 'http://47.93.191.192/user/pay_return_url/'
    # 得到构造的请求,如果http_method是GET,则是一个带完成请求参数的url,如果http_method是POST,则是一段HTML表单片段
    response = client.page_execute(request, http_method="GET")
    print("alipay.trade.page.pay response:" + response)

    # 第二种重定向方法,应用名:页面名(找的是路由,更改路径不影响页面跳转)
    return HttpResponseRedirect(response)