Ver código fonte

[智价云] 微信扫码登录配置修改&推送方法补充

tangyuanwang 1 semana atrás
pai
commit
4e6f32f298
2 arquivos alterados com 94 adições e 8 exclusões
  1. 86 0
      app/Jobs/Manager/Process/Subscription.php
  2. 8 8
      config/wechat.php

+ 86 - 0
app/Jobs/Manager/Process/Subscription.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Jobs\Manager\Process;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use App\Models\Manager\Personnel\Employee as EmployeeModel;
+use App\Facades\Servers\Wechat\Official;
+use App\Facades\Servers\Logs\Log;
+
+
+/**
+ * 订阅消息通知推送
+ * @author  唐远望
+ * @version 1.0
+ * @date  2026-03-04
+ */
+class Subscription implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    protected $message_data;
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(array $message_data)
+    {
+        $this->message_data = $message_data;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        try {
+            $this->send($this->message_data['user_id_list'], $this->message_data['msg_title']);
+        } catch (\Exception $e) {
+            Log::info('job_error', '订阅消息通知推送队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
+        }
+    }
+
+    /**
+     * 公众号消息订阅推送
+     *
+     * */
+    private function send($user_id_list, $msg_title = '')
+    {
+        $EmployeeModel = new EmployeeModel();
+        $user_list  = $EmployeeModel->whereIn('id',$user_id_list)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->select(['openid'])->select();
+        if(empty($user_list)) return true;
+        $data           = [
+            'thing1'    => $msg_title,
+            'thing2'    => '您有一条新的违规待处理通知要处理,请及时查看',
+            'time7'     => strtotime(time(), 'Y:m:d H:i:s'),
+            'phrase9'   => '待处理',
+        ];
+        foreach ($user_list as $value) {
+            $params     = [
+                'touser'            => $value['openid'],
+                'template_id'       => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
+                'url'               => '',
+                'data'              => $data,
+            ];
+            //发送模板消息
+            $result     = Official::sendSubscription($params);
+        }
+
+        // 告知结果
+        return            json_send(['code' => 'success', 'msg' => '成功', 'path' => '']);
+    }
+
+
+
+    public function failed(\Throwable $exception)
+    {
+        Log::info('job_error', '订阅消息通知推送队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
+    }
+}

+ 8 - 8
config/wechat.php

@@ -13,16 +13,16 @@ return [
         ],
     ],
     'openplat' => [
-        'app_id'               => env('WECHAT_OPENPLAT_APP_ID', 'wx2386988b9b706ff5'),
-        'secret'               => env('WECHAT_OPENPLAT_SECRET', '3b487dd62a738939bb833f928d4fa4bd'),
-        'token'                => env('WECHAT_OPENPLAT_TOKEN', 'Afd61RPH3GzEwfEATRwdJVKhy'),
-        'aes_key'              => env('WECHAT_OPENPLAT_AES_KEY', 'FL1brptJzQeDMwp5nvuojb8YEDx9GXy9kxaQ8JQl2Zi'),
-        'host_url'             => env('WECHAT_OPENPLAT_HOST_URL', 'https://retrieveapi.dfwy.tech/'),
-        'release_host_url'     => env('WECHAT_OPENPLAT_RELEASE_HOST_URL', 'https://retrieveapi.findit.ltd/'),
+        'app_id'               => env('WECHAT_OPENPLAT_APP_ID', 'wxa0567dbde0434a27'),//微信开放平台应用ID
+        'secret'               => env('WECHAT_OPENPLAT_SECRET', '3c0cde2e91fe46813209d637222da24b'),//微信开放平台应用秘钥
+        'token'                => env('WECHAT_OPENPLAT_TOKEN', ''),//微信开放平台应用令牌
+        'aes_key'              => env('WECHAT_OPENPLAT_AES_KEY', ''),//微信开放平台应用消息加解密密钥
+        'host_url'             => env('WECHAT_OPENPLAT_HOST_URL', 'https://retrieveapi.dfwy.tech/'),//微信开放平台接口地址
+        'release_host_url'     => env('WECHAT_OPENPLAT_RELEASE_HOST_URL', 'https://retrieveapi.findit.ltd/'),//微信开放平台接口地址
     ],
     'official' => [
-        'app_id' => env('OFFICIAL_APP_ID', 'wxb2a449728522cdaf'),
-        'secret' => env('OFFICIAL_SECRET', '734627d9e8c4a77a83cc58021cfc2e09'),
+        'app_id' => env('OFFICIAL_APP_ID', 'wxf7d79ce0e2f85092'),//微信公众平台应用ID
+        'secret' => env('OFFICIAL_SECRET', '3c0cde2e91fe46813209d637222da24b'),//微信公众平台应用秘钥(已转移到微信开放平台设置)
         'response_type' => 'array',
     ],