私はPHP Webサービスを初めて利用していますが、以前この質問をしましたが、有用な解決策を得ることができませんでした。私はAPIからの応答に耳を傾け、ペイパルIPNサービスによって行われているように私のデータベースを更新しようとしています。私がこれまでに行ってきたスクリプトは、ブラウザで実行するとうまくいきます。私はPOSTを介して私のjsonレスポンスを取得していますが、APIは後でブラウズ/クライアントの関与なしに別の応答を送ります。サーバーの私のPHPスクリプトとデータベースを更新します。 APIにはnotifyURLフィールドがあり、これらの通知を送信するために必要です。リクエストを送信したのと同じファイルに設定しました。私はカールとPHPを使用して私の目標を達成するために、私はスクリプトに追加する必要が何phpとcurlのレスポンスサービスをpaypalと同じように作成しましたIPN
if($ch !== false){
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Set the content type to application/json
// curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;odata=verbose',
'Content-length:' . strlen($jsonDataEncoded))
);
}
//Execute the request
$result = curl_exec($ch);
if ($result === false){
curl_close($ch);
echo "Error".curl_errno($ch). "\n";
}else {
curl_close($ch);
$decoded = json_decode($result, true);
// echo '<pre>';
// var_dump($decoded["paymentAmount"]["totalAmountCharged"]);
// die;
$data['unique_id'] = $decoded["clientCorrelator"];
$data['subscriber_number'] = $decoded["endUserId"];
$data['payment_status'] = $decoded["transactionOperationStatus"];
$data['payment_gross'] = $decoded["paymentAmount"]["totalAmountCharged"];
$data['txn_id'] = $decoded["ecocashReference"];
$this->payments->insertTransaction($data);
die;
:以下は、私がこれまで持っているコードです。 APIは、下のjsonレスポンスを返し、私はそれを聞いて、特定のフィールドをデータベースに更新しようとしています。
{"id":71109,"version":0,"clientCorrelator":"58ada3aec8615","endTime":null,"startTime":1487774641697,"notifyUrl":"http://website/ecocash_send/transaction","referenceCode":"17589","endUserId":"774705932","serverReferenceCode":"2202201716440169792864","transactionOperationStatus":"PENDING SUBSCRIBER VALIDATION","paymentAmount":{"id":71110,"version":0,"charginginformation":{"id":71112,"version":0,"amount":1,"currency":"USD","description":" Bulk Sms Online payment"},"chargeMetaData":{"id":71111,"version":0,"channel":"WEB","purchaseCategoryCode":"Online Payment","onBeHalfOf":"PAMONMEFT","serviceId":null},"totalAmountCharged":null},"ecocashReference":"MP170222.1644.A00059","merchantCode":"0000","merchantPin":"000","merchantNumber":"771999313","notificationFormat":null,"serviceId":null,"originalServerReferenceCode":null}"
ありがとうございます。あなたは、このPHPとカールのスクリプトがAPIからの応答を得るのに十分であると言っていますか? – tendaitakas
私は、なぜあなたがそこでcURLを使用しているのかわかりませんが、確かにAPIはあなたに何を伝えているのかを説明するいくつかのデータを渡します。あなたはその情報を使ってあなたのデータベースを修正するだけです – RiggsFolly
私は自分のjsonを送信し、応答を得るためにカールを使用しています:** $ result = curl_exec($ ch); ** – tendaitakas