From 1dbd96cb036621490d1bbd482e993c2707784820 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Tue, 14 Oct 2025 17:01:57 +0800 Subject: [PATCH] =?UTF-8?q?alibaba=E5=9F=BA=E7=B1=BB=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/YskController.php | 15 ++++ app/model/AlibabaSms.php | 134 ++++++++++++++++++++++++++++--- app/process/MessagePushTask.php | 18 +---- app/queue/redis/ApplySmsTemp.php | 4 + composer.json | 6 +- composer.lock | 61 ++++++++++++-- config/cons.php | 1 + 7 files changed, 202 insertions(+), 37 deletions(-) diff --git a/app/controller/YskController.php b/app/controller/YskController.php index 96e2103..3fd3755 100644 --- a/app/controller/YskController.php +++ b/app/controller/YskController.php @@ -29,6 +29,21 @@ class YskController extends ApiController // $data = \app\model\MessagePushTask::send_sms_msg(); } + public function sendsms(Request $request) + { + + // 加入队列发送短信 +// $a = AlibabaSms::main([ +// 'templateCode' => 'SMS_244665149', +// 'templateParam' => json_encode(['code' => 1234]), +// 'phoneNumbers' => '15851408673', +// 'signName' => '陕西超掌柜科技', +// ]); +// p($a); + } + + + } diff --git a/app/model/AlibabaSms.php b/app/model/AlibabaSms.php index e044104..94416cc 100644 --- a/app/model/AlibabaSms.php +++ b/app/model/AlibabaSms.php @@ -8,25 +8,30 @@ use support\Log; use think\Model; use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi; use AlibabaCloud\Tea\Exception\TeaError; -use AlibabaCloud\Tea\Utils\Utils; - +use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; +use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\CreateSmsTemplateRequest; +use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\GetSmsTemplateRequest; +use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\UpdateSmsTemplateRequest; +use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\DeleteSmsTemplateRequest; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest; -use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; - +use AlibabaCloud\Tea\Utils\Utils; class AlibabaSms extends Model { + + protected static $sms_code = '陕西超掌柜科技'; + /** * 使用AK&SK初始化账号Client * @param string $accessKeyId * @param string $accessKeySecret * @return Dysmsapi Client */ - public static function createClient($accessKeyId, $accessKeySecret){ + public static function createClient(){ $config = new Config([ - "accessKeyId" => $accessKeyId, - "accessKeySecret" => $accessKeySecret + "accessKeyId" => config('cons.alibaba_sms.access_key_id'), + "accessKeySecret" => config('cons.alibaba_sms.access_key_secret') ]); $config->endpoint = "dysmsapi.aliyuncs.com"; return new Dysmsapi($config); @@ -39,13 +44,13 @@ class AlibabaSms extends Model */ public static function main($args){ - $client = self::createClient(config('cons.alibaba_sms.access_key_id'), config('cons.alibaba_sms.access_key_secret')); + $client = self::createClient(); $sendSmsRequest = new SendSmsRequest($args); $runtime = new RuntimeOptions([]); try { // 复制代码运行请自行打印 API 的返回值 $res = $client->sendSmsWithOptions($sendSmsRequest, $runtime); - Log::info('短信接口返回---》' . json_encode($res->body->toArray())); + Log::info('发送短信接口返回---》' . json_encode($res->body->toArray())); if($res->body->code == 'OK') { return true; }else { @@ -58,12 +63,119 @@ class AlibabaSms extends Model } // 如有需要,请打印 error Utils::assertAsString($error->message); - Log::info('短信发送错误--' . $error->message); - return false; + Log::info('发送短信错误--' . $error->message); } } + // 申请新短信模版 + public function CreateSmsTemplate($data) + { + $client = self::createClient(); + $createSmsTemplateRequest = new CreateSmsTemplateRequest([]); + $runtime = new RuntimeOptions([]); + try { + $res = $client->createSmsTemplateWithOptions($createSmsTemplateRequest, $runtime); + Log::info('申请新短信模版接口返回---》' . json_encode($res->body->toArray())); + if($res->body->code == 'OK') { + return true; + }else { + return false; + } + } + catch (Exception $error) { + if (!($error instanceof TeaError)) { + $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); + } + Utils::assertAsString($error->message); + Log::info('申请新短信模版错误--' . $error->message); + } + } + + + // 查询模版审核详情 + public function GetSmsTemplate($data) + { + $client = self::createClient(); + $getSmsTemplateRequest = new GetSmsTemplateRequest([]); + $runtime = new RuntimeOptions([]); + try { + $res = $client->getSmsTemplateWithOptions($getSmsTemplateRequest, $runtime); + Log::info('查询模版审核详情接口返回---》' . json_encode($res->body->toArray())); + if($res->body->code == 'OK') { + return $res->body->toArray(); + }else { + return false; + } + } + catch (Exception $error) { + if (!($error instanceof TeaError)) { + $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); + } + Utils::assertAsString($error->message); + Log::info('查询模版审核详情接口错误--' . $error->message); + } + } + + // 修改模版 + public function UpdateSmsTemplate($data) + { + $client = self::createClient(); + $updateSmsTemplateRequest = new UpdateSmsTemplateRequest([]); + $runtime = new RuntimeOptions([]); + try { + $res = $client->updateSmsTemplateWithOptions($updateSmsTemplateRequest, $runtime); + Log::info('修改模版接口返回---》' . json_encode($res->body->toArray())); + if($res->body->code == 'OK') { + return true; + }else { + return false; + } + } + catch (Exception $error) { + if (!($error instanceof TeaError)) { + $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); + } + Utils::assertAsString($error->message); + Log::info('修改模版接口错误--' . $error->message); + } + } + + + + + // 删除短信模版 + public function DeleteSmsTemplate($data) + { + $client = self::createClient(); + $deleteSmsTemplateRequest = new DeleteSmsTemplateRequest([]); + $runtime = new RuntimeOptions([]); + try { + // 复制代码运行请自行打印 API 的返回值 + $res = $client->deleteSmsTemplateWithOptions($deleteSmsTemplateRequest, $runtime); + Log::info('删除短信模版接口返回---》' . json_encode($res->body->toArray())); + if($res->body->code == 'OK') { + return true; + }else { + return false; + } + } + catch (Exception $error) { + if (!($error instanceof TeaError)) { + $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); + } + Utils::assertAsString($error->message); + Log::info('删除短信模版接口错误--' . $error->message); + } + } + + + + + + + + /** * 查询短信发送结果 */ diff --git a/app/process/MessagePushTask.php b/app/process/MessagePushTask.php index 77beaa3..2ce1eeb 100644 --- a/app/process/MessagePushTask.php +++ b/app/process/MessagePushTask.php @@ -9,27 +9,11 @@ class MessagePushTask { public function onWorkerStart() { - - // 每月1号 营销接收次数更新 + // 每月1号 查询短信发送状态 new Crontab('0 0 1 * *', function(){ Log::info('营销接收次数更新开始执行---->'); \app\model\SaveUserPushNumber::savePushNumber(); Log::info('营销接收次数更新执行结束---->'); }); - - - // 每分钟执行 营销推送 -// new Crontab('1 * * * * *', function(){ -// Log::info('营销推送开始执行---->'); -// \app\model\MessagePushTask::send_msg(); -// Log::info('营销推送执行结束---->'); -// }); - - - - - - - } } \ No newline at end of file diff --git a/app/queue/redis/ApplySmsTemp.php b/app/queue/redis/ApplySmsTemp.php index dd37061..12d40a8 100644 --- a/app/queue/redis/ApplySmsTemp.php +++ b/app/queue/redis/ApplySmsTemp.php @@ -18,7 +18,11 @@ class ApplySmsTemp implements Consumer { Log::info('消息队列【申请新短信模版】接收到消息' . $data); + // 查询没有提交审核的模版 + $temp_list = Db::table('sms_shop_template')->where(['shop_id' => 1, 'status' => 0])->select()->toArray(); + if ($temp_list) { + } diff --git a/composer.json b/composer.json index c661d02..be7ae01 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,12 @@ "webman/redis-queue": "^1.3", "workerman/crontab": "^1.0", "overtrue/wechat": "~5.0", - "alibabacloud/dysmsapi-20170525": "^3.1", "webman/gateway-worker": "^1.0", "webman/console": "^2.1", - "php-amqplib/php-amqplib": "^3.6" + "php-amqplib/php-amqplib": "^3.6", + "alibabacloud/dysmsapi-20170525": "^4.2", + "alibabacloud/tea": "^3.2", + "alibabacloud/tea-utils": "^0.2.21" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 7bd7559..74c0637 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d61f7eb84a5a68f77a4c61eefda442a5", + "content-hash": "88c1a3313c5a2650ded93bc53da2caa5", "packages": [ { "name": "adbario/php-dot-notation", @@ -226,16 +226,16 @@ }, { "name": "alibabacloud/dysmsapi-20170525", - "version": "3.1.3", + "version": "4.2.0", "source": { "type": "git", "url": "https://github.com/alibabacloud-sdk-php/Dysmsapi-20170525.git", - "reference": "39bebd85974efc144615b9a11dfdb641d23f90f1" + "reference": "fcf6764d5d0d797fd5fbc20ecd940d22a81ea455" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alibabacloud-sdk-php/Dysmsapi-20170525/zipball/39bebd85974efc144615b9a11dfdb641d23f90f1", - "reference": "39bebd85974efc144615b9a11dfdb641d23f90f1", + "url": "https://api.github.com/repos/alibabacloud-sdk-php/Dysmsapi-20170525/zipball/fcf6764d5d0d797fd5fbc20ecd940d22a81ea455", + "reference": "fcf6764d5d0d797fd5fbc20ecd940d22a81ea455", "shasum": "", "mirrors": [ { @@ -267,9 +267,9 @@ ], "description": "Alibaba Cloud Dysmsapi (20170525) SDK Library for PHP", "support": { - "source": "https://github.com/alibabacloud-sdk-php/Dysmsapi-20170525/tree/3.1.3" + "source": "https://github.com/alibabacloud-sdk-php/Dysmsapi-20170525/tree/4.2.0" }, - "time": "2025-04-16T17:20:20+00:00" + "time": "2025-09-17T02:17:53+00:00" }, { "name": "alibabacloud/gateway-spi", @@ -442,6 +442,53 @@ }, "time": "2023-05-16T06:43:41+00:00" }, + { + "name": "alibabacloud/tea-utils", + "version": "0.2.21", + "source": { + "type": "git", + "url": "https://github.com/alibabacloud-sdk-php/tea-utils.git", + "reference": "5039e45714c6456186d267f5d81a4b260a652495" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/alibabacloud-sdk-php/tea-utils/zipball/5039e45714c6456186d267f5d81a4b260a652495", + "reference": "5039e45714c6456186d267f5d81a4b260a652495", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "alibabacloud/tea": "^3.1", + "php": ">5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "AlibabaCloud\\Tea\\Utils\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com" + } + ], + "description": "Alibaba Cloud Tea Utils for PHP", + "support": { + "issues": "https://github.com/aliyun/tea-util/issues", + "source": "https://github.com/aliyun/tea-util" + }, + "time": "2024-07-05T06:05:54+00:00" + }, { "name": "carbonphp/carbon-doctrine-types", "version": "3.2.0", diff --git a/config/cons.php b/config/cons.php index 02431dc..8fd320b 100644 --- a/config/cons.php +++ b/config/cons.php @@ -10,4 +10,5 @@ return [ 'access_key_id' => 'LTAI5t9Wn4qu9UFcvy5LUH4y', 'access_key_secret' => 'UnqHyd2ByXTYisnIyXl5PsJyveIEau', ], + 'sms_sign' => '陕西超掌柜科技' ];