当第三方API仅需要生产IP才能与白名单时,如何与Laravel在本地合作?

发布于 2025-02-12 22:40:03 字数 1264 浏览 2 评论 0原文

这样的场景,我将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城月光淡如水﹏ 2025-02-19 22:40:03

您需要将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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文