### Configure and Send SMS with Qiniu Cloud using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet details the setup for Qiniu Cloud provider credentials (secret_key, access_key) and demonstrates sending a templated SMS with a single data parameter using EasySms. ```php 'qiniu' => [ 'secret_key' => '', 'access_key' => '', ], ``` ```php $easySms->send(18888888888, [ 'template' => '1231234123412341234', 'data' => [ 'code' => 1234, ], ]); ``` -------------------------------- ### Configure and Send SMS with Maap using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet provides the configuration for Maap provider credentials (cpcode, key, excode) and an example of sending a templated SMS with a single positional data parameter using EasySms. ```php 'maap' => [ 'cpcode' => '', //必填 商户编码 'key' => '', //必填 接口密钥 'excode'=> '', //选填 扩展名 ], ``` ```php $easySms->send(18888888888, [ 'template' => '356120', //短信模板 'data' => [ '123465' ],//模板参数 ]); ``` -------------------------------- ### Configure and Send SMS with Rongheyun (Zhutong) using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet provides the configuration for Rongheyun provider credentials (username, password, signature) and an example of sending a templated SMS with a named data parameter using EasySms. ```php 'rongheyun' => [ 'username' => '', //必填 用户名 'password' => '', //必填 密码 'signature'=> '', //必填 已报备的签名 ], ``` ```php $easySms->send(18888888888, [ 'template' => '31874', //短信模板 'data' => [ 'valid_code' => '888888', //模板参数,对应模板的{valid_code} //... ], ]); ``` -------------------------------- ### Configure and Send SMS with Ucloud using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet provides the configuration for Ucloud provider credentials (private_key, public_key, sig_content, project_id) and an example of sending a templated SMS. It shows how to pass single or multiple parameters and mobile numbers. ```php 'ucloud' => [ 'private_key' => '', //私钥 'public_key' => '', //公钥 'sig_content' => '', // 短信签名, 'project_id' => '', //项目ID,子账号才需要该参数 ], ``` ```php $easySms->send(18888888888, [ 'template' => 'UTAXXXXX', //短信模板 'data' => [ 'code' => 1234, //模板参数,模板没有参数不用则填写,有多个参数请用数组,[1111,1111] 'mobiles' =>'', //同时发送多个手机短信,请用数组[xxx,xxx] ], ]); ``` -------------------------------- ### PHP: Configure and register a custom EasySms gateway Source: https://github.com/overtrue/easy-sms/blob/master/README.md This example demonstrates how to integrate a custom SMS gateway into EasySms. It involves updating the configuration to include the custom gateway in the default list and defining its parameters, then registering the gateway using the `extend` method with a factory function. ```php $config = [ ... 'default' => [ 'gateways' => [ 'mygateway', // 配置你的网站到可用的网关列表 ], ], 'gateways' => [ 'mygateway' => [...], // 你网关所需要的参数,如果没有可以不配置 ], ]; $easySms = new EasySms($config); // 注册 $easySms->extend('mygateway', function($gatewayConfig){ // $gatewayConfig 来自配置文件里的 `gateways.mygateway` return new MyGateway($gatewayConfig); }); $easySms->send(13188888888, [ 'content' => '您的验证码为: 6379', 'template' => 'SMS_001', 'data' => [ 'code' => 6379 ], ]); ``` -------------------------------- ### Send SMS via Ctyun using Content, Template, and Data Source: https://github.com/overtrue/easy-sms/blob/master/README.md This example demonstrates sending an SMS message through Ctyun using the EasySms `send` method. It combines direct `content` with a `template` ID and a `data` array for template variables, such as a verification `code`. This allows for flexible message construction. ```php $easySms->send(18888888888, [ 'content' => $content, 'template' => 'SMS64124870510', // 模板ID 'data' => [ "code" => 123456, ], ]); ``` -------------------------------- ### Send SMS via Volcengine using Template and Data Source: https://github.com/overtrue/easy-sms/blob/master/README.md This example demonstrates sending an SMS message through Volcengine using the EasySms `send` method. It requires a recipient phone number, a `template` ID, and a `data` array containing variables that correspond to the template placeholders, such as a verification `code`. ```php $easySms->send(18888888888, [ 'template' => 'SMS_123456', // 模板ID 'data' => [ "code" => 1234 // 模板变量 ], ]); ``` -------------------------------- ### PHP: Send international SMS via Aliyun International Source: https://github.com/overtrue/easy-sms/blob/master/README.md Example of sending an international SMS using the Aliyun International gateway. It demonstrates using the `PhoneNumber` class with a country code and providing `content`, `template`, and `data` for the message. ```php use Overtrue\EasySms\PhoneNumber; $easySms = new EasySms($config); $phone_number = new PhoneNumber(18888888888, 86); $easySms->send($phone_number, [ 'content' => '您好:先生/女士!您的验证码为${code},有效时间是5分钟,请及时验证。', 'template' => 'SMS_00000001', // 模板ID 'data' => [ "code" => 521410, ], ]); ``` -------------------------------- ### Send SMS via Yidongmasblack using Direct Content Source: https://github.com/overtrue/easy-sms/blob/master/README.md This example shows how to send a simple SMS message through Yidongmasblack using the EasySms `send` method. It directly provides the message `content` without requiring a template, suitable for plain text messages like verification codes. ```php $easySms->send(18888888888, [ 'content' => '您的验证码为: 6379', ]); ``` -------------------------------- ### Send SMS via Volcengine with Advanced Data Options Source: https://github.com/overtrue/easy-sms/blob/master/README.md This example illustrates an advanced SMS sending scenario with Volcengine, allowing overrides for configuration parameters. It uses a `template` ID and a `data` array that includes `template_param` for variables, `sign_name` to override the default signature, `sms_account` to override the message group account, and `phone_numbers` for batch sending, overriding the primary recipient. ```php $easySms->send(18888888888, [ 'template' => 'SMS_123456', // 模板ID 'data' => [ "template_param" => ["code" => 1234], // 模板变量参数 "sign_name" => "yoursignname", // 签名,覆盖配置文件中的sign_name "sms_account" => "yoursmsaccount", // 消息组帐号,覆盖配置文件中的sms_account "phone_numbers" => "18888888888,18888888889", // 手机号,批量发送,英文的逗号连接多个手机号,覆盖发送方法中的填入的手机号 ], ]); ``` -------------------------------- ### Configure and Send SMS with Smsbao using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet outlines the configuration for Smsbao provider credentials (user, password) and demonstrates sending a simple content-based SMS via the EasySms library. ```php 'smsbao' => [ 'user' => '', //账号 'password' => '' //密码 ], ``` ```php 'smsbao' => [ 'user' => '', //账号 'password' => '' //密码 ], ``` -------------------------------- ### Configure and Send SMS with Yunzhixun using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet shows how to configure Yunzhixun provider credentials (sid, token, app_id) and send an SMS using the EasySms library. It demonstrates sending a templated message with multiple parameters, including support for batch sending. ```php 'yunzhixun' => [ 'sid' => '', 'token' => '', 'app_id' => '', ], ``` ```php $easySms->send(18888888888, [ 'template' => 'SMS_001', 'data' => [ 'params' => '8946,3', // 模板参数,多个参数使用 `,` 分割,模板无参数时可为空 'uid' => 'hexianghui', // 用户 ID,随状态报告返回,可为空 'mobiles' => '18888888888,188888888889', // 批量发送短信,手机号使用 `,` 分割,不使用批量发送请不要设置该参数 ], ]); ``` -------------------------------- ### Configure and Send SMS with Kingtto using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet illustrates the configuration of Kingtto provider credentials (userid, account, password) and sending a simple content-based SMS via the EasySms library. ```php 'kingtto' => [ 'userid' => '', 'account' => '', 'password' => '', ], ``` ```php $easySms->send(18888888888, [ 'content' => '您的验证码为: 6379', ]); ``` -------------------------------- ### APIDOC: AliyunRest SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the AliyunRest SMS gateway. It requires `app_key`, `app_secret_key`, and `sign_name`. SMS content is sent using `template` and `data` parameters. ```APIDOC aliyunrest: app_key: string app_secret_key: string sign_name: string ``` -------------------------------- ### Configure and Send SMS with Nowcn using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet illustrates the configuration of Nowcn provider credentials (key, secret, api_type) and sending a simple content-based SMS via the EasySms library. ```php 'nowcn' => [ 'key' => '', //用户ID 'secret' => '', //开发密钥 'api_type' => '', // 短信通道, ], ``` ```php $easySms->send(18888888888, [ 'content' => '您的验证码为: 6379', ]); ``` -------------------------------- ### APIDOC: Luosimao SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Luosimao SMS gateway. It requires `api_key`. SMS content is sent using the `content` parameter. ```APIDOC luosimao: api_key: string ``` -------------------------------- ### Configure and Send SMS with Zzyun using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet details the configuration for Zzyun provider credentials (user_id, secret, sign_name) and shows how to send a templated SMS with a named data parameter using EasySms. ```php 'zzyun' => [ 'user_id' => '', //必填 会员ID 'secret' => '', //必填 接口密钥 'sign_name'=> '', //必填 短信签名 ], ``` ```php $easySms->send(18888888888, [ 'template' => 'SMS_210317****', //短信模板 'data' => [ 'code' => '888888', //模板参数,对应模板的{code} //... ], ]); ``` -------------------------------- ### APIDOC: Aliyun SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Aliyun SMS gateway. It requires `access_key_id`, `access_key_secret`, and `sign_name`. SMS content is sent using `template` and `data` parameters. ```APIDOC aliyun: access_key_id: string access_key_secret: string sign_name: string ``` -------------------------------- ### APIDOC: Yuntongxun SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Yuntongxun SMS gateway. It requires `app_id`, `account_sid`, `account_token`, and `is_sub_account`. SMS content is sent using `template` and `data` parameters. ```APIDOC yuntongxun: app_id: string account_sid: string account_token: string is_sub_account: boolean ``` -------------------------------- ### Configure Volcengine SMS Provider for EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This PHP configuration array defines the necessary parameters for integrating Volcengine SMS with EasySms. It includes `access_key_id`, `access_key_secret`, `region_id` (specifying domestic or international nodes), `sign_name` (SMS signature), and `sms_account` (message group account). `sign_name` and `sms_account` can be optionally overridden during message sending. ```php 'volcengine' => [ 'access_key_id' => '', // 平台分配给用户的access_key_id 'access_key_secret' => '', // 平台分配给用户的access_key_secret 'region_id' => 'cn-north-1', // 国内节点 cn-north-1,国外节点 ap-singapore-1,不填或填错,默认使用国内节点 'sign_name' => '', // 平台上申请的接口短信签名或者签名ID,可不填,发送短信时data中指定 'sms_account' => '', // 消息组帐号,火山短信页面右上角,短信应用括号中的字符串,可不填,发送短信时data中指定 ], ``` -------------------------------- ### Configure and Send SMS with Moduyun using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet details the configuration for Moduyun provider credentials (accesskey, secretkey, signId, type) and shows how to send a templated SMS with multiple positional data parameters using EasySms. ```php 'moduyun' => [ 'accesskey' => '', //必填 ACCESS KEY 'secretkey' => '', //必填 SECRET KEY 'signId' => '', //选填 短信签名,如果使用默认签名,该字段可缺省 'type' => 0, //选填 0:普通短信;1:营销短信 ], ``` ```php $easySms->send(18888888888, [ 'template' => '5a95****b953', //短信模板 'data' => [ 1234, //模板参数,对应模板的{1} 30 //模板参数,对应模板的{2} //... ], ]); ``` -------------------------------- ### APIDOC: Aliyun International SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Aliyun International SMS gateway. It requires `access_key_id`, `access_key_secret`, and `sign_name`. SMS content is sent using `template` and `data` parameters. ```APIDOC aliyunintl: access_key_id: string access_key_secret: string sign_name: string ``` -------------------------------- ### Configure Ctyun SMS Provider for EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This PHP configuration array defines the parameters for integrating Ctyun (China Telecom Tianyi Cloud) SMS. It includes `access_key`, `secret_key`, and `sign` (the SMS sending signature, e.g., '验证码测试'). ```php 'ctyun' => [ 'access_key' => '', //用户access 'secret_key' => '', //开发密钥secret 'sign' => '验证码测试', // 短信下发签名, ], ``` -------------------------------- ### Configure and Send SMS with Tinree using EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet outlines the configuration for Tinree provider credentials (accesskey, secret, sign) and demonstrates sending a templated SMS with multiple positional data parameters using EasySms. ```php 'tinree' => [ 'accesskey' => '', // 平台分配给用户的accesskey 'secret' => '', // 平台分配给用户的secret 'sign' => '', // 平台上申请的接口短信签名或者签名ID ], ``` ```php $easySms->send(18888888888, [ 'template' => '123456', // 模板ID 'data' => [ "a", 'b', 'c', //按模板变量占位顺序 ], ]); ``` -------------------------------- ### Configure Yidongmasblack SMS Provider for EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This PHP configuration array sets up the Yidongmasblack (Mobile Cloud MAS) SMS provider. Key parameters include `ecName` (institution name), `secretKey`, `apId` (application ID), `sign` (signature), and `addSerial` (channel number, typically empty). ```php 'yidongmasblack' => [ 'ecName' => '', // 机构名称 'secretKey' => '', // 密钥 'apId' => '', // 应用ID 'sign' => '', // 签名 'addSerial' => '', // 通道号默认空 ], ``` -------------------------------- ### APIDOC: Huyi SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Huyi SMS gateway. It requires `api_id`, `api_key`, and `signature`. SMS content is sent using the `content` parameter. ```APIDOC huyi: api_id: string api_key: string signature: string ``` -------------------------------- ### APIDOC: Submail SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Submail SMS gateway. It requires `app_id`, `app_key`, and an optional default `project` ID which can be overridden in the message `data`. SMS content is sent using the `data` parameter. ```APIDOC submail: app_id: string app_key: string project: string // Optional default project ``` -------------------------------- ### APIDOC: Yunpian SMS Gateway Configuration Source: https://github.com/overtrue/easy-sms/blob/master/README.md Configuration details for the Yunpian SMS gateway. It requires `api_key` and an optional `signature` to be used if no signature is present in the message content. SMS content is sent using the `content` parameter. ```APIDOC yunpian: api_key: string signature: string // Optional default signature ``` -------------------------------- ### PHP: Send SMS with specific gateways in EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md This snippet demonstrates how to send an SMS message using specific gateways, overriding the default global settings. The third parameter of the `send` method accepts an array of gateway names to be used for the current message. ```php $easySms->send(13188888888, [ 'content' => '您的验证码为: 6379', 'template' => 'SMS_001', 'data' => [ 'code' => 6379 ], ], ['yunpian', 'juhe']); // 这里的网关配置将会覆盖全局默认值 ``` -------------------------------- ### PHP: Understand EasySms multi-gateway return values Source: https://github.com/overtrue/easy-sms/blob/master/README.md When sending SMS messages through multiple gateways, EasySms returns an array containing the results from each gateway. Each entry indicates the gateway name, status (success/failure), and the platform's raw result or an exception object. ```php [ 'yunpian' => [ 'gateway' => 'yunpian', 'status' => 'success', 'result' => [...] // 平台返回值 ], 'juhe' => [ 'gateway' => 'juhe', 'status' => 'failure', 'exception' => \Overtrue\EasySms\Exceptions\GatewayErrorException 对象 ], //... ] ``` -------------------------------- ### PHP: Handle EasySms exceptions and retrieve results Source: https://github.com/overtrue/easy-sms/blob/master/README.md If all selected gateways fail to send the SMS, EasySms throws a `NoGatewayAvailableException`. This snippet shows how to catch the exception and use its methods to retrieve detailed results, including all API results, a list of exceptions, a specific gateway's exception, or the last failed exception. ```php $e->getResults(); // 返回所有 API 的结果,结构同上 $e->getExceptions(); // 返回所有调用异常列表 $e->getException($gateway); // 返回指定网关名称的异常对象 $e->getLastException(); // 获取最后一个失败的异常对象 ``` -------------------------------- ### PHP: Define custom EasySms message classes Source: https://github.com/overtrue/easy-sms/blob/master/README.md EasySms allows defining custom message classes by extending `Overtrue\EasySms\Message`. This enables encapsulating message content, template IDs, and data, along with specific gateway strategies and applicable platforms, for reusable message definitions. ```php order = $order; } // 定义直接使用内容发送平台的内容 public function getContent(GatewayInterface $gateway = null) { return sprintf('您的订单:%s, 已经完成付款', $this->order->no); } // 定义使用模板发送方式平台所需要的模板 ID public function getTemplate(GatewayInterface $gateway = null) { return 'SMS_003'; } // 模板参数 public function getData(GatewayInterface $gateway = null) { return [ 'order_no' => $this->order->no ]; } } ``` -------------------------------- ### PHP: Send custom EasySms message objects Source: https://github.com/overtrue/easy-sms/blob/master/README.md After defining a custom message class, you can instantiate it with relevant data and pass the message object directly to the `send` method. This simplifies sending complex or frequently used message types. ```php $order = ...; $message = new OrderPaidMessage($order); $easySms->send(13188888888, $message); ``` -------------------------------- ### PHP: Send international SMS with EasySms Source: https://github.com/overtrue/easy-sms/blob/master/README.md Sending international SMS requires specifying the country code along with the phone number. This snippet shows how to use the `PhoneNumber` class to encapsulate the phone number and its international dialing code, which is then passed to the `send` method. ```php use Overtrue\EasySms\PhoneNumber; // 发送到国际码为 31 的国际号码 $number = new PhoneNumber(13188888888, 31); $easySms->send($number, [ 'content' => '您的验证码为: 6379', 'template' => 'SMS_001', 'data' => [ 'code' => 6379 ], ]); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.