【问题标题】:PHP Walgreens API curl issue using WAMP (windows)?使用 WAMP(Windows)的 PHP Walgreens API curl 问题?
【发布时间】:2014-04-10 03:24:43
【问题描述】:

大家好,我正在运行我自己的 PHP 服务器(通过 WAMP)并使用提供的 Walgreens API PHP 示例来测试上传的照片。

以下是我的一些似乎停止的代码:

$affiliateId = "xxxxx";
$apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$apiEndPoint = "https://services-qa.walgreens.com/api/util/mweb5url";
$cred_data = array(
                "serviceType"=>"wagS3",
                "act"=>"genCredV2",
                "view"=>"genCredV2JSON",
                "affId"=> $affiliateId,
                "apiKey"=>$apiKey,
                "devinf"=>"IE,11",
                "appver"=>"0.01"
              );

$cred_data=json_encode($cred_data);
echo "<br/>Credential Request = ",$cred_data;
$headers = array('Content-type: application/json; charset=utf-8');
$curl = curl_init($apiEndPoint);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $cred_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$cred_response = curl_exec($curl);
echo "<br/>Credential Response = ",$cred_response,"<br/>";
$cred_response = json_decode($cred_response,TRUE);
curl_close($curl);

当我将它放到由托管公司托管的另一台服务器上并运行 php 文件时,它工作得很好(给出 echo "Credential Response = ",$cred_response,""; 一个实际的响应。)。

但是,当我在本地机器上运行代码时,它没有返回任何响应,例如被阻止或其他什么?

我从另一台服务器得到的响应是:

Credential Request = {"serviceType":"wagS3","act":"genCredV2","view":"genCredV2JSON","affId":"xxxxx","apiKey":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx","xxxxxx":"IE,11","appver":"0.01"}
Credential Response = {"uploadUrl":"http://xxxxxxxxxxxxx.com","secretKey":"xxxxxxxxxxxxxxxxxxxx","sessionId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","err":"","accessKeyId":"xxxxxxxxxxxxxxxxxxxxxxxx"}

我从本地服务器得到的响应是:

Credential Request = {"serviceType":"wagS3","act":"genCredV2","view":"genCredV2JSON","affId":"xxxxx","apiKey":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx","xxxxxx":"IE,11","appver":"0.01"}
Credential Response = 

我的 Apache 和/或 PHP 文件中是否缺少设置或插件?

【问题讨论】:

    标签: php api curl wamp wampserver


    【解决方案1】:

    我遇到过这样的问题,问题是 WALGreen 服务器找不到localhost,而且当它看到该域时可能甚至都懒得找。

    如果您设置了动态 DNS 服务,以便可以使用实际域名找到您的 PC(更确切地说是路由器),即使域名名称有点奇怪,它也会开始工作。

    不要忘记将您路由器上的 80 端口转发到运行 WAMP 的 PC 的 ip。 在您的本地 Apache 上创建一个虚拟主机也是一个好主意,以便域名(即动态 dns 名称和内部域名匹配)。

    【讨论】:

      【解决方案2】:

      正确答案是您必须拥有由 walgreens 团队设置的会员 ID 和 apikey。 所以这是无效的:

      $affiliateId = "xxxxx";
      $apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
      

      必须是这样的:

      $affiliateId = "extest1";
      $apiKey = "BLAHBLAHBLAHBLAH";
      

      根据开发者门户上的文档,您必须注册一个帐户才能创建 APIkey (https://developer.walgreens.com/user/register)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-06
        • 2018-07-26
        • 1970-01-01
        • 2012-06-11
        • 1970-01-01
        • 1970-01-01
        • 2011-11-07
        相关资源
        最近更新 更多