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)
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)
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}
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)
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)
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('&','&') #logging.info("alipay.trade.app.pay response:" + response) self.write(response)
settle_detail_info = SettleDetailInfo() settle_detail_info.amount = 50 settle_detail_info.trans_in_type = "userId" settle_detail_info.trans_in = "2088302300165604" 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") print("alipay.trade.page.pay response:" + response) """ 构造唤起支付宝客户端支付时传递的请求串示例:alipay.trade.app.pay """ model = AlipayTradeAppPayModel() model.timeout_express = "90m" model.total_amount = "9.00" model.seller_id = "2088301194649043" model.product_code = "QUICK_MSECURITY_PAY" model.body = "Iphone6 16G" model.subject = "iphone" model.out_trade_no = "201800000001201" request = AlipayTradeAppPayRequest(biz_model=model) response = client.sdk_execute(request) print("alipay.trade.app.pay response:" + response)