使用Python怎么迁移微信公众号粉丝

  介绍

使用Python怎么迁移微信公众号粉丝?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

首先,建立新旧openid对照表。

CREATE  TABLE  change_openidlist (   id 才能BIGINT  NOT  NULL  AUTO_INCREMENT,   ori_openid 才能varchar (100), NOT 空,   new_openid 才能varchar (100), NOT 空,   CONSTRAINT 才能crm_change_openidlist_pk  PRIMARY  KEY  (id)   ),引擎=InnoDB  DEFAULT  CHARSET=utf8 整理=utf8_general_ci ;

如果没有安装,则需先安装以下类库。

pip  install  mysql-connector-python   pip  install 

接请求着,运行下面python程序,即可将新旧openid对照数据写到change_openidlist,然后就可以根据这个表的数据去更新其它数据表了。

其它可见注释,不详述,当然不要忘了将appid和秘密替换为自己公众号。

#, - *安康;编码:utf-8  - * -   import 请求   import  mysql.connector   def  handle_data ():   尝试才能:   ,,,token =, get_access_token ()   ,,,#自动提交方式,自动提交=True   ,,,conn =, mysql.connector.connect(主机=& # 39;127.0.0.1 # 39;,,端口=& # 39;3306 & # 39;,,用户=& # 39;用户# 39;,,密码=& # 39;密码# 39;,,数据库=& # 39;天气# 39;,,use_unicode=True, autocommit=True);   ,,,qcursor =, conn.cursor(缓冲=True)   ,,,wcursor =, conn.cursor ()   ,,,#旧公众号,openid   ,,,qcursor.execute (& # 39; select  openid 得到wxmembers& # 39;)   ,,,size =100   ,,,while 正确的:   ,,,,,list =, qcursor.fetchmany(大小)   ,,,,,if  not 清单:   ,,,,,,,休息   ,,,,,changeopenid_list =, get_changeopenid_list(列表,令牌)   ,,,,,wcursor.executemany (& # 39; insert  into  change_openidlist  (ori_openid new_openid), values  (% s,, % s) & # 39;, changeopenid_list)   except 才能;mysql.connector.Error  as  e:   ,,,print  (& # 39; Error : {} & # 39; .format (e))   最后才能:   ,,qcursor.close   ,,,wcursor.close ()   ,,conn.close   ,,,print  & # 39; openid  handle 完成! & # 39;   def  get_access_token ():   时间=new_appid 才能;& # 39;00000 & # 39;   时间=new_secret 才能;& # 39;11111 & # 39;   时间=url 才能;& # 39;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential& # 39;, #, grant_type为固定值   payload 才能=,{& # 39;appid& # 39;:, new_appid,, & # 39;秘密# 39;:,new_secret}   r 才能=,requests.get (url, params =,有效负载)   时间=response 才能;r.json ()   return 才能响应[& # 39;access_token& # 39;】   def  get_changeopenid_list (ori_openid_list,令牌):   new_access_token =,才能令牌   时间=ori_appid 才能;& # 39;33333 & # 39;   时间=url 才能;& # 39;http://api.weixin.qq.com/cgi-bin/changeopenid?access_token=& # 39; + new_access_token   payload 才能=,{& # 39;to_appid& # 39;:, ori_appid,, & # 39; openid_list& # 39;:, ori_openid_list}   r 才能=,requests.post (url, json =,有效负载)   时间=response 才能;r.json ()   result_list 才能=,响应[& # 39;result_list& # 39;】   openid_list 才能=,[[结果[& # 39;ori_openid& # 39;],结果[& # 39;new_openid& # 39;]], for  result 拷贝result_list  if 结果[& # 39;err_msg& # 39;],==, & # 39;好吧,)   return  openid_list才能   if  __name__ ==, & # 39; __main__ # 39;:   handle_data才能()

关于使用Python怎么迁移微信公众号粉丝问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

使用Python怎么迁移微信公众号粉丝