Home > Backend Development > PHP Tutorial > Detailed explanation of SMS sending examples for PHP version of Alibaba (Alibaba Big Fish)

Detailed explanation of SMS sending examples for PHP version of Alibaba (Alibaba Big Fish)

黄舟
Release: 2023-03-06 06:40:01
Original
2640 people have browsed it

The example of this article describes the implementation method of SMS sending in the PHP version of Alibaba (Alibaba Big Fish). Share it with everyone for your reference, the details are as follows:

General function

// 发送大于短信 更牛逼的
  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;
  }
Copy after login



Optimization

// 发送大于短信 更牛逼的
  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;
  }
Copy after login



There is still a difference between require and include_once here. If you use require and call the method repeatedly, an error will be reported. Fatal error: Cannot redeclare class. Just change it to include_once.

Configuration Template

<?php
return array (
 // 阿里大鱼短信配置
 &#39;dayu_appkey&#39;=>&#39;xxxxxx&#39;,
 &#39;dayu_secretKey&#39;=>&#39;xxxxxxxxxxxxxxxxxxxxx&#39;,
 &#39;dayu_template_register&#39; => array(&#39;signname&#39;=>&#39;注册验证&#39;,&#39;templatecode&#39;=>&#39;SMS_9655457&#39;),
 &#39;dayu_template_alteration&#39; => array(&#39;signname&#39;=>&#39;变更验证&#39;,&#39;templatecode&#39;=>&#39;SMS_9655454&#39;),
 &#39;dayu_template_identity&#39; => array(&#39;signname&#39;=>&#39;身份验证&#39;,&#39;templatecode&#39;=>&#39;SMS_9655461&#39;),
 &#39;dayu_template_sold&#39;=> array(&#39;signname&#39;=>&#39;点多多&#39;,&#39;templatecode&#39;=>&#39;SMS_12800188&#39;),
 &#39;dayu_template_buysuccess&#39;=> array(&#39;signname&#39;=>&#39;点多多&#39;,&#39;templatecode&#39;=>&#39;SMS_12775103&#39;),
 &#39;dayu_template_newagent&#39;=> array(&#39;signname&#39;=>&#39;点多多&#39;,&#39;templatecode&#39;=>&#39;SMS_12815193&#39;),
);
Copy after login



About signature The signature will be displayed in the text message [click a lot], as long as it is an allowed signature, the system or your own Those that pass the review can be mixed.

Detailed explanation of SMS sending examples for PHP version of Alibaba (Alibaba Big Fish)

Detailed explanation of SMS sending examples for PHP version of Alibaba (Alibaba Big Fish)

Detailed explanation of SMS sending examples for PHP version of Alibaba (Alibaba Big Fish)
##Native class


<?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;
  }
}
Copy after login
That’s it PHP version of Alibaba (Alibaba Big Fish) SMS sending example detailed content, for more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template