* @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; } } }