123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- /**
- * Alidayu.php UTF-8
- * 阿里大鱼短信
- *
- * @date : 2018/4/23 17:32
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- * https://doc.alidayu.com/docs/doc.htm?spm=a3142.7629140.4.9.E36pdC&treeId=1&articleId=101617&docType=1
- */
- namespace huolib\sms\driver;
- use huolib\sms\SmsType;
- use huolib\status\MemberStatus;
- use think\Log;
- class Alidayu {
- protected $config
- = [
- 'APPKEY' => '',
- 'APPSECRET' => '',
- 'PRODUCT' => '',
- 'SMSTEMPAUTH' => '', //系统身份验证验证码
- 'SMSTEMPTEST' => '', //系统短信测试
- 'SMSTEMPLOGIN' => '', //系统登录确认验证码
- 'SMSTEMPLOGINERROR' => '', //系统登录异常验证码
- 'SMSTEMPREG' => '', //系统用户注册验证码
- 'SMSTEMPACT' => '', //系统活动确认验证码
- 'SMSTEMPPWDMOD' => '', //系统修改密码验证码
- 'SMSTEMPINFOMOD' => '', //系统信息变更验证码
- "SETEXTEND" => "", //setExtend
- "SMSTYPE" => "",//SmsType
- "SMSFREESIGNNAME" => "",//SmsFreeSignName
- ];
- public function __construct() {
- if (file_exists(GLOBAL_CONF_PATH."extra/sms/alidayu.php")) {
- $_config = include GLOBAL_CONF_PATH."extra/sms/alidayu.php";
- } else {
- $_config = array();
- }
- $this->config = array_merge($this->config, $_config);
- }
- /**
- * 标准返回
- *
- * @param $code
- *
- * @return mixed
- */
- private function getReturnByCode($code) {
- $_rdata['code'] = $code;
- $_rdata['msg'] = MemberStatus::getMsg($code);
- return $_rdata;
- }
- public function send($mobile, $type, $sms_code) {
- include EXTEND_PATH."taobao/TopSdk.php";
- include EXTEND_PATH."taobao/top/TopClient.php";
- include EXTEND_PATH."taobao/top/request/AlibabaAliqinFcSmsNumSendRequest.php";
- if (empty($this->config['APPKEY'])) {
- Log::write("func=".__FUNCTION__."&class=".__CLASS__." config error", LOG::ERROR);
- return MemberStatus::CONFIG_ERROR;
- }
- $_content = array(
- "code" => ''.$sms_code,
- "product" => ''.$this->config['PRODUCT']
- );
- switch ($type) {
- case SmsType::SMS_REG:
- {
- $_template_code = $this->config['SMSTEMPREG'];
- break;
- }
- case SmsType::SMS_LOGIN:
- {
- $_template_code = $this->config['SMSTEMPLOGIN'];
- break;
- }
- case SmsType::SMS_MODIFY:
- {
- $_template_code = $this->config['SMSTEMPPWDMOD'];
- break;
- }
- case SmsType::SMS_ID_VERIFY:
- {
- $_template_code = $this->config['SMSTEMPAUTH'];
- break;
- }
- case SmsType::SMS_FIND_PWD:
- {
- $_template_code = $this->config['SMSTEMPINFOMOD'];
- break;
- }
- case SmsType::SMS_BIND:
- {
- $_template_code = $this->config['SMSTEMPINFOMOD'];
- break;
- }
- case SmsType::SMS_OTHER:
- {
- $_template_code = $this->config['SMSTEMPACT'];
- break;
- }
- default:
- {
- $_template_code = $this->config['SMSTEMPTEST'];
- break;
- }
- }
- $_c = new \TopClient();
- $_c->appkey = $this->config['APPKEY'];
- $_c->secretKey = $this->config['APPSECRET'];
- $_req = new \AlibabaAliqinFcSmsNumSendRequest();
- $_req->setExtend($this->config['SETEXTEND']);
- $_req->setSmsType($this->config['SMSTYPE']);
- $_req->setSmsFreeSignName($this->config['SMSFREESIGNNAME']);
- $_req->setSmsParam(json_encode($_content));
- $_req->setRecNum($mobile);
- $_req->setSmsTemplateCode($_template_code);
- $_resp = $_c->execute($_req);
- $_resp = (array)$_resp;
- if (!empty($_resp['result'])) {
- return MemberStatus::NO_ERROR;
- } else {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&mobile=".$mobile."&type=".$type."&return_msg=.".json_encode(
- $_resp
- ), LOG::ERROR
- );
- return MemberStatus::PHONE_SEND_ERROR;
- }
- }
- }
|