"", 1=>"SMS_467590542", // 会议通知-个人 1 2=>"SMS_467610225", // 会议审批提醒-提醒领导审批 2 3=>"SMS_467510538", // 会议通知-部门 3 4=>"SMS_467595489", // 通知申请人 4 5=>"SMS_478990217", // 枣泉会议通知-个人 5 6=>"SMS_478610651", // 枣泉会议通知-部门 6 7=>"SMS_479150262", // 枣泉会议通知-个人 7 101=>"SMS_485475245" // 枣泉用印审批 ]; private $sign = "杰唯智能"; public function initModel() { } /** * 使用AK&SK初始化账号Client * @return Dysmsapi Client */ public function createClient(){ // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。 // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html。 $accessKeyId = getconfig('ALIBABA_CLOUD_ACCESS_KEY_ID'); $accessKeySecret = getconfig('ALIBABA_CLOUD_ACCESS_KEY_SECRET'); if (empty($accessKeyId) || empty($accessKeySecret)) { m("log")->addlog("短信错误", "请配置accessKeyId和accessKeySecret"); return null; } $config = new Config([ // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。 "accessKeyId" => $accessKeyId, // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 "accessKeySecret" => $accessKeySecret ]); // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi $config->endpoint = "dysmsapi.aliyuncs.com"; return new Dysmsapi($config); } public function sendBatchSms($phoneArr, $infoArr, $tplCode){ if (empty($phoneArr)||empty($infoArr) || empty($tplCode)) { m("log")->addlog("短信错误", "参数错误"); return; } $client = $this->createClient(); // 签名 for ($i = 0; $i < count($phoneArr); $i++) { $signArr[] = $this->sign; } $dSmsInfo = [ "phoneNumberJson" => json_encode($phoneArr), "signNameJson" => json_encode($signArr), "templateCode" => $this->templateCode[$tplCode], "templateParamJson" => json_encode($infoArr) ]; m('log')->addlog("短信配置", json_encode($dSmsInfo)); $sendBatchSmsRequest = new SendBatchSmsRequest($dSmsInfo); $runtime = new RuntimeOptions([]); try { // 复制代码运行请自行打印 API 的返回值 $res = $client->sendBatchSmsWithOptions($sendBatchSmsRequest, $runtime); if ($res->body->code != 'OK') { m("log")->addlog("短信报错", $res->body->message); } else { m("log")->addlog("短信发送", $res->body->message); } } catch (Exception $error) { m("log")->addlog("短信报错", "错误信息:".$error->message); } } /** * @param string[] $args * @return void */ // public static function test($args){ // $client = self::createClient(); // $sendBatchSmsRequest = new SendBatchSmsRequest([ // "phoneNumberJson" => "[\"15309501557\",\"17701056405\"]", // "signNameJson" => "[\"智慧矿山\", \"智慧矿山\"]", // "templateCode" => "SMS_465319645", // "templateParamJson" => json_encode([["name"=>"张先生","meetdate"=>"2024-04-08", "meetname"=>"周例会", "meetroom"=>"306会议室"], ["name"=>"安全管理部","meetdate"=>"2024-04-08", "meetname"=>"周例会", "meetroom"=>"306会议室"]]) // ]); // $runtime = new RuntimeOptions([]); // try { // // 复制代码运行请自行打印 API 的返回值 // $res = $client->sendBatchSmsWithOptions($sendBatchSmsRequest, $runtime); // if ($res->body->code != 'OK') { // m("log")->addlog("短信报错", $res->body->message); // } else { // m("log")->addlog("短信发送", $res->body->message); // } // } // catch (Exception $error) { // m("log")->addlog("短信报错", "错误信息:".$error->message); // } // } }