Browse Source

青爻公众号

cqp 10 months ago
parent
commit
66b04d6af6
1 changed files with 39 additions and 1 deletions
  1. 39 1
      app/Service/Weixin/WeixinService.php

+ 39 - 1
app/Service/Weixin/WeixinService.php

@@ -50,7 +50,7 @@ class WeixinService extends Service
         $post = [
             'offset' => $offset,
             'count' => $count,
-            'no_content' => 1,
+            'no_content' => 0,
         ];
         $result = $this->curlOpen($url, ['post' => json_encode($post)]);
         $result = json_decode($result,true);
@@ -270,4 +270,42 @@ class WeixinService extends Service
 
         return [true, $name];
     }
+
+    public function getArticle(){
+        list($status, $msg) = $this->getToken();
+        if(! $status) return [false, $msg];
+
+        $config = config('qingyaoWx');
+        $url = sprintf($config['get_article'], $msg);
+
+        $offset = 0;
+        $count = 20;
+        $get_total = 0;
+        do {
+            $post = [
+                'offset' => $offset,
+                'count' => $count,
+                'no_content' => 0,
+            ];
+
+            $result = $this->curlOpen($url, ['post' => json_encode($post)]);
+            $result = json_decode($result, true);
+
+            Log::channel('apiLog')->info('wxget', ["message" => $result]);
+            if (isset($result['errmsg'])) return [false, $result['errmsg']];
+
+            $a = ['data' => $result['item'] ?? [], 'total' => $result['total_count'], 'data_count' => $result['item_count']];
+
+            // 更新 offset
+            $offset += 1;
+
+            // 更新 total_count
+            $get_total += $result['total_count'];
+
+            // 检查是否还有更多数据
+            $hasMore = isset($result['total_count']) && ($result['total_count'] > $get_total);
+        } while ($hasMore);
+
+        return [true, ''];
+    }
 }