示例#1
0
        public async Task <IActionResult> ScanCodeGen(string orderName, string orderAmount, string outTradeNo)
        {
            AlipayTradePrecreateContentBuilder builder = BuildPrecreateContent(orderName, orderAmount, outTradeNo);

            //如果需要接收扫码支付异步通知,那么请把下面两行注释代替本行。
            //推荐使用轮询撤销机制,不推荐使用异步通知,避免单边账问题发生。
            AlipayF2FPrecreateResult precreateResult =
                _alipayF2FService.TradePrecreate(builder);
            //string notify_url = "http://10.5.21.14/Pay/Notify";  //商户接收异步通知的地址
            //AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder, notify_url);

            //以下返回结果的处理供参考。
            //payResponse.QrCode即二维码对于的链接
            //将链接用二维码工具生成二维码打印出来,顾客可以用支付宝钱包扫码支付。
            var bitmap = new Bitmap(Path.Combine(_hostingEnvironment.WebRootPath, "FTFPay/images/error.png"));

            switch (precreateResult.Status)
            {
            case ResultEnum.SUCCESS:
                bitmap.Dispose();
                bitmap = RenderQrCode(precreateResult.response.QrCode);
                //轮询订单结果
                //根据业务需要,选择是否新起线程进行轮询
                ParameterizedThreadStart parStart = new ParameterizedThreadStart(LoopQuery);
                Thread myThread = new Thread(parStart);
                object o        = precreateResult.response.OutTradeNo;
                myThread.Start(o);
                break;

            case ResultEnum.FAILED:
                Console.WriteLine("生成二维码失败:" + precreateResult.response.Body);
                break;

            case ResultEnum.UNKNOWN:
                Console.WriteLine("生成二维码失败:" + (precreateResult.response == null ? "配置或网络异常,请检查后重试" : "系统异常,请更新外部订单后重新发起请求"));
                break;
            }
            MemoryStream ms = new MemoryStream();

            bitmap.Save(ms, ImageFormat.Png);
            byte[] bytes = ms.GetBuffer();
            ms.Close();
            return(File(bytes, "image/png"));
        }
        public async Task <CreatePaymentResponse> CreatePaymentAsync(CreatePaymentRequest request)
        {
            var result = new CreatePaymentResponse();
            AlipayTradePrecreateContentBuilder builder = BuildPrecreateContent(request.PaymentId, request.Description, request.Amount);

            //支付回调
            string tenPayNotify = string.Concat(_configuration.ServerAddress, _configuration.NotifyUrl);
            AlipayF2FPrecreateResult precreateResult = _alipayF2FService.TradePrecreate(builder, tenPayNotify);

            //AlipayF2FPrecreateResult precreateResult = _alipayF2FService.TradePrecreate(builder);
            switch (precreateResult.Status)
            {
            case ResultEnum.SUCCESS:
                result.AdditionalData.Add("CodeUrl", precreateResult.response.QrCode);
                break;

            default:
                _logger.Error(L("Payments.Alipay.PayFail", precreateResult.response.SubCode, precreateResult.response.SubMsg));
                break;
            }

            return(await Task.FromResult(result));
        }