今天在接一個阿里雲的短信時,一直報錯 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); }
我也是服了,阿里那么大個平台,一個短信服務做的這么復雜,阿里也不看看人家聚合的是多么方便