本文实例讲述了PHP版阿里大于(阿里大鱼)短信发送实现方法。分享给大家供大家参考,具体如下:
通用函数
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;
}
优化
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;">
'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;">
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程序设计有所帮助。