如何进行身份验证以访问我们自己的数据?

时间:2013-02-15 21:56:12

标签: java quickbooks intuit-partner-platform quickbooks-online

我正在尝试使用IDS从基于java的Web应用程序访问QBO中的数据。我已经找到了一些例子(例如ipp-java-devkit中的例子)并且汇集了大约20行代码来连接和验证......我还没有任何工作。这些文档似乎是围绕构建第三方应用程序来销售给其他公司,以便他们可以从应用程序访问自己的数据。在这种情况下,我理解需要额外的安全性,但我当然不需要在Intuit App Store中创建一个应用程序来访问我们自己的数据吗?

有没有人知道有关如何执行此操作的示例或教程?

1 个答案:

答案 0 :(得分:1)

Per Intuit的FAQ,Intuit Anywhere / IDS只能用于SaaS应用程序(例如,您尝试向其他人销售的应用程序,允许他们将QuickBooks文件连接到您的应用程序)

来自常见问题解答:

  

问:实施Intuit Anywhere有哪些要求?

     

答:您的应用必须:

     
      
  • 是一款可在浏览器中使用的网络应用,   作为服务出售(SaaS,包括基于交易定价)   提供您向多个客户销售的产品。移动扩展到   您的SaaS应用程序受支持。

  •   
  • 在开始之前通过安全审核   和客户一起生活。

  •   

并且:

  问:我想将我的自定义(非SaaS,单租户)解决方案与Intuit Anywhere集成。 >我可以这样做吗?

     <答:答:不是今天,但我们正在考虑它。

由于您尝试构建的内容不属于该模式,因此您没有资格使用IDS。

您应该使用qbXML。

在我们的QuickBooks integration wiki上,我们有一些使用Java连接到QuickBooks Online的示例。

您应该使用Intuit register in DESKTOP mode,然后您可以使用这样的代码来交换数据:

import java.net.*;
import java.io.*;
import javax.net.ssl.*;

// WARNING SUPER SLOPPY DEMO CODE - YOU SHOULD CLEAN THIS UP AND MAKE THIS PRETTY IF YOU USE IT!

public class Test {

    protected static String _appID = "134476472";

    protected static String _appLogin = "test.www.yourdomain.com";

    protected static String _connTicket = "TGT-47-1sRm2nXMVfm$n8hb2MZfVQ";

    protected static String _appURL = "https://webapps.quickbooks.com/j/AppGateway";

    /**
     * @param args
     */
    public static void main(String[] args) {

        // First, we need to sign on to QBOE
        String xml = "<?xml version=\"1.0\" ?>" + 
        "<?qbxml version=\"6.0\"?>" + 
        "<QBXML>" + 
        "   <SignonMsgsRq>" + 
        "       <SignonDesktopRq>" + 
        "           <ClientDateTime>2007-01-02T01:02:35</ClientDateTime>" + 
        "           <ApplicationLogin>" + Test._appLogin + "</ApplicationLogin>" + 
        "           <ConnectionTicket>" + Test._connTicket + "</ConnectionTicket>" + 
        "           <Language>English</Language>" + 
        "           <AppID>" + Test._appID + "</AppID>" + 
        "           <AppVer>1</AppVer>" + 
        "       </SignonDesktopRq>" + 
        "   </SignonMsgsRq>" + 
        "</QBXML>";

        String out = "";
        try {
            out = Test._doRequest(xml);
            System.out.println(out);
        }
        catch (Exception ex) {
            System.out.println("Something bad happened: " + ex.getMessage());
        }

        // Parse out the connection ticket
        String sessTicket = out.substring(291, 330);
        System.out.println("Session ticket: " + sessTicket);

        // Send an actual request
        String xml2 = "<?xml version=\"1.0\" ?>" +  
"<?qbxml version=\"6.0\"?>" +  
"<QBXML> " + 
"   <SignonMsgsRq>" + 
"       <SignonTicketRq>" +  
"           <ClientDateTime>2006-09-20T15:49:26</ClientDateTime>" +  
"           <SessionTicket>" + sessTicket + "</SessionTicket>" + 
"           <Language>English</Language> " + 
"           <AppID>" + Test._appID + "</AppID>" + 
"           <AppVer>1</AppVer>" +  
"       </SignonTicketRq>" +  
"   </SignonMsgsRq>" +  
"   <QBXMLMsgsRq onError=\"continueOnError\">" +  
"       <CustomerQueryRq requestID=\"2\" />" +  
"   </QBXMLMsgsRq>" +  
"</QBXML>";

        try {
            System.out.println(Test._doRequest(xml2));      
        }
        catch (Exception ex) {
            System.out.println("Something bad happened: " + ex.getMessage());
        }
    }

    protected static String _doRequest(String xml) throws Exception {
        String xmlOut = null;

               try 
               {
                  URL url= new URL(Test._appURL);
                  HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
                  connection.setDoOutput(true);
                  connection.setDoInput(true);

                  connection.setRequestProperty("Content-Type", "application/x-qbxml");

                  PrintWriter out = new PrintWriter(connection.getOutputStream());
                  out.println(xml); //XML Input
                  out.close();
                  BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                  String inputLine = "";
                  xmlOut = "";
                  StringBuffer strOut = new StringBuffer();

                  while ((inputLine = in.readLine()) != null)
                  {
                      strOut.append(inputLine);
                  }
                  xmlOut = strOut.toString();

                  in.close();
               }
               catch(ConnectException conEx)
               {
                  System.out.println("Connection is unavailable. (ConnectException in SecureEnterpriseSocketSession class) " + conEx);
                  throw new Exception(conEx.getMessage());
               }
               catch(MalformedURLException malformedURLEx)
               {
                  System.out.println("Invalid URL. Cannot Connect. (MalformedURLException in SecureEnterpriseSocketSession class) " + malformedURLEx);
                  throw new Exception(malformedURLEx.getMessage());
               }
               catch(IOException ioEx)
               {
                  System.out.println("Invalid URL. Cannot Connect. (IOException in SecureEnterpriseSocketSession class) " + ioEx);
                  throw new Exception(ioEx.getMessage());
               }
               return xmlOut;
    }
}