阿里云短信服务SDK踩坑(php)
2017-07-25 14:27
645 查看
我用的php,下载demo和sdk导入项目后,写了一个driver,来驱动这个sdk
部分代码如下
执行后总是报错
Can not find endpoint to access.
慢慢debug发现是在 EndpointerProvider里面,没有setEndpoints就直接在demo里面使用了getEndpointers,所以返回为空信息
找一下源代码,发现setEndpoints操作是在EndpointConf中调用的,加载xml中的endpoints
上面贴的代码中已经加入了该行代码
然后另一个坑出现了
Use of undefined constant ENABLE_HTTP_PROXY - assumed 'ENABLE_HTTP_PROXY'
讲道理,阿里云做这个么久了,就不能做个好用点的SDK么,真是操碎了心
看看日志,是代理的问题,在HttpHelper中注释掉下面的代码即可
部分代码如下
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); }
相关文章推荐
- 阿里大于(alidayu)升级为阿里云短信服务(dysms)Golang新版SDK
- 阿里云PHP-SMS短信服务——验证码发送教程
- 阿里云直播服务 sdk demo php
- php 阿里云短信服务及阿里大于实现短信验证码的发送
- 阿里云PHP SMS短信服务验证码发送方法
- php 阿里云短信服务及阿里大鱼实现短信验证码的发送
- PHP开发阿里云短信服务接口
- 精简阿里云短信服务官方SDK及DEMO
- 阿里云PHP-SMS短信服务——验证码发送教程
- PHP阿里云短信服务
- 阿里云短信服务 nodejs版本SDK,非阿里大鱼
- 基于PHP的阿里云短信发送服务。防坑!!!
- 阿里云短信服务API服务调用SendSMSUtil
- 阿里云视频服务SDK
- Springboot实现阿里云通信短信服务有关短信验证码的发送
- 【阿里云产品公测】消息队列服务MQS java SDK 机器人应用初体验
- OSSC 0.1.6 发布,阿里云存储服务的C SDK
- ThinkPHP5 集成阿里云SMS短信服务--验证码发送
- Springboot实现阿里云通信短信服务有关短信验证码的发送
- 阿里云短信服务