阿里云短信服务SDK踩坑(php)

我用的php,下载demo和sdk导入项目后,写了一个driver,来驱动这个sdk


部分代码如下


require_once 'api_sdk/vendor/autoload.php';


use Aliyun\Api\Sms\Request\V20170525\QuerySendDetailsRequest;
use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\Regions\EndpointConfig;

//include './api_sdk/vendor/autoload.php';

class MessageDriver{


    function __construct($app_key,$secret_key)
    {
        // 短信API产品名
        $product = "Dysmsapi";

        // 短信API产品域名
        $domain = "dysmsapi.aliyuncs.com";

        // 暂时不支持多Region
        $region = "cn-hangzhou";

        // 服务结点
        $endPointName = "cn-hangzhou";

        // 初始化用户Profile实例
        $profile = DefaultProfile::getProfile($region, $app_key, $secret_key);

        // 手动加载endpoint
        EndpointConfig::load();
        // 增加服务结点
        DefaultProfile::addEndpoint($endPointName, $region, $product, $domain);

        // 初始化AcsClient用于发起请求
        $this->acsClient = new DefaultAcsClient($profile);
    }

执行后总是报错

Can not find endpoint to access.

慢慢debug发现是在 EndpointerProvider里面,没有setEndpoints就直接在demo里面使用了getEndpointers,所以返回为空信息

找一下源代码,发现setEndpoints操作是在EndpointConf中调用的,加载xml中的endpoints


上面贴的代码中已经加入了该行代码

 EndpointConfig::load();

然后另一个坑出现了

Use of undefined constant ENABLE_HTTP_PROXY - assumed 'ENABLE_HTTP_PROXY'


讲道理,阿里云做这个么久了,就不能做个好用点的SDK么,真是操碎了心

看看日志,是代理的问题,在HttpHelper中注释掉下面的代码即可

if(ENABLE_HTTP_PROXY) {
   curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
   curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP);
   curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT);
   curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
}

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值