跳到主要内容

嵌入代码

Step 1 : 导入

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

Step 2 : 源代码

.....

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();

.....