当第三方API仅需要生产IP才能与白名单时,如何与Laravel在本地合作?
这样的场景,我将Laravel应用程序部署到Heroku。第三方API需要我的生产IP来使用白名单才能使用其资源。 Heroku不提供IP,我使用添加来获取IP。现在,我的应用程序将确定连接到第三方。问题在于,当我克隆我的应用程序到本地并开始在本地运行和测试时,它会出现错误。 (未定义的索引:主机)我的代码
$testparam = 'q='.$q.'&s='.$s;
$quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
$quotaguard = parse_url($quotaguard_env);
$proxyUrl = $quotaguard['host'].":".$quotaguard['port'];
$proxyAuth = $quotaguard['user'].":".$quotaguard['pass'];
$url = "http://xxxxx.com/api/resource";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_POSTFIELDS,$testparam);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_
decode($json,TRUE);
dd($array);
目前在下面,我必须在编写一两个代码后将文件推到Heroku,以查看结果。有什么方法可以在本地写作和测试吗?
The scenario like this, I deployed my laravel app to heroku. The third-party api needs my production IP for whitelisting in order to use their resources. Heroku doesn't provide ip, I use add on to get ip. It connected ok between my app to third-party now. The problem is that, when I clone my app to local and start to run and test locally, it give error. (Undefined index: host) My code is below
$testparam = 'q='.$q.'&s='.$s;
$quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
$quotaguard = parse_url($quotaguard_env);
$proxyUrl = $quotaguard['host'].":".$quotaguard['port'];
$proxyAuth = $quotaguard['user'].":".$quotaguard['pass'];
$url = "http://xxxxx.com/api/resource";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_POSTFIELDS,$testparam);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_
decode($json,TRUE);
dd($array);
Currently, I have to push my file to heroku after I write one or two lines of code in order to see the result. Is there any way to write and test locally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将QuartAguardStatic_url环境变量设置为“ Quartaguard Admin仪表板”或Heroku的Heroku Config -a AppName命令中的内容。
You need to set the QUOTAGUARDSTATIC_URL environment variable to what is in the QuotaGuard Admin dashboard or in Heroku's heroku config -a APPNAME command.