singleSmsByAli()阿里短信发送函数 * * * * * ~~~ /** * @param $mid * @param $PhoneNumbers 必填: 短信接收号码 * @param $SignName 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign * @param $TemplateCode 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template * @param array $TemplateParam 必填: 设置模板参数, 假如模板中存在变量需要替换则为必填项 * @param string $OutId 可选: 设置发送短信流水号 * @param string $SmsUpExtendCode 可选: 上行短信扩展码, 扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段 * @return bool|mixed|stdClass|string */ function singleSmsByAli($mid, $PhoneNumbers, $SignName, $TemplateCode, $TemplateParam = [], $OutId = '', $SmsUpExtendCode = '') { include_once EXTEND_PATH . 'aliyunSms/SignatureHelper.php'; if (!$conf = getSetting($mid, 'sms')) { return false;//没有配置信息参数 } $accessKeyId = isset($conf['alisms']['appid']) ? $conf['alisms']['appid'] : ''; $accessKeySecret = isset($conf['alisms']['appsecret']) ? $conf['alisms']['appsecret'] : ''; $helper = new \Aliyun\DySDKLite\SignatureHelper(); $params = array(); $params["PhoneNumbers"] = $PhoneNumbers; $params["SignName"] = $SignName; $params["TemplateCode"] = $TemplateCode; $params['TemplateParam'] = $TemplateParam; $params['OutId'] = $OutId; $params['SmsUpExtendCode'] = $SmsUpExtendCode; if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) { $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE); } $content = $helper->request( $accessKeyId, $accessKeySecret, "dysmsapi.aliyuncs.com", array_merge($params, array( "RegionId" => "cn-hangzhou", "Action" => "SendSms", "Version" => "2017-05-25", )) // fixme 选填: 启用https // ,true ); $result = $helper->getErrCode($content->Code); if ($result == false) { return false; } else { return $result; } } ~~~