- 先找到人群 openid导出成csv
1
2
3CSV.open('/home/ubuntu/20190417-openids.csv', 'a+') do |csv|
User.all.find_each {|user| openids << [user.wondercv_openid]}
end
文章发给自己预览
1
2
3
4
5
6
7
8
9items = [
{ thumb_media_id: Wechat.api.media_create('image', '/opt/wondercv_files/0514summer-vacation.png')["media_id"],
author: 'xxx', title: 'xxx',
content_source_url:'https://www.wondercv.com/cvs',
content: File.read("/opt/wondercv_files/wx_content1.html"), digest: "xxx",
show_cover_pic: 0 }\nxxx
]
result = Wechat.api.media_uploadnews(Wechat::Message.new(MsgType: 'mpnews').mpnews(items))
Wechat.api.message_mass_preview(Wechat::Message.to("oodHF0pynBim76dsu7tGKVTui_Vs").ref_mpnews(result["media_id"]))#预览查看发给用户
1
2
3
4
5
6
7
8
9
10
11Wechat.api.class_eval do
def message_mass_send(message)
post 'message/mass/send', message.to_json
end
end
send_result = []
openids.each_slice(8000).to_a.each do |ids|
a = Wechat.api.message_mass_send(Wechat::Message.to(ids, send_ignore_reprint: 1).ref_mpnews(result["media_id"]))
send_result << a
end
Wechat.api.message_mass_get(msg_id)
8000一个任务 这个会分成多个send result 状态分别有DELETE SENDING SEND_SUCCESS
一次最多发1W