0

私はこのコードを使用しています...しかし、コードでcurlエラーが発生しています..

 function send_data($data) {
            $url = ""; // URL to POST FORM. (Action of Form)
            $url .= '?acx=' . urlencode('V2ViSnNvbkRldkFwbkBTaWdtYUFwbjpXZWIxMjMkSnNvbg==') . '&key=' . urlencode('QW51bWF0aGlVbmRhQFNpZ21hQXBuOlVuZHVBbnVtYXRoaQ==');
            $url .= '&impdata=' . urlencode('{"System":{"Client":"SigmaApn","ACX":"V2ViSnNvbkRldkFwbkBTaWdtYUFwbjpXZWIxMjMkSnNvbg==","KEY":"QW51bWF0aGlVbmRhQFNpZ21hQXBuOlVuZHVBbnVtYXRoaQ==","ClientIP":"74.117.104.99","Mode":"TEST"},"Module":{"Process":"BatchEnrollment","Version":"2.1.5","DataDefinition":[{"Name":"enrolment_queue","IncludeRecType":"false","Identifier":"sys_batch_no","Header":["batch_no","source","source_line","agent_code","premise_id","plan_group","request_date","enrol_type","cust_firstname","cust_lastname","phone1","cm_address1","cm_city","cm_state","cm_zip","life_support","cust_status","plan_id1","contract_ind","contract_type","calc_method","rate_type","adder1_rate","cust_bill_type","edi_bill_presenter"]}],"Data":[["Batch","BATCH","1","0","PREMISE1","R","10/28/2011","M","' . $data['personalinfo_first_name'] . '","' . $data['personalinfo_last_name'] . '","8050123481","' . $data['service_address1'] . '","' . $data['service_city'] . '","' . $data['service_state'] . '","' . $data['service_zipcode'] . '","N","P","PN001","Y","MCP2","1","4","0.02","Default","ESP"]]}}');
            $url .= '&mode=' . urlencode('TEST');
            $headersVal = array("application/x-www-form-uriencoded");
            $myFile = "/tmp/isigma.txt";
            $fh = fopen($myFile, 'w') or die("can't open file");
            $ch = curl_init();    // Initialize a CURL session.
            curl_setopt($ch, CURLOPT_URL, $url);  // Pass URL as parameter.
            curl_setopt($ch, CURLOPT_STDERR, $fh);
            curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form  
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
            curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/iSIGMARootCA.crt");
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "/APN_Generic_JSON.pem");
            curl_setopt($ch, CURLOPT_SSLKEY, getcwd() . "/apnakey.pem");
            curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);  // grab URL and pass it to the variable.
            curl_close($ch);  // close curl resource, and free system resources.  
            fclose($fh);

            $res_array = json_decode($result, true);

            if (!empty($result)) {
                return $res_array;
            } else {
                echo "Curl Error" . curl_error($ch);
            }
        }

事前に助けてくれてありがとう..

4

1 に答える 1

1

この関数を使用してデータを投稿しています。連想配列を 2 番目のパラメーターとして配置できます。最初のパラメーターは呼び出したい URL です。

private function postData($url, $data) {

        $post_data = http_build_query($data);
        $fp = tmpfile();
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_TIMEOUT, 20);
        curl_setopt($curl, CURLOPT_FILE, $fp);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_FAILONERROR, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_COOKIEJAR, '/dev/null');

        $status = curl_exec($curl);
        $response['http_code'] = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($status) {
            $response['error'] = curl_error($curl);
            $response['errno'] = curl_errno($curl);
        }

        curl_close($curl);

        rewind($fp);

        $response['data'] = '';
        while ($str = fgets($fp, 4096)) {
            $response['data'] .= $str;
        }
        fclose($fp);

        return $response['data'];
    }
于 2012-04-26T13:17:54.050 に答える