首页 > 开发 > PHP > 正文

php版阿里大于(阿里大鱼)短信发送实例详解

2024-05-04 22:50:36
字体:
来源:转载
供稿:网友

本文实例讲述了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 就可以了。

配置模板

<?phpreturn 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'),);            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表