Example #1
0
def api_wechat_login():
    global thread
    uuid = itchat.get_QRuuid()
    itchat.get_QR(uuid=uuid, qrCallback=QR_to_b64)
    print(thread.is_alive())
    if thread.is_alive():
        return jsonify({'success': 0, 'msg': '已有登陆线程存在' })

    # thread = task(monitor_login,itchat)
    thread = Thread(target = monitor_login, args = (itchat, ))
    thread.start()
    return jsonify({'success': 1, 'qr': qr_b64.decode("utf-8") })
Example #2
0
def get_qr():
    if not test_connect():
        logger.info(
            "You can't get access to internet or wechat domain, so exit.")
        return None

    global qruuid
    qruuid = itchat.get_QRuuid()
    itchat.uuid = qruuid
    if os.path.exists(qrCode_dir):
        os.remove(qrCode_dir)
    itchat.get_QR(uuid=qruuid, picDir=qrCode_dir, qrCallback=qr_callback)
    return qruuid
Example #3
0
    def open_qr(self):

        for get_count in range(1):

            self.outputWritten('获取uuid中…… ')

            uuid = itchat.get_QRuuid()

            while uuid is None:

                uuid = itchat.get_QRuuid()

                time.sleep(1)

                self.outputWritten('成功获取uuid ')

                if itchat.get_QR(uuid, picDir=r'%s' % os.path.join(current_path, 'qrcode.jpg')):

                    break

                elif get_count >= 1:

                    self.outputWritten("获取二维码出错,请重启程序 ")

            sys.exit()

        return uuid
Example #4
0
def open_QR(id):
    for get_count in range(10):
        output_info('Getting uuid')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        output_info('Getting QR Code')
        if itchat.get_QR(uuid, picDir='images/%s.png' % id): break
        elif get_count >= 9:
            output_info('Failed to get QR Code, please restart the program')
            sys.exit()
    output_info('Please scan the QR Code')
    return uuid


# uuid = open_QR()
# waitForConfirm = False
# while 1:
#     status = itchat.check_login(uuid)
#     if status == '200':
#         break
#     elif status == '201':
#         if waitForConfirm:
#             output_info('Please press confirm')
#             waitForConfirm = True
#     elif status == '408':
#         output_info('Reloading QR Code')
#         uuid = open_QR()
#         waitForConfirm = False
Example #5
0
def hello_world():
    # return 'Hello World!'
    # itchat.login(enableCmdQR=2,hotReload=True,picDir='C:\\Users\laomingming\Pictures\\'+'qr.png')
    # img = itchat.login(hotReload=True)
    # shutil.copy(os.getcwd() + '/' + 'QR.png', '/home/mysite/static/QR.png')

    # byte_io = BytesIO()
    # img.save(byte_io, 'PNG')
    # byte_io.seek(0)
    path = 'C:\\Users\\laomingming\\Pictures\\'
    os.chdir(path)
    os.getcwd()

    a = itchat.get_QRuuid()
    byte_io = itchat.get_QR(a)
    # byte_io = BytesIO()
    # img.save(byte_io, 'PNG')
    # byte_io.seek(0)
    # b.seek(0)
    # b = obj.seek(0)
    print(type(byte_io))
    # byte_io = BytesIO()
    # obj.save(byte_io, 'PNG')
    b = byte_io.seek(0)
    print(type(b))
    return send_file(byte_io, mimetype='image/png')
Example #6
0
def login_weixin(request):
    uuid = itchat.get_QRuuid()
    qrStorage = itchat.get_QR(uuid)
    # t = time.strftime("%Y%m%d %H%M%S")
    # response = HttpResponse(qrStorage.getvalue())
    # response['Content-Type'] = 'image/png'
    # response['Content-Disposition'] = 'attachment;filename="QR_%s.png"' % t
    return HttpResponse(itchat.log)
Example #7
0
        def _entry(self, current_user, app):
            print(self.isLoggedIn, 'self is loggedin')
            if not self.isLoggedIn:
                load_status = self.itchat.load_login_status(
                    'data/itchat{}.pk1'.format(current_user.get_id()))
                print('threadalive1:', threading.active_count())
                print(self.thread.is_alive())
                print(self.qr_img, 'qr_img')
                print(load_status)
                if load_status.get('BaseResponse').get('Ret') == 0:
                    self.isLoggedIn = True
                    self.thread = Thread(target=self.readygo)
                    self.thread.start()
                    self.itchat.dump_login_status('data/itchat{}.pk1'.format(
                        current_user.get_id()))
                    print('threadalive2:', threading.active_count())
                    return None
                uuid = itchat.get_QRuuid()
                itchat.get_QR(uuid=uuid, qrCallback=_qrtrans)

                if self.thread.is_alive() and self.qr_img != 0:
                    return self.qr_img

                if not self.thread.is_alive():
                    print('please Login')
                self.thread = Thread(target=self.monitor_login)
                self.thread.start()

                return self.qr_img
            # 已经登陆微信
            if self.isLoggedIn:

                # wechat 掉线或者登出
                if not self.thread.is_alive():
                    print('threadalive3:', self.thread.is_alive())
                    self.isLoggedIn = False
                    uuid = itchat.get_QRuuid()
                    itchat.get_QR(uuid=uuid, qrCallback=_qrtrans)
                    self.thread = Thread(target=self.monitor_login)
                    self.thread.start()
                    return self.qr_img
                return None
Example #8
0
def get_code():
    """
    获取UUID
    :return:
    """

    uuid = itchat.get_QRuuid()
    if not uuid:
        uuid = itchat.get_QRuuid()
        time.sleep(2)
    code = itchat.get_QR(uuid)
    return code, uuid
Example #9
0
 def open_QR():
     for get_count in range(10):
         output_info('Getting uuid')
         uuid = itchat.get_QRuuid()
         while uuid is None: uuid = itchat.get_QRuuid();time.sleep(1)
         output_info('Getting QR Code')
         if itchat.get_QR(uuid): break
         elif get_count >= 9:
             output_info('Failed to get QR Code, please restart the program')
             sys.exit()
     output_info('Please scan the QR Code')
     return uuid
Example #10
0
def get_qrimg(current_user, app):
    global thread
    global isLoggedIn
    import threading

    if not isLoggedIn:
        #load_status 会开启一个线程
        load_status = itchat.load_login_status('itchat.pkl')
        print('threadalive1:', threading.active_count())
        #服务器接受hotreload,开始数据的初始化
        if load_status.get('BaseResponse').get('Ret') == 0:
            isLoggedIn = True
            thread = Thread(target=ready, args=(app, itchat, current_user))
            thread.start()
            itchat.dump_login_status('itchat.pkl')
            print('threadalive2:', threading.active_count())
            return None

        uuid = itchat.get_QRuuid()
        itchat.get_QR(uuid=uuid, qrCallback=Qr2Img)

        if thread.is_alive():
            return qr_img
        if not thread.is_alive():
            print('please Login')
        thread = Thread(target=monitor_login, args=(itchat, current_user, app))
        thread.start()
        return qr_img
    #已经登陆微信
    if isLoggedIn:
        # wechat 掉线或者登出
        if not thread.is_alive():
            print('threadalive3:', thread.is_alive())
            isLoggedIn = False
            thread = Thread(target=monitor_login,
                            args=(itchat, current_user, app))
            thread.start()
            return qr_img
        return None
Example #11
0
def login():
    # pic = request.headers.get('Host')
    picname = 'weixin'
    qr_path = f'./weixinapp/static/weixin/QRcode/{picname}.png'
    uuid = itchat.get_QRuuid()
    # print(f'24{uuid}')
    qrStorage = itchat.get_QR(uuid=uuid, enableCmdQR=True)
    with open(qr_path, 'wb') as f:
        f.write(qrStorage.getvalue())
    # print(f'28{uuid}')
    return render_template('weixin/login.html',
                           uuid=uuid,
                           qr=picname,
                           note='请使用微信扫描二维码进行登陆!')
Example #12
0
def open_QR():
    for get_count in range(10):
        output_info("正在获取 uuid")
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        if itchat.get_QR(uuid, enableCmdQR=True):
            break
        elif get_count >= 9:
            output_info("获取二维码信息失败 请重新运行程序")
            sys.exit()
    output_info("请扫描二维码")
    return uuid
Example #13
0
def open_QR():
    for get_count in range(10):
        output_info("getting uuid")
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        output_info("getting QR CODE")
        if itchat.get_QR(uuid): break
        elif get_count >= 9:
            output_info("Failed to get QR Code ,restart the program")
            sys.exit()
    output_info("Please scan the QR Code")
    return uuid
Example #14
0
def open_QR():
    global uuid
    for get_count in range(15):
        output_info('Getting uuid')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        output_info('Getting QR code')
        if itchat.get_QR(uuid):
            break
        elif get_count >= 9:
            output_info('没有正常获取二维码,请刷新页面')
        return uuid
    output_info('请扫描二维码')
Example #15
0
def hello(name=None):

    global thread
    uuid = itchat.get_QRuuid()
    itchat.get_QR(uuid=uuid, qrCallback=QR_to_b64)
    print(thread.is_alive())
    if thread.is_alive():
        return render_template('login.html',
                               name=name,
                               info={
                                   'success': 1,
                                   'msg': '已有登陆线程存在',
                                   'qr': qr_b64.decode("utf-8")
                               })

    # thread = task(monitor_login,itchat)
    thread = Thread(target=monitor_login, args=(itchat, ))
    thread.start()
    return render_template('login.html',
                           name=name,
                           info={
                               'success': 1,
                               'qr': qr_b64.decode("utf-8")
                           })
Example #16
0
def open_QR():
    for get_count in range(10):
        output_info("Getting uuid")
        uuit = itchat.get_QRuuid()
        while uuid is None:
            uuitd = itchat.get_QRuuid();
            time.sleep(1)
        output_info("Getting QR code")
        if itchat.get_QR(uuid):
            break
        elif get_coun >= 9:
            output_info("Failed to get QR code, plz restart the program")
            sys.exit()

    output_info("Plz scan the QE Code")
    return uuid
Example #17
0
def open_QR():
    while True:
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        code_img = itchat.get_QR(uuid)
        print(code_img)
        if code_img:
            # add_wx = Wx()
            # add_wx.code = 1
            # add_wx.code_img = code_img
            # add_wx.save()
            break
        time.sleep(1200)
    output_info('Please scan the QR Code')
    return uuid
Example #18
0
def open_qr(com_queue=None):
    for get_count in range(10):
        print ('Getting uuid')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid();
            time.sleep(1)
        print ('Getting QR Code')
        if itchat.get_QR(uuid, enableCmdQR=True, qrCallback=qrcode_handle):
            break
        elif get_count >= 9:
            print ('Failed to get QR Code, please restart the program')
            sys.exit()
    print ('Please scan the QR Code')
    # todo 更新手机显示
    if com_queue:
        com_queue.put({"mode": 1})
    return uuid
Example #19
0
def open_QR():
    for get_count in range(10):
        print('Getting uuid')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        print('Getting QR Code')
        try:
            if itchat.get_QR(uuid): break
            elif get_count >= 9:
                print('Failed to get QR Code, please restart the program')
                sys.exit()
        except ZeroDivisionError:
            print 'div 0 error'

    print('Please scan the QR Code.  uuid = ' + str(uuid))
    return uuid
Example #20
0
def open_QR():
    num=input("请输入今天签到的人数")
    try:
        num=int(num)
    except Exception as e:
        num=1
    for get_count in range(num):
        output_info('Getting uuid')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(10)
            output_info('Getting QR Code')
        if itchat.get_QR(uuid):
            break
        elif get_count >= num:
            output_info('获取二维码出错,请重启程序')
            sys.exit()
            output_info('请重新扫二维码')
    return uuid
Example #21
0
    nicklist = []
    a = 0
    for i in friends:
        signature = i["Signature"].strip().replace("span", "").replace(
            "class", "").replace("emoji", "")
        rep = re.compile("1f\d+\w*|[<>/=]")
        signature = rep.sub("", signature)
        siglist.append(signature)
        nickname = i["NickName"]
        nicklist.append(nickname)
        a = a + 1

    # for i in range(0,a):
    #     print(nicklist[i]+":"+siglist[i]+"\n" )
    # nicklist[i]+":"
    text = "".join(siglist)
    print(text)


# img = itchat.auto_login(enableCmdQR=2,hotReload=True)
uuid = itchat.get_QRuuid()
byte_io = itchat.get_QR(uuid)
id = itchat.check_login(uuid)
if id == 200:
    web = itchat.web_init
    print(web)
    get = itchat.get_contact()
    print(get)

# print (type(itchat.auto_login(enableCmdQR=2,hotReload=True)))
# text()
Example #22
0
#     for get_count in range(10):
#         output_info('Getting uuid')
#         uuid = itchat.get_QRuuid()
#         while uuid is None: uuid = itchat.get_QRuuid();time.sleep(1)
#         output_info('Getting QR Code')
#         if itchat.get_QR(uuid): break
#         elif get_count >= 9:
#             output_info('Failed to get QR Code, please restart the program')
#             sys.exit()
#     output_info('Please scan the QR Code')
#     return

# # uuid =
# open_QR()
uuid = itchat.get_QRuuid()
itchat.get_QR(uuid, picDir="./test.png")
# waitForConfirm = False
# while 1:
#     status = itchat.check_login(uuid)
#     if status == '200':
#         break
#     elif status == '201':
#         if waitForConfirm:
#             output_info('Please press confirm')
#             waitForConfirm = True
#     elif status == '408':
#         output_info('Reloading QR Code')
#         uuid = open_QR()
#         waitForConfirm = False
# userInfo = itchat.web_init()
# itchat.show_mobile_login()
Example #23
0
import itchat
import os
path = os.path.dirname(__file__) + '/QR'
if not os.path.exists(path):
    os.mkdir(path)
    while not itchat.get_QRuuid():
        time.sleep(1)
    itchat.get_QR(picDir=path + '/QR.png')
itchat.auto_login(picDir=path + '/sss.png')
Example #24
0
"""
    如果单纯的使用send函数,需要对发送内容进行标注。
    @fil@:在发送内容前添加,表明是发送文件
    @img@:在发送内容前添加,表明是图片文件
    @msg@:在发送内容前添加,表明是消息
    @vid@:在发送内容前添加,表明是视频文件,视频文件要小于20M
    如果什么都没有添加,默认是消息

"""
# itchat.send("nihao", friend["UserName"])
# chatrooms = itchat.get_chatrooms()
# contact = itchat.get_contact()
# mps = itchat.get_mps()
# msg = itchat.get_msg()
# itchat.get_head_img(friend["UserName"], picDir="1.jpg")
itchat.get_QR(enableCmdQR=True)

# import io
#
# import requests, itchat
#
# url = 'https://avatars3.githubusercontent.com/u/13028340'
# r = requests.get(url, stream=True)
# imageStorage = io.BytesIO()
# for block in r.iter_content(1024):
#     imageStorage.write(block)
# imageStorage.seek(0)
#
# itchat.auto_login(True)
# friend = itchat.search_friends(u"爱自由")[0]     # 搜索内容的字符串格式需要是unicode
# r = itchat.send_image(imageStorage, friend["UserName"])
Example #25
0
def getAuthQr(uuid, qrPath):

    output_info('Getting QR Code')

    return itchat.get_QR(uuid, picDir=qrPath, enablePrintQR=False)