嵌入代码
- Java
- .Net
- PHP
- Python
- Node.js
Step 1 : 导入
导入用于发出 HTTP 请求的库。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
Step 2 : 源代码
构建 HTTP 请求主体并将此数据作为 POST 请求发送。
.....
String jsonMessage = "{'MsgVer' : '" + msgVer +
"', 'PmtType' : '" + pmtType +
"', 'IsPreauthInd' : '" + isPreauthInd +
"', 'CallerDeviceType' : '" + callerDevice +
"', 'CallerDeviceVer' : '" + callerDeviceVer +
"', 'TxnID' : '" + txnID +
"', 'LocalTxnDTTime' : '" + txnDateTime +
"', 'Email' : '" + email +
"', 'DeviceSN' : '" + deviceSN +
"', 'AmtTxn' : '" + amt +
"', 'CrcyTxn' : '" + crcyCde +
"', 'MID' : '" + mid +
"', 'sourceSystem' : '" + sourceSystem +
"', 'sequenceNo' : '" + sequenceNo +
"', 'OptInPrintReceipt' : '" + isOptInPrintReceipt +
"', 'OptInSendEReceipt' : '" + isOptInSendEReceipt +
"', 'OptInEReceipt' : '" + isOptInEReceipt +
"', 'OptInPmtAckmnt' : '" + isOptInPmtAckmnt +
"', 'Description' : '" + desc +
"', 'signature' : '" + signature + "'}";
URL url = new URL("https://xxx.finexusgroup.com/fnx-fintech/xxx/mqpos-host/thirdparty/paymentAuthorization");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; utf-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
byte[] input = jsonMessage.getBytes("utf-8");
os.write(input, 0, input.length);
os.close();
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = in.readLine()) != null) {
response.append(responseLine.trim());
}
in.close();
.....
Step 1 : 命名空间
使用命名空间进行 HTTP 请求。
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
Step 2 : 源代码
构建 HTTP 请求主体并将此数据作为 POST 请求发送。
.....
string jsonMessage = $"{{" +
$"\"MsgVer\":\"{msgVer}\"," +
$"\"PmtType\":\"{pmtType}\"," +
$"\"IsPreauthInd\":\"{isPreauthInd}\"," +
$"\"CallerDeviceType\":\"{callerDevice}\"," +
$"\"CallerDeviceVer\":\"{callerDeviceVer}\"," +
$"\"TxnID\":\"{txnID}\"," +
$"\"LocalTxnDTTime\":\"{txnDateTime}\"," +
$"\"Email\":\"{email}\"," +
$"\"DeviceSN\":\"{deviceSN}\"," +
$"\"AmtTxn\":\"{amt}\"," +
$"\"CrcyTxn\":\"{crcyCde}\"," +
$"\"MID\":\"{mid}\"," +
$"\"sourceSystem\":\"{sourceSystem}\"," +
$"\"sequenceNo\":\"{sequenceNo}\"," +
$"\"OptInPrintReceipt\":\"{isOptInPrintReceipt}\"," +
$"\"OptInSendEReceipt\":\"{isOptInSendEReceipt}\"," +
$"\"OptInEReceipt\":\"{isOptInEReceipt}\"," +
$"\"OptInPmtAckmnt\":\"{isOptInPmtAckmnt}\"," +
$"\"Description\":\"{desc}\"," +
$"\"signature\":\"{signature}\"" +
$"}}";
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("https://xxx.finexusgroup.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("fnx-fintech/xxx/mqpos-host/thirdparty/paymentAuthorization", content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
.....
Step 1 : 源代码
构建 HTTP 请求主体并将此数据作为 POST 请求发送。
<?php
.....
$jsonMessage = json_encode([
"MsgVer" => $msgVer,
"PmtType" => $pmtType,
"IsPreauthInd" => $isPreauthInd,
"CallerDeviceType" => $callerDevice,
"CallerDeviceVer" => $callerDeviceVer,
"TxnID" => $txnID,
"LocalTxnDTTime" => $txnDateTime,
"Email" => $email,
"DeviceSN" => $deviceSN,
"AmtTxn" => $amt,
"CrcyTxn" => $crcyCde,
"MID" => $mid,
"sourceSystem" => $sourceSystem,
"sequenceNo" => $sequenceNo,
"OptInPrintReceipt" => $isOptInPrintReceipt,
"OptInSendEReceipt" => $isOptInSendEReceipt,
"OptInEReceipt" => $isOptInEReceipt,
"OptInPmtAckmnt" => $isOptInPmtAckmnt,
"Description" => $desc,
"signature" => $signature
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xxx.finexusgroup.com/fnx-fintech/xxx/mqpos-host/thirdparty/paymentAuthorization");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Accept: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonMessage);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
.....
?>
Step 1 : 导入
导入用于发出 HTTP 请求的库。
import requests
import json
Step 2 : 源代码
构建 HTTP 请求主体并将此数据作为 POST 请求发送。
.....
json_message = {
"MsgVer": msgVer,
"PmtType": pmtType,
"IsPreauthInd": isPreauthInd,
"CallerDeviceType": callerDevice,
"CallerDeviceVer": callerDeviceVer,
"TxnID": txnID,
"LocalTxnDTTime": txnDateTime,
"Email": email,
"DeviceSN": deviceSN,
"AmtTxn": amt,
"CrcyTxn": crcyCde,
"MID": mid,
"sourceSystem": sourceSystem,
"sequenceNo": sequenceNo,
"OptInPrintReceipt": isOptInPrintReceipt,
"OptInSendEReceipt": isOptInSendEReceipt,
"OptInEReceipt": isOptInEReceipt,
"OptInPmtAckmnt": isOptInPmtAckmnt,
"Description": desc,
"signature": signature
}
url = "https://xxx.finexusgroup.com/fnx-fintech/xxx/mqpos-host/thirdparty/paymentAuthorization"
headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
response = requests.post(url, headers=headers, json=json_message)
if response.status_code == 200:
print(response.text)
.....
Step 1 : Install
安装用于发出 HTTP 请求的库。
npm install axios
Step 2 : 源代码
构建 HTTP 请求主体并将此数据作为 POST 请求发送。
.....
const axios = require('axios');
const jsonMessage = {
MsgVer: msgVer,
PmtType: pmtType,
IsPreauthInd: isPreauthInd,
CallerDeviceType: callerDevice,
CallerDeviceVer: callerDeviceVer,
TxnID: txnID,
LocalTxnDTTime: txnDateTime,
Email: email,
DeviceSN: deviceSN,
AmtTxn: amt,
CrcyTxn: crcyCde,
MID: mid,
sourceSystem: sourceSystem,
sequenceNo: sequenceNo,
OptInPrintReceipt: isOptInPrintReceipt,
OptInSendEReceipt: isOptInSendEReceipt,
OptInEReceipt: isOptInEReceipt,
OptInPmtAckmnt: isOptInPmtAckmnt,
Description: desc,
signature: signature
};
// Send the POST request
const url = 'https://xxx.finexusgroup.com/fnx-fintech/xxx/mqpos-host/thirdparty/paymentAuthorization';
axios.post(url, jsonMessage, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(`Error: ${error.response.status} - ${error.response.data}`);
});
.....