Java 微信公眾號導出所有粉絲(openId)

由于公眾號換了公司主體,需要做遷移,玩家的openId數據需要做處理。

(我是按我要的json格式,將粉絲導成了1萬條數據的一個json文件)

?文件格式:

{"info":[{"openId":"ogVous494ltuNmO4zHb1seHeGLSk"}]
}

?

package exportFansFromPublic;import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.odao.weixin.api.support.AccessTokenKit;
import com.odao.weixin.api.support.HttpKit;/*** 導出公眾號粉絲* @author wangfj*/
public class ExportFansFromPublic {  @SuppressWarnings({ "unchecked", "static-access","rawtypes"})public static void main(String[] args) throws Exception {  String token = AccessTokenKit.getTokenNew("appId", "app秘鑰");String accesstoken = (String) ((Map) JSON.parseObject(token, Map.class)).get("access_token");Map<String,String> params = new HashMap<String,String>();params.put("access_token", accesstoken);String nextOpenId = "";for(int i=1;i<=50;i++){ //我這了定的50,是根據公眾號粉絲數量來的,一個文件一萬條,你們自己算if(!"".equals(nextOpenId)){params.put("next_openid", nextOpenId);}//根據appId,appSecret獲取數據粉絲openId(1次1萬條)//格式:{"data":{"openid":["oneOpenId,twoOpenId"]},"next_openid":"theNextOpenId"}try{String data = HttpKit.get("https://api.weixin.qq.com/cgi-bin/user/get",params);JSONObject json = (JSONObject) JSONObject.parse(data);String openId = json.get("data").toString();JSONObject open = (JSONObject) JSONObject.parse(openId);String openIds = open.get("openid").toString();JSONArray arr= JSONObject.parseArray(openIds);List<String> list = arr.toJavaObject(arr,  List.class);nextOpenId = writerJson(list,i);}catch(Exception e){System.out.println("導出完畢");break;}    }}public static String writerJson(List<String> list,int fileName){String nextOpenId = "";FileWriter fw = null;  PrintWriter out = null;  try {  // 指定生成txt的文件路徑  fw = new FileWriter("C:/Users/admin/Desktop/fan/"+fileName+".json");  out = new PrintWriter(fw);  out.println("{");out.println("\t\"info\":[");for(int i=0;i<list.size();i++){if(i!=list.size()-1){out.println("\t\t{\"openId\":\""+list.get(i)+"\"},");}else{nextOpenId = list.get(i);out.println("\t\t{\"openId\":\""+list.get(i)+"\"}");}}out.println("\t]");out.println("}");} catch (Exception e) {  e.printStackTrace();} finally {  try {  out.close();  fw.close();  out.flush();  // 由于此處用到了緩沖流,如果數據量過大,不進行flush操作,某些數據將依舊  存在于內從中而不會寫入文件,此問題一定要注意  } catch (Exception e) {  e.printStackTrace();  }  }  return nextOpenId;}
}  

?

轉載于:https://www.cnblogs.com/wangfajun/p/8399585.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390264.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390264.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390264.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

javascript閉包_JavaScript閉包教程–帶有JS閉包示例代碼

javascript閉包Closures – many of you JavaScript devs have probably heard this term before. When I started my journey with JavaScript, I encountered closures often. And I think theyre one of the most important and interesting concepts in JavaScript. 閉包–…

1646. 獲取生成數組中的最大值

1646. 獲取生成數組中的最大值 給你一個整數 n 。按下述規則生成一個長度為 n 1 的數組 nums &#xff1a; nums[0] 0 nums[1] 1 當 2 < 2 * i < n 時&#xff0c;nums[2 * i] nums[i] 當 2 < 2 * i 1 < n 時&#xff0c;nums[2 * i 1] nums[i] nums[i …

docker保存日志文件到本地

其實很簡單 docker logs 你需要添加的額外參數 容器id >文件名稱 然后查看這個文件就可以了&#xff0c;也可以通過ftp協議下載到本地

防反射JavaScript –如何讓您的JS等待

Debounce methods do not execute when invoked. Instead, they wait for a predetermined time before executing. If the same method is called again, the previous is cancelled and the timer restarts.防抖動方法在調用時不執行。 而是&#xff0c;它們在執行之前等待預…

21天學通Visual.Basic pdf

下載地址&#xff1a;網盤下載《21天學通Visual Basic(第2版)》是Visual Basic 6.0的入門教程&#xff0c;主要針對沒有程序設計基礎的讀者&#xff0c;詳細介紹了Visual Basic 6.0的基本概念和編程技術。書中通過大量的范例及綜合練習來介紹Visual Basic 6.0的基本概念、語言特…

297. 二叉樹的序列化與反序列化

297. 二叉樹的序列化與反序列化 序列化是將一個數據結構或者對象轉換為連續的比特位的操作&#xff0c;進而可以將轉換后的數據存儲在一個文件或者內存中&#xff0c;同時也可以通過網絡傳輸到另一個計算機環境&#xff0c;采取相反方式重構得到原數據。 請設計一個算法來實現…

交互式圖表_如何構建羅馬數字轉換器和交互式羅馬數字圖表

交互式圖表The Roman numerals are no longer an essential part of our daily lives. But we do use them when designing monuments, clocks, and even for sporting events.羅馬數字不再是我們日常生活中必不可少的部分。 但是我們在設計紀念碑&#xff0c;鐘表甚至體育賽事…

Python 08 面向對象

Python 面向對象 1、編程范式 2、面向對象特性 3、屬性、方法 4、三大特性 5、高級方法 6、類的特殊成員方法 7、反射 8、異常處理 9、單例模式 一、編程范式 編程&#xff1a;程序員用特定的語法數據結構算法組成的代碼來告訴計算機如何執行任務的過程 &#xff0c; 實現一個…

eclipse手動添加SVN插件

https://www.cnblogs.com/hcl1991/p/5888461.html 1.手動下載svn插件&#xff08;百度SVNsite-1.8.18&#xff09; 2.將下載好的SVNsite-1.8.18.zip 解壓 3.在eclipse安裝目錄的plugins新建SVN文件夾 4.將SVNsite-1.8.18解壓包下的features和plugins拷貝到新建的SVN文件夾下 5.…

440. 字典序的第K小數字

440. 字典序的第K小數字 給定整數 n 和 k&#xff0c;找到 1 到 n 中字典序第 k 小的數字。 注意&#xff1a;1 ≤ k ≤ n ≤ 109。 示例 : 輸入: n: 13 k: 2 輸出: 10 解釋: 字典序的排列是 [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]&#xff0c;所以第二小的數字是…

微信小程序 設置背景占滿整個頁面

微信小程序,默認的根節點是<page></page>&#xff0c;所有內容都包裹在這個標簽里&#xff0c;如何讓頁面的背景占滿整個屏幕&#xff1f;&#xff1f; <page><view class"bg">....</view> </page> .bg {background-image:ur…

udemy下載課程無法播放_最好的Udemy Web開發課程+熱門免費課程

udemy下載課程無法播放Heres a list of some of the most popular web development courses on Udemy:以下是Udemy上一些最受歡迎的Web開發課程的列表&#xff1a; Best General Web Development Courses on Udemy:關于Udemy的最佳常規Web開發課程&#xff1a; The Complete …

滲透測試初學者_滲透測試許可證:面向初學者的道德黑客課程

滲透測試初學者A penetration test is an authorized cyberattack on a computer system, performed to evaluate the security of the system. 滲透測試是對計算機系統的授權網絡攻擊&#xff0c;旨在評估系統的安全性。 Weve released a full pentesting course on the free…

Codeforces 915 E Physical Education Lessons

題目描述 This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is …

JDK 11 還有一個處于計劃階段的 JEP:讓其支持 TLS 1.3

開發四年只會寫業務代碼&#xff0c;分布式高并發都不會還做程序員&#xff1f; >>> JDK 11 最近有什么消息&#xff1f;我們不妨來看一下它的進展情況&#xff0c;包括最新的 JEP 提案。Java 的新版本發布計劃意味著總會有一款新的 JDK 即將推出。根據他們的計劃&a…

498. 對角線遍歷

498. 對角線遍歷 給定一個含有 M x N 個元素的矩陣&#xff08;M 行&#xff0c;N 列&#xff09;&#xff0c;請以對角線遍歷的順序返回這個矩陣中的所有元素&#xff0c;對角線遍歷如下圖所示。 示例: 輸入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 輸出: [1,2,4,7,5…

軟件測試測試用例編寫_不要先編寫所有軟件測試-只需編寫一個

軟件測試測試用例編寫Test Driven Development (TDD) is sometimes described as “writing tests first”. The TDD mantra states that we should not write code before we have written automated tests that exercise that code. Writing code first is considered subopt…

練習五

1.團隊模式和團隊的開發模式有什么關系&#xff1f; 答&#xff1a; 首先我來解釋一下這兩個名詞&#xff1a; 我查資料了解了一下&#xff0c;團隊模式&#xff0c;更偏向于多人合作的那種&#xff0c;而且我理解的“團隊”會是一種多人合作的情況下&#xff0c;長期磨合后的一…

Squid 訪問控制配置

Squid 訪問控制配置 主配置文件內加入限制參數 vim /etc/squid/squid.conf # 訪問控制 acl http proto HTTP # 限制訪問 good_domain添加兩個域名“.”表示半解析(相當于*) acl good_domain dstdomain .kevin.net .baidu.com # 允許good_domain內的域名訪問 http_access allow …

劍指 Offer 62. 圓圈中最后剩下的數字

0,1,,n-1這n個數字排成一個圓圈&#xff0c;從數字0開始&#xff0c;每次從這個圓圈里刪除第m個數字&#xff08;刪除后從下一個數字開始計數&#xff09;。求出這個圓圈里剩下的最后一個數字。 例如&#xff0c;0、1、2、3、4這5個數字組成一個圓圈&#xff0c;從數字0開始每…