我使用PHP的CURL连接到API。地址或$ url是我需要帮助的。目前我有一个脚本,当用户提交投资表格时会运行该脚本,然后创建一个" InvestmentID"
此投资ID是JSON对象的一部分,我可以在其中获取投资金额等项目。
目前我的代码可以在表单提交时使用CURL连接到API,但我无法理解的是如何传递" InvestmentID"到$ URL字符串的末尾,例如
$ url =' https://sandbox.fundamerica.com/api/investments/' 。 $ outputtedID;
对于我已经处理了几个小时的重复代码感到抱歉并且意识到它需要一些健康的整理,一旦我弄清楚了,我会做的。
我真的希望这是有道理的。请在下面找到我的代码。
<script>
document.addEventListener('fa.investnow.success', function(e){
var InvestorInvestmentID = e.investment_id;
<?php
$url = 'https://sandbox.fundamerica.com/api/investments/';
$username = 'c7YU_vDAQmPrLkHCw6ydXRYKcrviev7U';
$password = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//echo $output ;
?>
var investmentReturn =
<?php echo $output; ?>;
console.log(investmentReturn);
console.log(InvestorInvestmentID);
});
function doSomethingWithInvestmentId(InvestorInvestmentID){
console.log(InvestorInvestmentID);
<?php
$url = 'https://sandbox.fundamerica.com/api/investments/';
$username = 'c7YU_vDAQmPrLkHCw6ydXRYKcrviev7U';
$password = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//echo $output ;
?>
var investmentReturn =
<?php echo $output; ?>;
console.log(investmentReturn);
};
</script>
由于
答案 0 :(得分:0)
在我看来,最好的解决方案是创建separete JS和PHP文件。
所以你得到你的身份
a = np.ones((1100000, 800), dtype="float64") # just a few more column
b = np.log10(a[:, 0]) # 6 min 20 sec
然后使用jQuery调用
document.addEventListener('fa.investnow.success', function(e){
var InvestorInvestmentID = e.investment_id;
}
$.get( "test.php?id=" + InvestorInvestmentID );
id的PHP文件并在外部资源上执行API调用。$_GET