当前位置: 首页 > 编程笔记 >

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

贺俊楚
2023-03-14
本文向大家介绍php版阿里大于(阿里大鱼)短信发送实例详解,包括了php版阿里大于(阿里大鱼)短信发送实例详解的使用技巧和注意事项,需要的朋友参考一下

本文实例讲述了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程序设计有所帮助。

 类似资料:
  • egg 集成阿里短信验证码 安装Node.js SDK https://help.aliyun.com/document_detail/112185.html?spm=a2c4g.11174283.6.634.36bf2c42lebO4R 阿里控制器 添加签名 添加一个短信模板 生成短信发送NodeJS类 封装阿里生成的类,适用于eggJS [ ] app / service / alisms.j

  • 封装基于eggJS短信发送类 Service 层 'use strict'; // 引入阿里SDK const Core = require('@alicloud/pop-core'); const Service = require('egg').Service; /** * 阿里短信验证码封装类 */ class AlismsService extends Service {

  • 一 :短信配置 1、首先登陆阿里云,没有账号的话先注册一个 2、阿里云首页选择短信服务(如图) 3、选择管理控制台 4、选择消息添加签名 5、打开后台短信配置 6、配置后台短信配置 (1)APP_KEY : (2)SECRET_KEY : (3)短信内容签名 :我们第四步添加(通过审核)签名的名称 (4)阿里云用户 : 新用户 或旧用户(旧用户为已入驻阿里大于短信的用户) 二:短信模板配置(其他短

  • 本文向大家介绍阿里大于短信验证码node koa2的实现代码(最新),包括了阿里大于短信验证码node koa2的实现代码(最新)的使用技巧和注意事项,需要的朋友参考一下 今天给大家分享一下最新版阿里大于的短信验证码在node koa2的实现,还是有很多坑需要注意。 首先需要在阿里云注册账号,并获取阿里云访问秘钥,在控制台完成模板与签名的申请获得调用接口的必备参数。具体方法参见短信发送api 步骤

  • 周二约面 周四电话 人生第一次面试 甚至约面的时候我还问这是什么 面试还是啥 简历不都有吗 为什么要聊一聊(蚌埠住了,现在想想当时好傻) 面试官小哥哥可能看出来我是第一次面试 还一直安慰我不要紧张 整个面试流程体验特别好 一面 1h20mins 自我介绍 项目深挖: 每一步的背景 目的 特征工程的进一步选择 机器学习算法 怎么选择的指标 为什么不选其他指标 (简历写的基本都问了,特别特别深入,不愧

  • 本文向大家介绍laravel框架使用阿里云短信发送消息操作示例,包括了laravel框架使用阿里云短信发送消息操作示例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了laravel框架使用阿里云短信发送消息操作。分享给大家供大家参考,具体如下: 最新需要用到发送短信的功能,所以就在网上搜索一些写好的扩展。 扩展地址: https://github.com/MissMyCat/aliyun-