近日,因公司业务需要,需将原两个公众号合并为一个,即要将其中一个公众号(主要是粉丝)迁移到另一个公众号。按微信规范,同一用户在不同公众号内的 openid 是不同的,我们的业务系统不例外地记录了用户的 openid,因此,涉及到两个公众号的 openid 的转换。幸好,微信公众号平台在账号迁移描述提供了方法和API供调用,详见:
http://kf.qq.com/faq/170221aUnmmU170221eUZJNf.html
这里使用 Python 写个程序来完成,简单快捷,主要知识点有:
- MySQL connector 使用,也就是 Python DB API 规范
- HTTP客户端库 requests 使用
- 微信公众号平台 API 使用
首先,建立新旧 openid 对照表。
CREATE TABLE change_openidlist( id BIGINT NOT NULL AUTO_INCREMENT, ori_openid varchar(100) NOT NULL, new_openid varchar(100) NOT NULL, CONSTRAINT crm_change_openidlist_pk PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ;
如果没有安装,则需先安装以下类库。
pip install mysql-connector-python pip install requests
接着,运行下面 python 程序,即可将新旧 openid 对照数据写到 change_openidlist,然后就可以根据这个表的数据去更新其它数据表了。
其它可见注释,不详述,当然不要忘了将 appid 和 secret 替换为自己公众号。
# -*- coding: utf-8 -*- import requests import mysql.connector def handle_data(): try: token = get_access_token() #自动提交方式 autocommit=True conn = mysql.connector.connect(host='127.0.0.1', port='3306', user='user', password='password', database='wx', use_unicode=True,autocommit=True); qcursor = conn.cursor(buffered=True) wcursor = conn.cursor() #旧公众号 openid qcursor.execute('select openid from wxmembers') size = 100 while True: list = qcursor.fetchmany(size) if not list: break changeopenid_list = get_changeopenid_list(list,token) wcursor.executemany('insert into change_openidlist (ori_openid,new_openid) values (%s, %s)',changeopenid_list) except mysql.connector.Error as e: print ('Error : {}'.format(e)) finally: qcursor.close wcursor.close() conn.close print 'openid handle finished!' def get_access_token(): new_appid = '00000' new_secret = '11111' url = 'https://api.weixin.qq.com/cgi-bin/token"color: #ff0000">总结以上所述是小编给大家介绍的使用 Python 实现微信公众号粉丝迁移流程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“使用 Python 实现微信公众号粉丝迁移流程”评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍