3

に引用符をインポートする必要がありますvtiger。vtiger WebサービスAPIを使用して実行できることがわかりました

リファレンス マニュアルを見つけました: https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual

しかし、PHPスクリプトの例も、渡す必要のあるデータフィールドも見つかりませんwebservice.php

助けてください、私はいくつかのガイダンスが必要です。

4

2 に答える 2

3

私はこのようなことをしました。私は迅速で(むしろ)汚いが実用的な解決策を持っています:

<?php

function createOffer($account_id,$subject,$offerlanguage, $totalamount,$date_submission,$date_decision,$date_start,$assigned_user_id,$quotestage,$winningchance,$description,$productarray){

        global $adb;

        $endpointUrl = "[your URL]/webservice.php";
        $userName="admin";
        $userAccessKey = '[your accesskey]';

        $httpc = new HTTP_CLIENT();

        //getchallenge request must be a GET request.
        $httpc->GET($endpointUrl."?operation=getchallenge&username=".$userName);

        $response = $httpc->currentResponse();
        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        //check for whether the requested operation was successful or not.
        if($jsonResponse['success']==false)
            //handle the failure case.
            die('getchallenge failed:'.$jsonResponse['error']['errorMsg']);

        //operation was successful get the token from the reponse.
        $challengeToken = $jsonResponse['result']['token'];
        //create md5 string concatenating user accesskey from my preference page
        //and the challenge token obtained from get challenge result.
        $generatedKey = md5($challengeToken.$userAccessKey);

        //getchallenge request must be a GET request.
        $httpc->post("$endpointUrl",
                        array('operation'=>'login', 'username'=>$userName, 'accessKey'=>$generatedKey), true);
        $response = $httpc->currentResponse();

        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        //operation was successful get the token from the reponse.
        if($jsonResponse['success']==false)
            //handle the failure case.
            die('login failed:'.$jsonResponse['error']['errorMsg']);

        //login successful extract sessionId and userId from LoginResult to it can used for further calls.
        $sessionId = $jsonResponse['result']['sessionName'];
        $userId = $jsonResponse['result']['userId'];

        $currency_id=1;
        $params =  array('description'=>$description,'subject'=>$subject,'quotestage'=>$quotestage,'assigned_user_id'=>'2x'.$assigned_user_id,'account_id'=>'3x'.$account_id,'cf_682'=>$offerlanguage,'currency_id'=>'21x'.$currency_id,'taxtype'=>'group','cf_683'=>$date_submission,'cf_684'=>$date_decision,'cf_685'=>$date_start,'cf_766'=>$winningchance);

        $urlArgs = "?&total=".$totalamount;
        //encode the object in JSON format to communicate with the server.
        $objectJson = Zend_JSON::encode($params);
        //name of the module for which the entry has to be created.
        $moduleName = 'Quotes';
        //sessionId is obtained from loginResult.
        $params = array("sessionName"=>$sessionId, "operation"=>'create', "element"=>$objectJson, "elementType"=>$moduleName);
        //Create must be POST Request.
        $httpc->post($endpointUrl.$urlArgs, $params, true);
        $response = $httpc->currentResponse();
        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        $savedObject = $jsonResponse['result'];
        $id = $savedObject['id'];   

        $id=str_replace("13x", "", $id);

        echo $id." offer: ".$subject." created for amount ".$totalamount." for customer: ".$account_id." assigned to: ".$assigned_user_id;

        return $id;

    }

ご覧のとおり、カスタム フィールドもいくつかあるので、それらをどのように処理したかがわかります。

この関数は次のように呼び出すことができます。

createOffer($account_id, $subject, $offerlanguage, $totalamount, $date_submission, $date_decision, $date_start, $assigned_user_id, $quotestage, $winningchance, $description, $productarray)

次に、製品も追加する必要があります。これは、見積もりごとにより多くの製品がある可能性があるため、別の関数を介して最も簡単であることがわかりました...

<?php

function createProducts($productarray,$id) {
    $counter = 1;
    foreach ($productarray as $prod) {
        $query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice) values(?,?,?,?,?)";
        $qparams = array($id,$prod['prod'],$counter,$prod['pcs'],$prod['price']);
        $productadded=$adb->pquery($query,$qparams);
        $counter=$counter+1;
    }
}

次のように使用します。

$prodlist = array();

array_push($prodlist,array('prod'=>"prod1",'pcs'=>2,'price'=>1000));
array_push($prodlist,array('prod'=>"prod2",'pcs'=>2,'price'=>100));

createProducts($prodlist,10);

私のロジックは次のようになります。

  • createOffer 関数を使用して見積もりを作成します。新しく作成された見積もりの​​ ID を返します
  • 次に、製品の配列を作成し (ここには非常に基本的なデータしかありません)、見積もりの​​ ID を参照して追加します。

おそらく最も美しいソリューションではありませんが、機能します。

于 2013-02-06T21:42:31.153 に答える
1

たぶん、このように始めることができます(参照リンクによると)。

マニュアル: https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual
ログイン: https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual#Login

擬似;

<?php
class VTiger_Login
{
    private $serviceURL = 'http://vtiger_url/webservice.php?operation=login&username=%s&accessKey=%s';
    // A Vtiger username.
    private $userName = 'my_username';
    // An md5 of the concatenation of the challenge token and the user's webservice access key. 
    private accessKey = 'my_accesskey';

    public function login() {
        // Open CURL
        $ch = curl_init();
        // Set URL as same as on manual
        curl_setopt($ch, CURLOPT_URL, sprintf($this->serviceURL, $this->userName, $this->accessKey));
        // Need POST according to manual
        curl_setopt($ch, CURLOPT_POST, 1);
        // Receive server response = TRUE
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // Exec CURL
        $result = curl_exec($ch);
        // Close CURL
        curl_close($ch);

        /*
        $result should be like this according to manual;
        LoginResult {
            sessionId: String     // Unique Identifier for the session
            userId: String        // The vtiger id for the logged in user
            version: String       // The version of the webservices api
            vtigerVersion: String // The version of the vtiger crm.
        } 
        */

        // From manual: All structural data including response from the api is represented as JSON strings. 
        $result =@ json_decode($result);
        // See "Response" on manual
        if (null === $result) {
            throw new Exception('No response returned from Vtiger server!');
        }
        // See "ErrorObject" on manual
        if (null !== $result->success && false === $result->success) {
            throw new Exception('Something went wrong with login operation! errorCode: '. 
                        $result->errorCode .', errorMessage: '. $result->errorMessage);
        }

        // I think, there is no problem anymore, go with $result after this line...
    }
}
于 2013-01-30T11:34:06.753 に答える