فهرست منبع

[智价云] 订阅推送调试

tangyuanwang 1 هفته پیش
والد
کامیت
40482266fb
2فایلهای تغییر یافته به همراه35 افزوده شده و 23 حذف شده
  1. 9 5
      app/Jobs/Manager/Process/SubscriptionJobs.php
  2. 26 18
      app/Servers/Wechat/Official.php

+ 9 - 5
app/Jobs/Manager/Process/SubscriptionJobs.php

@@ -83,6 +83,7 @@ class SubscriptionJobs implements ShouldQueue
                             'totle_number' => $value->total_number
                         ];
                     }
+                    // $user_id_list=['2'=>'10'];
                     $this->send_low_price_goods_notice($user_id_list);
                     break;
                 case 'violation_product':
@@ -114,6 +115,7 @@ class SubscriptionJobs implements ShouldQueue
                             'totle_number' => $value['total_number']
                         ];
                     }
+                    // $user_id_list=['2'=>'10'];
                     $this->send_violation_product($user_id_list);
                     break;
                 default:
@@ -134,17 +136,19 @@ class SubscriptionJobs implements ShouldQueue
     {
         $EmployeeModel = new EmployeeModel();
         foreach ($user_id_list as $key => $totle_number) {
-            $user_info  = $EmployeeModel->where('id', $key)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->first(['openid']);
+            $user_info  = $EmployeeModel->join('personnel_employee_openid', 'personnel_employee_openid.employee_id', '=', 'personnel_employee.id')
+                ->select(['personnel_employee.*', 'personnel_employee_openid.employee_id', 'personnel_employee_openid.openid'])
+                ->where('personnel_employee.id', $key)->where([['personnel_employee.open_notice', '=', 0], ['personnel_employee.status', '=', 0]])->first();
             if (empty($user_info)) return true;
             if ($user_info['openid'] == '') return true;
             $data           = [
                 'thing1'    => '数据违规预警',
                 'thing2'    => '低价挂网商品:共【' . $totle_number . '】条',
-                'time7'     => strtotime(time(), 'Y:m:d H:i:s'),
+                'time7'     => time(),
                 'phrase9'   => '待处理',
             ];
             $params     = [
-                'touser'            => $user_info['openid'],
+                'openid'            => $user_info['openid'],
                 'template_id'       => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
                 'miniprogram'               => [
                     'appid' => config('wechat.mini.app_id'),
@@ -172,7 +176,7 @@ class SubscriptionJobs implements ShouldQueue
         foreach ($user_id_list as $key => $totle_number) {
             $user_info  = $EmployeeModel->join('personnel_employee_openid', 'personnel_employee_openid.employee_id', '=', 'personnel_employee.id')
                 ->select(['personnel_employee.*', 'personnel_employee_openid.employee_id', 'personnel_employee_openid.openid'])
-                ->where('personnel_employee.id', $key)->where([['personnel_employee.open_subscribe', '=', 0], ['personnel_employee.status', '=', 1]])->first();
+                ->where('personnel_employee.id', $key)->where([['personnel_employee.open_notice', '=', 0], ['personnel_employee.status', '=', 0]])->first();
             if (empty($user_info)) return true;
             if ($user_info['openid'] == '') return true;
             $data           = [
@@ -182,7 +186,7 @@ class SubscriptionJobs implements ShouldQueue
                 'phrase9'   => '待处理',
             ];
             $params     = [
-                'touser'            => $user_info['openid'],
+                'openid'            => $user_info['openid'],
                 'template_id'       => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
                 'miniprogram'               => [
                     'appid' => config('wechat.mini.app_id'),

+ 26 - 18
app/Servers/Wechat/Official.php

@@ -1,4 +1,6 @@
-<?php namespace App\Servers\Wechat;
+<?php
+
+namespace App\Servers\Wechat;
 
 use EasyWeChat\Factory;
 
@@ -12,7 +14,8 @@ class Official
     protected \EasyWeChat\OfficialAccount\Application  $app;
 
     // 构造函数
-    public function __construct(){
+    public function __construct()
+    {
         // 应用实例
         $this->app                          = $this->getApp();
     }
@@ -23,9 +26,10 @@ class Official
      * @return \EasyWeChat\OfficialAccount\Application
      * 
      */
-    public function getApp(){
+    public function getApp()
+    {
         // 获取配置
-		$this->app                          = Factory::officialAccount(config('wechat.official',[]));
+        $this->app                          = Factory::officialAccount(config('wechat.official', []));
         // 返回结果
         return                              $this->app;
     }
@@ -36,11 +40,12 @@ class Official
      *
      *
      */
-    public function userFromCode($code){
+    public function userFromCode($code)
+    {
         // 获取手机号
-        $result							    = $this->app->oauth->userFromCode($code);
+        $result                                = $this->app->oauth->userFromCode($code);
         // 判断结果
-        if( !empty($result['errcode']) )    return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
+        if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
         // 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
         return                              $result;
     }
@@ -49,11 +54,12 @@ class Official
      * 获取JSSDK的配置数组
      * @return array
      */
-    public function getJssdkConfig($url=''){
+    public function getJssdkConfig($url = '')
+    {
         // 如果指定路径的话
-        if( $url )                          $this->app->jssdk->setUrl($url);
+        if ($url)                          $this->app->jssdk->setUrl($url);
         // 获取JSSDK的配置对象
-        $config                             = $this->app->jssdk->buildConfig(['updateAppMessageShareData','updateTimelineShareData'],false,false,false);
+        $config                             = $this->app->jssdk->buildConfig(['updateAppMessageShareData', 'updateTimelineShareData'], false, false, false);
         // 获取JSSDK的配置数组
         return                              $config;
     }
@@ -62,17 +68,18 @@ class Official
      * @param array $params
      *
      */
-    public function sendSubscription($params){
-        // 获取手机号
-        $result							    = $this->app->template_message->sendSubscription([
+    public function sendSubscription($params)
+    {
+
+        $result    = $this->app->template_message->sendSubscription([
             'touser' => $params['openid'],
             'template_id' => 'template-id',
-            'url' => $params['url'],
+            'miniprogram' => $params['miniprogram'],
             'scene' => 1000,
             'data' => $params['data'],
         ]);
         // 判断结果
-        if( !empty($result['errcode']) )    return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
+        if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
         // 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
         return                              $result;
     }
@@ -81,9 +88,10 @@ class Official
      * @param array $params
      *
      */
-    public function send($params){
+    public function send($params)
+    {
         // 获取手机号
-        $result							    = $this->app->template_message->send([
+        $result                                = $this->app->template_message->send([
             'touser' => $params['openid'],
             'template_id' => 'template-id',
             'url' => $params['url'],
@@ -91,7 +99,7 @@ class Official
             'data' => $params['data'],
         ]);
         // 判断结果
-        if( !empty($result['errcode']) )    return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
+        if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
         // 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
         return                              $result;
     }