繁体   English   中英

QuickBooks桌面和Laravel-内容类型为xml; charset = UTF-8,但预期为text / xml

[英]QuickBooks desktop and Laravel- content type xml; charset=UTF-8 but expected text/xml

我试图获得在Laravel(5.1)中工作的consolibyte quickbooks-php的示例之一。 我在使用控制器时无法正常工作。 Web连接器的日志显示客户端找到的响应内容类型为'xml; charset = UTF-8”,但预期为“ text / xml”。

我使用的代码是quickbooks-php demo的稍作修改的版本。 我一直无法找到quickbooks-php桌面和laravel的示例,并且不确定自己在做什么。

注意-require_once('../ QuickBooks.php')在app / config / app.php中。

调节器

public function sync(RequestInterface $request, InvoiceSyncService $obj){
    $this->logger->info('############################### Start QB sync (laravel) ######################################');

    $user = 'user';
    $pass = 'password';

    // Map QuickBooks actions to handler functions
    $map = array(
        QUICKBOOKS_ADD_CUSTOMER => array( array( $obj, 'addCustomerRequest' ), array( $obj, 'addCustomerResponse' ) ),
    );

    // This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
    $errmap = array(
        500 => array( $obj, 'handleError500' ),
    );

    // An array of callback hooks
    $hooks = array(
    );

    // Logging level
    $log_level = QUICKBOOKS_LOG_DEVELOP;        // Use this level until you're sure everything works!!!

    // What SOAP server you're using
    $soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;        // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)

    $soap_options = array(      // See http://www.php.net/soap
    );

    $handler_options = array(
    );      // See the comments in the QuickBooks/Server/Handlers.php file

    $driver_options = array(
    );

    $callback_options = array(
    );

    $dsn = 'mysqli://username:password@localhost/database';

    if (!QuickBooks_Utilities::initialized($dsn))
    {
        // Initialize creates the neccessary database schema for queueing up requests and logging
        QuickBooks_Utilities::initialize($dsn);

        // This creates a username and password which is used by the Web Connector to authenticate
        QuickBooks_Utilities::createUser($dsn, $user, $pass);

        $primary_key_of_your_customer = 5;

        $Queue = new QuickBooks_WebConnector_Queue($dsn);
        $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
    }

    // Set the DSN string because some of our callbacks will use it
    $obj->setDSN($dsn);

    // Create a new server and tell it to handle the requests
    $Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
    $response = $Server->handle(true, true);

    return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}

InvoiceSyncService

protected $_dsn;

private $logger;

public function __construct(LoggerFactory $loggerFactory)
{
    $this->logger = $loggerFactory->createLogger('invoice-sync');
}


public function setDSN($dsn)
{
    $this->_dsn = $dsn;
}

public function addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    $this->logger->info('A request occurred');

    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerAddRq>
                    <CustomerAdd>
                        <Name>ConsoliBYTE Solutions (' . mt_rand() . ')</Name>
                        <CompanyName>ConsoliBYTE Solutions</CompanyName>
                        <FirstName>Keith</FirstName>
                        <LastName>Palmer</LastName>
                        <BillAddress>
                            <Addr1>ConsoliBYTE Solutions</Addr1>
                            <Addr2>134 Stonemill Road</Addr2>
                            <City>Mansfield</City>
                            <State>CT</State>
                            <PostalCode>06268</PostalCode>
                            <Country>United States</Country>
                        </BillAddress>
                        <Phone>860-634-1602</Phone>
                        <AltPhone>860-429-0021</AltPhone>
                        <Fax>860-429-5183</Fax>
                        <Email>Keith@ConsoliBYTE.com</Email>
                        <Contact>Keith Palmer</Contact>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}


public function addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{

    $this->logger->info('A response occured');
}

public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{


    // return true;         // If you return TRUE, it will continue to process requests
    return false;           // If you return FALSE, it will stop processing requests
}

public function hookLoginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
    if ($this->_dsn)
    {
        return true;
    }

    return false;
}

编辑

这是格式不正确的xml的Web连接器日志。

20190201.22:01:32 UTC:QBWebConnector.WebServiceManager.DoUpdateSelected():application ='Laravel'的updateWS()已启动20190201.22:01:32 UTC:QBWebConnector.RegistryManager.getUpdateLock():HKEY_CURRENT_USER \\ Software \\ Intuit \\ QBWebConnector \\ UpdateLock = FALSE 20190201.22:01:32 UTC:QBWebConnector.RegistryManager.setUpdateLock():HKEY_CURRENT_USER \\ Software \\ Intuit \\ QBWebConnector \\ UpdateLock已设置为True 20190201.22:01:32 UTC:QBWebConnector.RegistryManager.setUpdateLock():**** *****************更新会话已锁定********************* UTC 20190201.22:01:32:QBWebConnector。 SOAPWebService.instantiateWebService():启动到以下应用程序的连接。 20190201.22:01:32 UTC:QBWebConnector.SOAPWebService.instantiateWebService():AppName:Laravel 20190201.22:01:32 UTC:QBWebConnector.SOAPWebService.instantiateWebService():AppUniqueName(如果可用):Laravel 20190201.22:01:32 UTC:QBWebConnector.SOAPWebService .instantiateWebService():AppURL: http:// localhostvisuals / invoicing / sync 20190201.22:01:32 UTC:QBWebConnector.SOAPWebService.do_serverVersion(): *调用serverVersion()。 20190201.22:01:33 UTC:QBWebConnector.SOAPWebService.do_serverVersion():从Web服务收到的serverVersion调用实际错误:。 为了向后兼容所有Web服务器,QBWC将在app-not-supporting-serverVersion下捕获所有错误。 20190201.22:01:33 UTC:QBWebConnector.SOAPWebService.do_serverVersion():此应用程序不包含对serverVersion的支持。 允许更新操作以实现向后兼容。 20190201.22:01:33 UTC:QBWebConnector.SOAPWebService.do_clientVersion():*调用具有以下参数的clientVersion():20190201.22:01:34 UTC:QBWebConnector.SOAPWebService.updateWS():从Web服务收到的clientVersion调用实际错误:。 为了向后兼容所有Web服务器,QBWC将在app-not-supporting-clientVersion下捕获所有错误。 20190201.22:01:34 UTC:QBWebConnector.SOAPWebService.do_clientVersion():此应用程序不包含对clientVersion的支持。 允许更新操作以实现向后兼容。 20190201.22:01:34 UTC:QBWebConnector.SOAPWebService.do_authenticate():正在对应用程序'Laravel'进行身份验证,用户名='user'20190201.22:01:34 UTC:QBWebConnector.SOAPWebService.do_authenticate():***使用以下参数:20190201.22:01:34 UTC:QBWebConnector.SOAPWebService.do_authenticate():QBWC1012:由于以下错误消息,身份验证失败。 响应不是格式正确的XML。 更多信息:System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(位于QBWebConnector.localhost.WCWebServiceDoc.authenticate(字符串strUserName,字符串strPassword)位于QBWebConnector.localhost.WCWebService.authenticate(String MethodName,Object [] parameters) QBWebConnector.SOAPWebService.authenticate处的字符串strUserName,String strPassword)(QBWebConnector.WebService.do_authenticate(String&ticket,String&companyFileName)处的String UserName,字符串密码)Source = System.Web.Services 20190201.22:01:34 UTC:QBWebConnector.RegistryManager。 setUpdateLock():HKEY_CURRENT_USER \\ Software \\ Intuit \\ QBWebConnector \\ UpdateLock已设置为False 20190201.22:01:34 UTC:QBWebConnector.RegistryManager.setUpdateLock():***************** ****更新会话已解锁********************** 20190201.22:01:34 UTC:QBWebConnector.WebServiceManager.DoUpdateSelected():更新已完成,但有错误。 有关详细信息,请参见日志(QWClog.txt)。

您想要的内容类型是text/xml ,而不仅仅是xml

例如改变这个:

return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml'); }

对此:

return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'text/xml'); }

xml不是有效的内容类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM