阿里云短信服务SDK 遇到的坑

今天在接一个阿里云的短信时,一直报错 Can not find endpoint to access.

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

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

所以在他的DEMO代码中加入

// 手动加载endpoint
EndpointConfig::load();
如下:
    /**
     * 取得AcsClient
     *
     * @return DefaultAcsClient
     */
    public function getAcsClient() {
        //产品名称:云通信流量服务API产品,开发者无需替换
        $product = "Dysmsapi";
        //产品域名,开发者无需替换
        $domain = "dysmsapi.aliyuncs.com";
        // TODO 此处需要替换成开发者自己的AK (https://ak-console.aliyun.com/)
        $accessKeyId = "LTAIqp9OkHSLOjqy"; // AccessKeyId
        $accessKeySecret = "LAUldiI0aukzJau4o9qDg9GylG1Psi"; // AccessKeySecret
        // 暂时不支持多Region
        $region = "cn-hangzhou";
        // 服务结点
        $endPointName = "cn-hangzhou";

        if($acsClient == null) {
            //初始化acsClient,暂不支持region化
            $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
			
			
			// 手动加载endpoint
			EndpointConfig::load();

			
            // 增加服务结点
            DefaultProfile::addEndpoint($endPointName, $region, $product, $domain);

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

然后另一个坑出现了,有可能会出下以下一种报错

Use of undefined constant ENABLE_HTTP_PROXY - assumed 'ENABLE_HTTP_PROXY'

Server unreachable: Errno: 5 Could not resolve proxy: HTTP_PROXY_IP

是代理的问题,在HttpHelper中注释掉下面的代码即可,文件\Core\Http\HttpHelper.php   大概15行

//注释下面
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);
}

 

 我也是服了,阿里那么大个平台,一个短信服务做的这么复杂,阿里也不看看人家聚合的是多么方便 

posted @ 2017-11-17 15:55  智昕  阅读(10446)  评论(1编辑  收藏  举报