如何使用curl和php在另一台服务器上收到此请求

时间:2018-01-07 07:50:03

标签: php curl

我是新来的,所以请耐心等待,这是我的请求代码,我想在另一台服务器中编写另一段代码,接受它并使用php和curl返回xml 7101成功代码。如何在接收服务器中编写代码。这实际上是我将用于在我的系统和存储在云中的另一个远程系统之间交换数据的API我已经设法成功发送请求但是我一直在接收他们的请求,我已经花了整整一周时间请帮助我在他们发送请求时收到请求。

成功代码

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gepgBillSubReqAck>
    <TrxStsCode>7101</TrxStsCode>
</gepgBillSubReqAck>

请求代码是这个,

<?php

    //Bill Request 
    $content ="<gepgBillSubReq>
        <BillHdr>
            <SpCode>SP103</SpCode>
            <RtrRespFlg>true</RtrRespFlg>
        </BillHdr>
        <BillTrxInf>
            <BillId>1812022009968</BillId>
            <SubSpCode>1001</SubSpCode>
            <SpSysId>TANESCO001</SpSysId>
            <BillAmt>1180</BillAmt>
            <MiscAmt>0</MiscAmt>
            <BillExprDt>2017-12-31T23:59:59</BillExprDt>
            <PyrId>5144AA5914</PyrId>
            <PyrName>test</PyrName>
            <BillDesc>Bill Number 5913</BillDesc>
            <BillGenDt>2017-12-21T09:39:00</BillGenDt>
            <BillGenBy>Bhstenkubo</BillGenBy>
            <BillApprBy>Bhstenkubo</BillApprBy>
            <PyrCellNum/>
            <PyrEmail/>
            <Ccy>TZS</Ccy>
            <BillEqvAmt>1180</BillEqvAmt>
            <RemFlag>false</RemFlag>
            <BillPayOpt>1</BillPayOpt>
            <BillItems>
                <BillItem>
                    <BillItemRef>5144AA5914</BillItemRef>
                    <UseItemRefOnPay>N</UseItemRefOnPay>
                    <BillItemAmt>1180</BillItemAmt>
                    <BillItemEqvAmt>1180</BillItemEqvAmt>
                    <BillItemMiscAmt>0</BillItemMiscAmt>
                    <GfsCode>140316</GfsCode>
                </BillItem>
            </BillItems>
        </BillTrxInf>
    </gepgBillSubReq>";

    $resultCurlPost = "";

    $serverIp = "XXXXXXXXXXXXXXXX";

    $uri = "/XXX/XXX/qrequest"; //this is for qrequest

    echo "Message ready to GePG:"."\n".$content."\n";

    $ch = curl_init($serverIp.$uri);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type:application/xml',
                        'Gepg-Com:default.sp.in',
                        'Gepg-Code:SP103',
                        'Content-Length:'.strlen($content))
    );

    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);

    //Capture returned content from GePG
    $resultCurlPost = curl_exec($ch);
    curl_close($ch);
    //$resultCurlPost=$data; 
    if(!empty($resultCurlPost)){

        echo "\n\n";
        echo "Received Response\n";
        echo  $resultCurlPost;
        echo "\n";              
    }
    else
    {
        echo "No result Returned"."\n";
    }

?>

1 个答案:

答案 0 :(得分:0)

Thanks, you guys for contributing I found a solution, I used file_get_contents("php://input"); on the receiving server and so far it is working fine.