Exemple #1
0
    def post(self, request, *args, **kwargs):
        try:
            package_id = request.POST.get('package_id')
            order = VIPOrder.create_order(request.user, int(package_id))
            if order:
                log.info('****** order id: {} ******'.format(order.id))
                order.pay_type = VIPOrder.PAY_TYPE_BY_ALIPAY_APP
                out_trade_no = create_trade_id(order.id)
                order.outtradeno = out_trade_no
                order.save()
                result = {'order_id': order.id}

                alipay_client_config = AlipayClientConfig()
                alipay_client_config.app_id = smart_str(settings.ALIPAY_APP_INFO['basic_info']['APP_ID'])
                alipay_client_config.sign_type = smart_str(settings.ALIPAY_APP_INFO['other_info']['SIGN_TYPE'])
                with open(settings.ALIPAY_APP_INFO['basic_info']['APP_PRIVATE_KEY'], 'r') as fp:
                    alipay_client_config.app_private_key = fp.read()

                client = DefaultAlipayClient(alipay_client_config=alipay_client_config)

                model = AlipayTradeAppPayModel()
                model.total_amount = smart_str(str_to_specify_digits(str(order.price)))
                model.product_code = smart_str("QUICK_MSECURITY_PAY")
                model.body = smart_str(order.name)
                model.subject = smart_str(order.name)
                model.out_trade_no = smart_str(out_trade_no)
                model.passback_params = smart_str(settings.LMS_ROOT_URL + reverse("vip_purchase"))

                request = AlipayTradeAppPayRequest(biz_model=model)
                request.notify_url = smart_str(settings.ALIPAY_APP_INFO['other_info']['NOTIFY_URL'])
                result['alipay_request'] = client.sdk_execute(request)

                return Response(data=result)
        except Exception, e:
            log.exception(e)
Exemple #2
0
    def pay_apply(self,
                  order_id,
                  price: float,
                  subject: str,
                  content: str,
                  back_params: str = None,
                  timeout_express=None,
                  callback_url: str = callback_url):
        """
        :param timeout_express: 超时时间,分钟
        :param order_id: 订单编号
        :param price: 总价,金额
        :param subject: 标题
        :param content:
        :param back_params:公用回传参数,必须进行 UrlEncode
        :param callback_url:
        :return:
        """
        model = AlipayTradeAppPayModel()
        model.timeout_express = f'{round(timeout_express, 4)}m'
        model.total_amount = float(price)
        model.seller_id = """config.alipay_account"""
        model.product_code = "QUICK_MSECURITY_PAY"  # 固定值
        model.body = content[:128]  # 接口最长支持128个字符
        model.subject = subject
        model.out_trade_no = order_id

        if back_params:
            model.passback_params = back_params

        request = AlipayTradeAppPayRequest(biz_model=model)
        request.notify_url = callback_url
        return self.client.sdk_execute(request)
Exemple #3
0
    def get_pay_data(self, order, ip):
        " 获取支付数据 "
        model = AlipayTradeAppPayModel()
        model.total_amount = str(order.amount)
        model.subject = ""
        model.out_trade_no = order.number
        request = AlipayTradeAppPayRequest(biz_model=model)
        request.notify_url = ''
        response = self.client.sdk_execute(request)

        return {'detail': response}
Exemple #4
0
 def test_func(self):
     """测试函数"""
     model = AlipayTradeAppPayModel()
     model.timeout_express = "90m"
     model.total_amount = "0.01"
     model.seller_id = """config.alipay_account"""
     model.product_code = "QUICK_MSECURITY_PAY"
     model.body = "Iphone6 16G"
     model.subject = "iphone"
     model.out_trade_no = uuid.uuid1().hex
     request = AlipayTradeAppPayRequest(biz_model=model)
     request.notify_url = 'https://test_app.xunbaowang.net/interface/v1/transaction/pay/ali/app/pay_callback/'
     return self.client.sdk_execute(request)
Exemple #5
0
 def TradeAppPay(self, body, subject, out_trade_no, total_amount):
     client = DefaultAlipayClient(
         alipay_client_config=self.alipay_client_config, logger=logger)
     model = AlipayTradeAppPayModel()
     model.body = body
     model.subject = subject
     model.out_trade_no = out_trade_no
     model.total_amount = '0.01'
     model.timeout_express = self._alipy_apps['ALIPAY_TIMEOUT_EXPRESS']
     model.product_code = 'QUICK_MSECURITY_PAY'
     request = AlipayTradeAppPayRequest(biz_model=model)
     request.notify_url = self._alipy_apps['ALIPAY_NOTIFY_URL']
     response = client.sdk_execute(request)
     return str(response)
Exemple #6
0
 def get(self):
     model = AlipayTradeAppPayModel()
     model.timeout_express = "90m"
     model.total_amount = self.get_query_argument('amount', '1')
     #model.seller_id = "*****@*****.**"
     model.product_code = self.get_query_argument('product', '1_1_')
     #model.body = "Iphone6 16G"
     model.subject = self.get_query_argument('subject', '1_1_')
     model.out_trade_no = str(int(time.time())) + model.subject
     request = AlipayTradeAppPayRequest(biz_model=model)
     request.notify_url = 'http://xxxxxxx/AliPayOk'
     response = client.sdk_execute(request)
     #response = response.replace('&','&amp')
     #logging.info("alipay.trade.app.pay response:" + response)
     self.write(response)
Exemple #7
0
    """
    设置配置,包括支付宝网关地址、app_id、应用私钥、支付宝公钥等,其他配置值可以查看AlipayClientConfig的定义。
    """
    alipay_client_config = AlipayClientConfig()
    alipay_client_config.server_url = 'https://openapi.alipay.com/gateway.do'
    alipay_client_config.app_id = '2017020805562382'
    alipay_client_config.app_private_key = 'MIIEowIBAAKCAQEApSLuzkBrcuivMbmy/qaaYRBzKsZ24ALQMx580rT5BBLHiRcnRYcr4kz90wuE+akLfY9AYztMrGVZ6bQsnkkwH303sPUTB0wffN9By4FT/cvxMGsMYguL4zmLyUGl1C2YhuwvP1WYq08tuzRSMe5CaOFhxGrqnfDV1C6z7oowU/gugDjHUfgL+N9cohbXj5chKRcUOtZB0kSO0kn+AxULroc4hO1MEE4B/HQy1wNRX2Yjsh1IFw8Es32JIT60nAzOyR2MQcMdxZV4BiQS4DUB0x5Z55D2hTERliB95WPkhlNdq4BlQmKN/vAChi0zyKNnBkiOwV7u+pnwM4L4U4M3IwIDAQABAoIBACcoJWAavl+89O3hjqP7dVfWwrg93yo3AI9eh1KfPvzMRywmpVVDPBCpGPbWIG3iu6rGMQpWoVOvpKZZ5sqRqCuPUYlQU3bDgiPl/H/45qWjmklU2NbWzhDPMGpEesHZHfXAQ2PNNCpK2Bkvyt20FWMxLjGY+JEC7nElsdy6P8NpEGgWCWWvx4lhZ+anrSHiu+c/wp8ujsZSGILqiF36InCqV0lW64x/qtiSmJ4knBNbm1vMAXODD9Rw/fw7pWo/h4kPA8+vApSaBhTUKsgJ+93UoFr0h2FuJDXYrr+uVncjIFgQIMUOavS6DlQbKZ6IciIcRv7U0dE4mggiv0C9u0ECgYEA1eFPepCpiBz4IXYW1kmmce3WbzVKDsvWKeLOlc8rXtWkBmjbQEayRo8X8Hfthd8brvEnQUPLAuBRcc7L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ayiXPihsavSTN33mj8RdH3vOF52XGpQv7MXR56nAkoAvjlg9hyZa9Un00/xGhnJNMmUYQDG1aCmeVkcpCD1PBlzMuJjjPn7rDeRlkzINPIMBIaOhfdkK6bWjjIIEj0k3JMLWSl/fkMWTwIDAQAB'
    """
    得到客户端对象。
    注意,一个alipay_client_config对象对应一个DefaultAlipayClient,定义DefaultAlipayClient对象后,alipay_client_config不得修改,如果想使用不同的配置,请定义不同的DefaultAlipayClient。
    logger参数用于打印日志,不传则不打印,建议传递。
    """
    client = DefaultAlipayClient(alipay_client_config=alipay_client_config,
                                 logger=log)
    """
    构造唤起支付宝客户端支付时传递的请求串示例:alipay.trade.app.pay
    """
    model = AlipayTradeAppPayModel()
    model.timeout_express = "90m"
    model.total_amount = "0.01"
    model.seller_id = "2088102169162785"
    model.product_code = "QUICK_MSECURITY_PAY"
    model.body = "product_des"
    model.subject = "iphone"
    model.out_trade_no = "%d" % 1546067572847
    request = AlipayTradeAppPayRequest(biz_model=model)
    response = client.sdk_execute(request)
    # log.info("alipay.trade.app.pay response:" + response)
    print("alipay.trade.app.pay response:" + response)