php版阿里大于(阿里大鱼)短信发送实例详解
程序员文章站
2024-04-01 22:28:34
本文实例讲述了php版阿里大于(阿里大鱼)短信发送实现方法。分享给大家供大家参考,具体如下:
通用函数
// 发送大于短信 更牛逼的
protected...
本文实例讲述了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 就可以了。
配置模板
<?php return array ( // 阿里大鱼短信配置 'dayu_appkey'=>'xxxxxx', 'dayu_secretkey'=>'xxxxxxxxxxxxxxxxxxxxx', 'dayu_template_register' => array('signname'=>'注册验证','templatecode'=>'sms_9655457'), 'dayu_template_alteration' => array('signname'=>'变更验证','templatecode'=>'sms_9655454'), 'dayu_template_identity' => array('signname'=>'身份验证','templatecode'=>'sms_9655461'), 'dayu_template_sold'=> array('signname'=>'点多多','templatecode'=>'sms_12800188'), 'dayu_template_buysuccess'=> array('signname'=>'点多多','templatecode'=>'sms_12775103'), 'dayu_template_newagent'=> array('signname'=>'点多多','templatecode'=>'sms_12815193'), );
关于签名签名会显示在短信中【点多多】,只要是允许的签名,系统的或者自己审核通过的,可以混用。
原生类
<?php /** * top api: alibaba.aliqin.fc.sms.num.send request * * @author auto create * @since 1.0, 2015.12.02 */ class alibabaaliqinfcsmsnumsendrequest { /** * 公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员id,在消息返回时,该会员id会包含在内,用户可以根据该会员id识别是哪位会员使用了你的应用 **/ private $extend; /** * 短信接收号码。支持单个或多个手机号码,传入号码为11位手机号码,不能加0或+86。群发短信需传入多个号码,以英文逗号分隔,一次调用最多传入200个号码。示例:18600000000,13911111111,13322222222 **/ private $recnum; /** * 短信签名,传入的短信签名必须是在阿里大鱼“管理中心-短信签名管理”中的可用签名。如“阿里大鱼”已在短信签名管理中通过审核,则可传入”阿里大鱼“(传参时去掉引号)作为短信签名。短信效果示例:【阿里大鱼】欢迎使用阿里大鱼服务。 **/ private $smsfreesignname; /** * 短信模板变量,传参规则{"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程序设计有所帮助。