某网站的微信营销群发实现
- 抓取商品信息整理成图片带二维码的形式,最终形式类似淘宝上搜索的结果
- 通过控制器发送特别款号,带款式说明,特性
大致就是itchat的使用与一些简单的抓包,另外还涉及到一些图片的处理,微信发图片有限制,之前有加过队列来处理,后面实际上使用很少
功能:从控制群发出指定款号,带上特别的信息,最后生成特定的图片发送到微信群,实现群控营销,可以批量发很多的群,群多的时候,发送消息的间隔要长一点,不然图片会被微信屏蔽,无法发出
# coding:utf-8
import itchat
import importlib
import sys
import time
import copy
from itchat.content import *
import json
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.schedulers.background import BackgroundScheduler
import qrcode
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import os.path
import random
import xlrd
import file as myFile
import multiprocessing as mp
from multiprocessing import Manager
#import multiprocessing Queue
import re
import requests
import os
os.makedirs('./image/', exist_ok=True)
os.makedirs('./infomation/', exist_ok=True)
os.makedirs('./codeImage/', exist_ok=True)
os.makedirs('./tempImage/', exist_ok=True)
os.makedirs('./WXCodeImage/', exist_ok=True)
global schedule;
global starttime;
global p;
global dumpfile;
global addflag;
global q;
# 二维码样式,1表示网站二维码,2表示小程序二维码,默认是网站二维码
codeType = 1
#
groomlist=[
'影儿商城-精品群-小杨', #小杨 0
'影儿商城-会员1群-张金', #张金 1
'影儿商城-会员2群-张金', #张金 2
'发款群',
];
#推荐人id,可以改成自己的ID
memberid="1795466";
sendNickName="@小海"
#改群功能
sendgroup=u"发款群";
groupSources={};
infotip=u"长按查看商品详情"
insungroup='【恩裳】- 新零售二群';
zkqgroup='找款群'
#这个是发送任时间全局的,任务会一直增长
sendtime=0;
#这个是款号任务列表
tasklist=[];
#这个是查询到的信息列表
dictlist=[];
#这个是memberid列表
memberidset=set('1795466');
#这个是sheet里面的内容
contents=[];
insumSizeInfo=[];
result=[];
sendgoodids=[];
psalterids={};
#################
def initGroupSources():
data={'roomid':'xxx','memberid':'1795466','flag':'1'};
for group in groomlist:
groupSources[group]=copy.deepcopy(data);
def setMemberId():
groupSources['影儿商城-会员1群-张金']['memberid']='1795466';
groupSources['影儿商城-会员2群-张金']['memberid']='1795466';
# 小杨
groupSources['影儿商城-精品群-小杨']['memberid']='1795466'; #小杨
groupSources[sendgroup]['flag']=0
groupSources[groomlist[0]]['flag']=1;
groupSources[groomlist[1]]['flag']=1;
groupSources[groomlist[2]]['flag']=1;
#memberidset
def initMemberidSet():
memberidset=set();
for r in groupSources:
if len(groupSources[r]['roomid'])<10:
continue;
memberidset.add(groupSources[r]['memberid']);
#初绐化数据
def initData():
# initSheetData();
initGroupSources();
setMemberId();
initMemberidSet();
#读取款号
def readTaskList():
pass
# filename='/款号.txt';
# file1 = myFile.File();
# print("读取款号")
# with file1.open(filename) as f:
# for line in f:
# line = myFile.delete_line_breaks(line)
# if line not in tasklist:
# tasklist.append(line);
# print(line);
def resizeImg(souceimg):
img = Image.open(souceimg)
w,h = img.size;
destw = 450.0
rw = destw/w
if w > h:
rw = destw/w
else:
rw = destw/h
nw = int(w*rw)
nh = int(h*rw)
img = img.resize((nw,nh),Image.ANTIALIAS)
return img
def makeCodeWithHeaderImage(url,memberid):
registerUrl = "http://mall.yingerfashion.com/yinger-m/index.html#/loginView?member_id=%s&store_id=%s"%('memberid','memberid')
homeUrl = "http://mall.yingerfashion.com/yinger-m/index.html#/homeView?store_id=2674273"
qr = qrcode.QRCode(version=5, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=8, border=4)
qr.add_data(url)
qr.make(fit=True)
img = qr.make_image()
img = img.convert("RGBA")
icon = Image.open("%s.jpg"%memberid) # 这里是二维码中心的图片
img_w, img_h = img.size
factor = 4
size_w = int(img_w / factor)
size_h = int(img_h / factor)
icon_w, icon_h = icon.size
if icon_w > size_w:
icon_w = size_w
if icon_h > size_h:
icon_h = size_h
icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS)
w = int((img_w - icon_w) / 2)
h = int((img_h - icon_h) / 2)
icon = icon.convert("RGBA")
img.paste(icon, (w, h), icon)
# img.show() # 显示图片,可以通过save保存
# img.save('xufeicode.png')
return img
# tagName 精选秒杀
# def makeCodeImage(souceimg,url,title,price,memberid,buyCount,tagName='',features='',scheme_price='',goodid=''):
def makeCodeImage(souceimg, dict, amemberid='1795466'):
url = dict['url'] + amemberid
title = dict['title']
price = dict['price']
buyCount = dict['buyCount']
tagName = dict['tagName']
features = dict['features']
scheme_price=dict['scheme_price']
goodid = dict['id']
memberid = amemberid
#缩放图片
offset = 20
infoImg1 = resizeImg(souceimg)
#二维码图片
# qrimg = qrcode.make(url);
qrimg=''
# 这里是正常的网站的二维码
if codeType==1:
qrimg = makeCodeWithHeaderImage(url, memberid)
# 这里是小程序的二维码
else:
qrimg = Image.open('./WXCodeImage