相思资源网 Design By www.200059.com
本文实例讲述了php版阿里大于(阿里大鱼)短信发送实现方法。分享给大家供大家参考,具体如下:
通用函数
// 发送大于短信 更牛逼的 protected function sendDayuSmsPlus($tel,$type,$data) { $dayu_template = 'dayu_template_'.$type; $signname = C($dayu_template.".signname"); $templatecode = C($dayu_template.".templatecode"); // require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; include_once LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; $c = new TopClient; $c->appkey = C('dayu_appkey'); $c->secretKey = C('dayu_secretKey'); $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setSmsType("normal"); $req->setSmsFreeSignName("{$signname}"); if ($type == 'sold') { $req->setSmsParam('{"name":"'. $data['name'] .'"}'); } if ($type == 'buysuccess') { $req->setSmsParam('{"name":"'. $data['name'] .'","product":"'. $data['product'] .'"}'); } if ($type == 'newagent') { $req->setSmsParam('{"name":"'. $data['name'] .'"}'); } $req->setRecNum("{$tel}"); $req->setSmsTemplateCode("{$templatecode}"); $resp = $c->execute($req); return $resp; }
优化
// 发送大于短信 更牛逼的 protected function sendDayuSmsPlus($tel,$type,$data) { $dayu_template = 'dayu_template_'.$type; $signname = C($dayu_template.".signname"); $templatecode = C($dayu_template.".templatecode"); // require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; include_once LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; $c = new TopClient; $c->appkey = C('dayu_appkey'); $c->secretKey = C('dayu_secretKey'); $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setSmsType("normal"); $req->setSmsFreeSignName("{$signname}"); switch($type) { case 'sold': $req->setSmsParam('{"name":"'. $data['name'] .'"}'); break; case 'buysuccess': $req->setSmsParam('{"name":"'. $data['name'] .'","product":"'. $data['product'] .'"}'); break; case 'newagent': $req->setSmsParam('{"name":"'. $data['name'] .'"}'); break; default: $req->setSmsParam('{"code":"'. $data['code'] .'","product":"'. $data['product'] .'"}'); } $req->setRecNum("{$tel}"); $req->setSmsTemplateCode("{$templatecode}"); $resp = $c->execute($req); return $resp; }
这里的require 和 include_once 还是有区别的。如果用require,重复调用方法,就会报错。Fatal error: Cannot redeclare class。改成include_once 就可以了。
配置模板
<"//img.jbzj.com/file_images/article/201611/20161130110710985.png" alt="" />原生类
<"key":"value"},key的名字须和申请模板中的变量名一致,多个变量之间以逗号隔开。示例:针对模板“验证码$[code],您正在进行${product}身份验证,打死不要告诉别人哦!”,传参时需传入{"code":"1234","product":"alidayu"} **/ private $smsParam; /** * 短信模板ID,传入的模板必须是在阿里大鱼“管理中心-短信模板管理”中的可用模板。示例:SMS_585014 **/ private $smsTemplateCode; /** * 短信类型,传入值请填写normal **/ private $smsType; private $apiParas = array(); public function setExtend($extend) { $this->extend = $extend; $this->apiParas["extend"] = $extend; } public function getExtend() { return $this->extend; } public function setRecNum($recNum) { $this->recNum = $recNum; $this->apiParas["rec_num"] = $recNum; } public function getRecNum() { return $this->recNum; } public function setSmsFreeSignName($smsFreeSignName) { $this->smsFreeSignName = $smsFreeSignName; $this->apiParas["sms_free_sign_name"] = $smsFreeSignName; } public function getSmsFreeSignName() { return $this->smsFreeSignName; } public function setSmsParam($smsParam) { $this->smsParam = $smsParam; $this->apiParas["sms_param"] = $smsParam; } public function getSmsParam() { return $this->smsParam; } public function setSmsTemplateCode($smsTemplateCode) { $this->smsTemplateCode = $smsTemplateCode; $this->apiParas["sms_template_code"] = $smsTemplateCode; } public function getSmsTemplateCode() { return $this->smsTemplateCode; } public function setSmsType($smsType) { $this->smsType = $smsType; $this->apiParas["sms_type"] = $smsType; } public function getSmsType() { return $this->smsType; } public function getApiMethodName() { return "alibaba.aliqin.fc.sms.num.send"; } public function getApiParas() { return $this->apiParas; } public function check() { RequestCheckUtil::checkNotNull($this->recNum,"recNum"); RequestCheckUtil::checkNotNull($this->smsFreeSignName,"smsFreeSignName"); RequestCheckUtil::checkNotNull($this->smsTemplateCode,"smsTemplateCode"); RequestCheckUtil::checkNotNull($this->smsType,"smsType"); } public function putOtherTextParam($key, $value) { $this->apiParas[$key] = $value; $this->$key = $value; } }更多关于PHP相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无php版阿里大于(阿里大鱼)短信发送实例详解的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。