easy-sms发送华为云短信,怎么替换变量

app('sms')->send('180xxxxxxxx', [
    'template' => 'f7c4f009ae0a42bbafd9eacbxxxxxxx',
    'data' => [
        'from' => 'custom'
    ],
]);

有个变量为${1}怎么进行替换

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案
$easySms->send(13188888888, [
    'template' => 'f7c4f009ae0a42bbafd9eacbxxxxxxx',
    'data' => [
        6379, // ${1}
        'from' => 'custom' // 对应 config 中的 from 数组中 custom
    ],
]);
2个月前 评论
王大牛 (楼主) 2个月前
codeSeele (作者) 2个月前
王大牛 (楼主) 2个月前
讨论数量: 8

// 假设您有一个包含 ${1} 变量的字符串 $variable = 'your_value'; // 要替换的值

// 替换字符串中的 ${1} 变量 $template = 'f7c4f009ae0a42bbafd9eacbxxxxxxx'; $template = str_replace('${1}', $variable, $template);

// 添加新变量到数据数组中 $data = [ 'from' => 'custom', 'new_variable' => 'your_new_value' ];

// 发送短信 app('sms')->send('180xxxxxxxx', [ 'template' => $template, 'data' => $data, ]);

2个月前 评论
王大牛 (楼主) 2个月前

没怎么用过这个,不过看起来像配置那个参数加一个需要发送的变量对应的数组,这个得看文档

2个月前 评论
$easySms->send(13188888888, [
    'template' => 'f7c4f009ae0a42bbafd9eacbxxxxxxx',
    'data' => [
        6379, // ${1}
        'from' => 'custom' // 对应 config 中的 from 数组中 custom
    ],
]);
2个月前 评论
王大牛 (楼主) 2个月前
codeSeele (作者) 2个月前
王大牛 (楼主) 2个月前

华为的垃圾东西你也用。有问题看华为的文档,不过文档也烂。提交工单

2个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!