如何将这个java变量传递到php页面?

eqqqjvef  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(203)

这是一个restapi-hmac签名密钥生成器,我试了很多次把它传递给php页面。有什么帮助吗?
进程.html

public static String signingkey(String apiAccessKey, String hmacSecretKey, String apiMethod, String clientip, String jsonInput) {
String retval = "";
final String HMAC_SHA_512_ALGORITHM = "HmacSHA512";
final String userKey = apiAccessKey + hmacSecretKey;
try {
// get an hmac_sha512 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(userKey.getBytes(), HMAC_SHA_512_ALGORITHM);
// get an hmac_sha512 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance(HMAC_SHA_512_ALGORITHM);
mac.init(signingKey);
// compute the hmac on input data bytes
String payload = (apiMethod.toUpperCase()).concat(clientip).concat(jsonInput);
byte[] rawHmac = mac.doFinal(payload.getBytes());
// the value of hmac needs to placed in headers under the key api-hmac
return Hex.encodeHexString(rawHmac);
document.location = 'apirequest.php?signing_key=' + rawHmac;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

这是我迄今为止尝试过的。我对这些还不熟悉。
下面的代码必须获得该签名密钥。如何做到这一点
apirequest.php文件

<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "http://10.11.3.47/portalws2/api/gateway/ehospitalapi?hosId=5",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

curl_setopt($curl, CURLOPT_HTTPHEADER, [
        "cache-control: no-cache",
        "TOKEN: c33e744948a077a4924eaf64ff81e140",
        "api-hmac: RhQkf+K8WgaoQaYqBD7R8Ghmmifdmycwql+FCpHHhr1X7IoJsnQmo1GWlTuM7BDf",
"signing_key:xxxxxxxxxxxxx",
        "api_identifier: 12",
         "sender_id: 52"

]);

$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);

if ($error) {
        echo "cURL error #:" . $error;
} else {
        echo $response;
}

?>

连接部分我感到困难。谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题