1

我目前正在使用 instamojo 支付网关。

我有一个相同的付款 ID,并使用以下代码获取付款状态

echo $cUrl = 'https://test.instamojo.com/api/1.1/payments/' . $payment_id;
                     (function_exists('curl_init')) ? '' : die('cURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini');
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $cUrl);
                    curl_setopt($ch, CURLOPT_HEADER, FALSE);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:90a1c44nmb8ac4e65nmnm3eab5b308cf",
                                                               "X-Auth-Token:8164083509a889951fhjhjh1ff89c4"));
                    $response = curl_exec($ch);
                    $error_number = curl_errno($ch);
                    $error_message = curl_error($ch);
                    curl_close($ch);
                    $response_obj = json_decode($response, true);
                    echo "Eror number: $error_number<br />";
                    echo "Eror message: $error_message<br />";
                    print_r($response_obj);

                    if($response_obj['success'] == false) {
                        $message = json_encode($response_obj['message']);
                        return Array('payment' => Array('status' => $message));

                    }
                    if(empty($response_obj) || is_null($response_obj)){
                        return Array('payment' => Array('status' => 'No response from the server.'));
                    }
                    else{
                        return $response_obj;
                    }

但是当我在我的本地主机上运行这段代码时,我得到了正确的结果。

但是当我在我的服务器(即 000webhost.com)上运行它时却出现错误:

Warning:  curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a2963438/public_html/wp-content/plugins/instamojo-register/imojoregister_shortcode.php on line 18

我正在使用 000webhost.com 的免费帐户,所以我无法启用 safe_mode 或编辑任何php.ini.

所以我想问有没有其他方法可以实现这个url的响应?

4

2 回答 2

9

你可能想看看 Guzzle。

http://docs.guzzlephp.org/en/latest/

http://docs.guzzlephp.org/en/latest/quickstart.html

根据他们位于此处的常见问题解答:http ://docs.guzzlephp.org/en/latest/faq.html#does-guzzle-require-curl

Guzzle 需要 cURL 吗?

不可以。Guzzle 可以使用任何 HTTP 处理程序来发送请求。这意味着 Guzzle 可以与 cURL、PHP 的流包装器、套接字和 React 等非阻塞库一起使用。您只需配置一个 HTTP 处理程序以使用不同的发送请求方法。

笔记

Guzzle 过去只使用 cURL 来发送 HTTP 请求。cURL 是一个了不起的 HTTP 客户端(可以说是最好的),当它可用时,Guzzle 将默认继续使用它。这种情况很少见,但一些开发人员没有在他们的系统上安装 cURL 或遇到特定于版本的问题。通过允许可交换的 HTTP 处理程序,Guzzle 现在更加可定制,并且能够适应更多开发人员的需求。

于 2016-11-11T09:37:29.093 回答
1

最好的方法是升级你的服务器,这意味着你可以使用file_get_contents来完成你的事情

于 2016-11-11T09:46:48.910 回答