CI = & get_instance(); $this->CI->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file')); $this->setting = $this->CI->cache->get('setting'); } /** * 取得AcsClient * * @return DefaultAcsClient */ private function getAcsClient() { //产品名称:云通信流量服务API产品,开发者无需替换 $product = "Dysmsapi"; //产品域名,开发者无需替换 $domain = "dysmsapi.aliyuncs.com"; $accessKeyId = $this->setting['access_key_id']; // AccessKeyId $accessKeySecret = $this->setting['access_key_secret'];; // AccessKeySecret // 暂时不支持多Region $region = "cn-hangzhou"; // 服务结点 $endPointName = "cn-hangzhou"; if(static::$acsClient == null) { //初始化acsClient,暂不支持region化 $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret); // 增加服务结点 DefaultProfile::addEndpoint($endPointName, $region, $product, $domain); // 初始化AcsClient用于发起请求 static::$acsClient = new DefaultAcsClient($profile); } return static::$acsClient; } /** * 发送短信 * @return stdClass */ public function sendSms($phone,$template_code,$content) { if(is_array($content)){ // 初始化SendSmsRequest实例用于设置发送短信的参数 $request = new SendSmsRequest(); //可选-启用https协议 //$request->setProtocol("https"); // 必填,设置短信接收号码 $request->setPhoneNumbers($phone); // 必填,设置签名名称,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign $request->setSignName($this->setting['sign_name']); // 必填,设置模板CODE,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template $request->setTemplateCode($template_code); // 可选,设置模板参数, 假如模板中存在变量需要替换则为必填项 $request->setTemplateParam(json_encode($content), JSON_UNESCAPED_UNICODE); // 发起访问请求 $acsResponse = $this->getAcsClient()->getAcsResponse($request); return (array)$acsResponse; }else{ return array("Code"=>0,"msg"=>"参数错误"); } } }