使用CURL使https发布请求失败

时间:2019-02-24 01:44:01

标签: curl php-curl

我正在实现一个支付网关,用于通过php编写的api传输通话时间和移动资金。通话时间有一个http post端点,移动汇款有一个https端点。当我为通话时间执行http端点时,我从api服务器得到响应。但是,当我对移动资金的https端点进行api调用时,我没有收到任何响应。当我使用邮递员访问https端点时,它给了我正确的响应,但是在我的实时环境中不起作用。 下面是我正在使用的curl函数

`

function call_api($MERCHANT_KEY,$MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL) {
   try{
        $request = curl_init($API_URL);
        $request_params = array(
        "merchantKey"  =>  $MERCHANT_KEY,
        "merchantToken" => $MERCHANT_TOKEN,
        "serviename"  =>  $SERVICE_NAME,
        "merchantreference" => $MERCHANT_REFERRENCE,
        "serviceDetails" => $SERVICE_DETAILS
        );
        curl_setopt($request, CURLOPT_POST, true);
        curl_setopt($request,CURLOPT_POSTFIELDS, json_encode($request_params));
        curl_setopt($request, CURLOPT_HTTPHEADER, array(
            "Content-type: application/json"
            )
        );
        curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
        $feedback = curl_exec($request);

        curl_close($request);
        return $feedback;
    }
    catch(Exception $ex){
        echo "API IS NOT WORKING";
    }


//END OF API CALL
}

`

Below is my code implementation for the airtime endpoint

`

$SERVICE_NAME='airtime'; $AMOUNT=2.00; //CALL THE API $MERCHANT_KEY = '1C60809F-4F6B-4404-BB46-738F5A365B5F'; $MERCHANT_TOKEN = '777402A0-1166-4307-9C88-7C65475321B2'; $MERCHANT_REFERRENCE = date("YmdHis"); $TRANSACTION_ID=date("YmdHis"); $SERVICE_DETAILS="{'amount': '".$AMOUNT."','network': '".$NETWORK."','mobileNumber': '".$MSISDN."','transId':'".$TRANSACTION_ID."'}"; $API_URL = 'http://196.216.228.23/ApiHubtest/api/myghpayextension/paymentRequest'; $feedback=call_api($MERCHANT_KEY, $MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL); //DECODE THE RESPONSE AND SAVE IN A TABLE $obj = json_decode($feedback); $STATUS=$obj->{'Status'}; if($STATUS==1){ //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='API_FAILED'"; $conn->query($dbconnection,$apisave); $RESPONSE="API_FAILED"; }elseif($STATUS==0){ $MESSAGE=$obj->{'Message'}; //$TRANSACTION_ID=$obj->{'transactionid'}; //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='$TRANSACTION_ID'"; $conn->query($dbconnection,$apisave); //UPDATE THE STAFF RECORDS $updsub="SELECT * FROM promo_subs WHERE MSISDN='$MSISDN'"; $updsubrun=$conn->query($dbconnection,$updsub); if($conn->sqlnum($updsubrun)==0){ $inssub="INSERT INTO promo_subs(msisdn,creditrating,lastplayed) VALUES ('$MSISDN',1,'$dateTime')"; $conn->query($dbconnection,$inssub); }else{ $updsub="UPDATE promo_subs SET creditrating=(creditrating + 1), lastplayed='$dateTime' WHERE msisdn='$MSISDN'"; $conn->query($dbconnection,$updsub); } $RESPONSE="OK"; }

And this is the code implementation for the mobile money transfer <pre>

$SERVICE_NAME='creditwallet'; $AMOUNT=1.00; //CALL THE API $MERCHANT_KEY = 'BBA81A2F-E9E3-46FB-9E89-6B8A0EABF26E'; $MERCHANT_TOKEN = '59E00F9D-F98F-4348-B221-E7DFA79A445F'; $MERCHANT_REFERRENCE = date("YmdHis"); $TRANSACTION_ID=date("YmdHis"); $SERVICE_DETAILS="{'amount': '".$AMOUNT."','network': '".$NETWORK."','mobileNumber': '".$MSISDN."','transId':'".$TRANSACTION_ID."','ReferecnceID':'".$TRANSACTION_ID."','remarks':'CREDIT Wallet'}"; $API_URL = "https://196.216.228.129/apihub/api/myghpayextension/paymentRequest"; echo $feedback=call_api($MERCHANT_KEY, $MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL); //DECODE THE RESPONSE AND SAVE IN A TABLE $obj = json_decode($feedback); $STATUS=$obj->{'Status'}; if($STATUS==0){ //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='API_FAILED'"; $conn->query($dbconnection,$apisave); $RESPONSE="API_FAILED"; }elseif($STATUS==1){ $MESSAGE=$obj->{'Message'}; //$TRANSACTION_ID=$obj->{'transactionid'}; //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='$TRANSACTION_ID'"; $conn->query($dbconnection,$apisave); //UPDATE THE STAFF RECORDS $updsub="SELECT * FROM promo_subs WHERE MSISDN='$MSISDN'"; $updsubrun=$conn->query($dbconnection,$updsub); if($conn->sqlnum($updsubrun)==0){ $inssub="INSERT INTO promo_subs(msisdn,creditrating,lastplayed) VALUES ('$MSISDN',1,'$dateTime')"; $conn->query($dbconnection,$inssub); }else{ $updsub="UPDATE promo_subs SET creditrating=(creditrating + 1), lastplayed='$dateTime' WHERE msisdn='$MSISDN'"; $conn->query($dbconnection,$updsub); } $RESPONSE="OK";

0 个答案:

没有答案