微信迁移主体 将关注用户转移到新公众号

/*** 得到微信公众号用户OPENID* @param 原微信accessToken*/public static List getOpenIdList(String accessToken)
{String total;           //关注该公众账号的总用户数String count;           //拉取的OPENID个数,最大值为10000JSONObject data;            //列表数据,OPENID的列表String next_openid;     //拉取列表的最后一个用户的OPENIDList openidList =null;//http请求方式: GET(请使用https协议)//https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENIDString url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken;try {URL getUrl=new URL(url);HttpURLConnection http=(HttpURLConnection)getUrl.openConnection();http.setRequestMethod("GET");http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");http.setDoOutput(true);http.setDoInput(true);http.connect();//请求成功200提示码if( http.getResponseCode()==200 ) {InputStream is = http.getInputStream(); int size = is.available(); byte[] b = new byte[size];is.read(b);String message = new String(b, "UTF-8");JSONObject obj=new JSONObject(message);total=(String) obj.get("total");count=(String) obj.get("count");data = (JSONObject)obj.get("data");openidList = (List)data.get("openid");next_openid=(String) obj.get("next_openid");}} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return openidList;
}
/*** 旧微信公众号OPENID转化为新微信公众号OPENID----* @param openidList原微信的用户openid集合  新微信accessToken 原微信appid*/
public static LinkedHashMap<String,String>  oldOpenIdConvertToNewOpenId(List openidList,String accessToken,String appid)
{LinkedHashMap<String,String> map = new LinkedHashMap<String,String>();//http请求方式: post(请使用https协议)token为新帐号的token//http://api.weixin.qq.com/cgi-bin/changeopenid?access_token=xxxxxif( openidList != null && openidList.size() > 0){//计算需要转化次数  因为每次微信转化最多100个/次int amount = (int)Math.ceil(openidList.size()/100);//从下标为0开始截取int count = 0;//截取listList subList;for( int i=0;i<amount; i++ ){count +=1;subList = openidList.subList((count-1)*100, count*100);if( amount == count){subList = openidList.subList((count-1)*100, openidList.size()+1);}String url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken;try {URL getUrl=new URL(url);HttpURLConnection http=(HttpURLConnection)getUrl.openConnection();http.setDoOutput(true);http.setDoInput(true);http.setRequestMethod("POST");http.setUseCaches(false); http.setInstanceFollowRedirects(true);http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");http.setRequestProperty("Charset", "UTF-8"); http.connect();DataOutputStream out = new DataOutputStream(http.getOutputStream());String params="{"+ "\"from_appid\":"+ appid+","+ "\"openid_list\":"+subList+"}";        System.out.println(params);out.write(params.getBytes("UTF-8"));out.flush();out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream(),"UTF-8"));String line;String responseStr="";while ((line = reader.readLine()) != null){responseStr+=line;}System.out.println(responseStr);JSONObject obj=new JSONObject(responseStr);System.out.println(obj.get("errmsg"));JSONArray newOpenIdList = JSON.parseArray( obj.get("result_list")+"");//遍历得到取到的新旧OPENIDif( newOpenIdList!=null && newOpenIdList.size()>0){for(int j=0;j<newOpenIdList.size();j++){com.alibaba.fastjson.JSONObject jsonObject = newOpenIdList.getJSONObject(j);String err_msg = jsonObject.get("err_msg")+"";//取到目前还关注公众号的用户,即会返回"ok"if( err_msg != null && err_msg.equals("ok") ){String ori_openid = jsonObject.get("ori_openid")+"";String new_openid = jsonObject.get("new_openid")+"";System.out.println(ori_openid);System.out.println(new_openid);map.put(ori_openid, new_openid);}}}reader.close();http.disconnect();}catch (MalformedURLException e) {e.printStackTrace();} catch (ProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}return map;
}

}

微信转化接口(2018-06-14)相关推荐

  1. php微信支付接口开发程序(概念篇)

    From: https://www.bbsmax.com/A/KE5QLr1kJL/ 阅读对象 本文阅读对象:商户系统(在线购物平台.人工收银系统.自动化智能收银系统或其他)集成微信支付涉及的技术架构 ...

  2. 前端微信签名验证工具_微信JS接口签名的生成

    简要说明微信JS接口签名的生成方式 签名生成规则参与签名的字段包括有效的 jsapi_ticket(获取方式详见微信 JSSDK 文档), noncestr (随机字符串,由开发者随机生成),time ...

  3. 个人微信协议接口开发

    #联系作者微信 :damibtc 第一步 开发者登录 获取API token POST http://域名地址/foreign/auth/login 请求参数 Request Form Data Pa ...

  4. kaos linux 包管理,KaOS 发布 2018.06 版

    KaOS 是一个独立的遵循滚动更新模型的 Linux 发行版.它旨在以 KDE 及基于 Qt 的软件提供优雅的桌面体验:仅配有 KDE Plasma 桌面环境,且紧跟 Plamsa 桌面的最新更新:并 ...

  5. 微信支付接口,提示:调用支付jsapi缺少参数: $key0$

    下面是 官方给的 帮助文档. 支付返回签名错误 注意签名参数的大小写,支付密钥key要到商户平台设置,设置的规则是32位数字与字母大小写的组合.以下链接为签名过程. (https://pay.weix ...

  6. 微信API接口目录大全

    微信API接口目录大全 1.基础消息类型 1.客户端发送的心跳包HeartBeatReq = 1001;  2.消息接收确认回复(接收或拒绝接收)MsgReceivedAck = 1002;  3.错 ...

  7. 微信JS接口- 企业号开发者接口文档

    目录 1 概述 1.1 使用说明 1.1.1 步骤一:引入JS文件 1.1.2 步骤二:通过config接口注入权限验证配置 1.1.3 步骤三:通过ready接口处理成功验证 1.1.4 步骤四:通 ...

  8. 微信JS接口签名的生成

    简要说明微信JS接口签名的生成方式 签名生成规则 参与签名的字段包括有效的 jsapi_ticket(获取方式详见微信 JSSDK 文档), noncestr (随机字符串,由开发者随机生成),tim ...

  9. 微信小程序控制硬件 第14篇 微信小程序腾讯地图控制 4G Cat.1模组 ,安信可CA-01加载定位显示当前位置。

    文章目录 一.前言 通讯协议 技术问题点 二.4G模组业务逻辑 上报基站信息 三.微信小程序控制 另外,不要把我的博客作为学习标准,我的只是笔记,难有疏忽之处,如果有,请指出来,也欢迎留言哈! 微信物 ...

最新文章

  1. hive的用户和用户权限
  2. opencv在python环境下的安装_python环境下安装opencv库的方法
  3. .NET Core 3.0:System.Data的变化
  4. 【渝粤教育】电大中专学前儿童健康教育_1作业 题库
  5. html 高度不够,HTML/CSS:Div未扩展到内容高度
  6. Linux网络编程--聊天室客户端程序
  7. 学计算机写作文怎么写,关于学电脑的作文
  8. 【每日学习】Apache重写未开启,导致The requested URL /xxxx.html was not found on this server...
  9. [暴力]JZOJ 100036 随机
  10. 2023考研计算机408王道考研网盘资源
  11. 前端商城vue项目案例1
  12. win calc计算器妙用-功能键-编辑键-视图-命令键-脚本-迭代-连分数-批量和-批次高精度-内存-lisp-文本VS代码
  13. 基于深度学习的图像匹配技术一览
  14. Python练习_数据类型_day4
  15. swift [Application] The app delegate must implement the window property if it wants to use a main 报错
  16. 基于Kotlin实现学生信息管理系统【100010063】
  17. 85寸左右电视怎么选 2023年85寸高性价比电视推荐榜单
  18. web靶场 --- sqli-labs
  19. MindMaster思维导图及亿图图示会员 优惠活动
  20. margin-left:-100%理解

热门文章

  1. 2022-2028年全球与中国热真空室行业发展趋势及投资战略分析
  2. Redhat6.5离线配置Zabbix,含自定义Zabbix监控项
  3. 纵然前方困难重重,我们也要一直坚持
  4. 计算机键盘怎么打勾符号,word方框(□)中打钩(√)的3种方法
  5. LeetCode887题:鸡蛋掉落——动态规划法与数学法
  6. 信号满格无去连接服务器,小米10信号满格但是没网络
  7. 开源html5在线音乐网站,一个漂亮的开源HTML5音乐播放器——APlayer
  8. Bugly SDK 集成使用
  9. 关于计算机方面的知识小故事,「计算机小故事」-奇妙的HelloWorld任务
  10. java 双亲委派_JVM双亲委派机制与Tomcat