Esempio n. 1
0
 def _start(self):
     itchatmp.update_config(itchatmp.WechatConfig(
         token=WECHAT_TOKEN,
         appId=WECHAT_APP_ID,
         appSecret=WECHAT_APP_SECRET,
         encryptMode=itchatmp.content.SAFE,
         encodingAesKey=WECHAT_ENCODING_AES_KEY),
                            filterRequest=False)
     itchatmp.run()
Esempio n. 2
0
import itchatmp
import rsa
import pickle
import base64

with open('cakey/pri.pem', 'rb') as f:
    prikey = rsa.PrivateKey.load_pkcs1(f.read())

itchatmp.update_config(
    itchatmp.WechatConfig(token='testitchatmp',
                          appId='wx03b5a10f61d8e884',
                          appSecret='7a0bc25cdf7e0ae71ea4c7df54233366'))


def enc(bytestream):
    return base64.b64encode(bytestream).decode('ascii')


def dec(charstream):
    return base64.b64decode(charstream)


@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    message = dec(msg['Content'])
    print(pickle.loads(message))
    return enc(rsa.sign(message, prikey, 'SHA-256'))


itchatmp.run()
Esempio n. 3
0
        'output': 'json',
        'pois': '1',
        'ak': config['baidu']['ak']
    }
    try:
        r = session.get('http://api.map.baidu.com/geocoder/v2/', params=params)
        if r.ok:
            print(r.text)
            data = json.loads(r.text)
            if data['status'] == 0:
                # success
                # 将位置保存到数据库
                city_name = data['result']['addressComponent']['city'][:-1]
                city = db.query(models.City).filter_by(name=city_name).first()
                if city:
                    user.city_id = city.id
                    return f'成功将您的城市更新为{city_name}'
                return '不支持的城市'
            else:
                # todo save into log
                return '解析地理位置失败'
    except:
        # todo save into log
        return ' 链接 GPS 解析失败'


if __name__ == '__main__':
    # models.Base.metadata.create_all(models.engine)
    itchatmp.run(port=8000)
    print(itchatmp.send('123', config['wechat']['admin']))
Esempio n. 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itchatmp

itchatmp.update_config(
    itchatmp.WechatConfig(token='hello2018',
                          appId='wx1f1d5a54a37112401',
                          appSecret='9a1eac4f7c6f8e284e102247a8f877691'))


@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    return msg['Content']


itchatmp.run(port=5000)
Esempio n. 5
0
            raise (Exception)
        else:
            print('get unknown resp')
            raise (Exception)

    def wechat_login(self):  # 自动登陆微信
        self.get_token()
        if self.is_test:
            print(u'本地测试开启')
            itchatmp.update_config(
                itchatmp.WechatConfig(token=self.token,
                                      appId=self.appid,
                                      appSecret=self.app_secret))
        else:
            itchatmp.update_config(
                itchatmp.WechatConfig(token=self.token,
                                      appId=self.appid,
                                      appSecret=self.app_secret))
            print(u'微信登陆成功')
            itchatmp.set_logging(loggingLevel=10)

            @itchatmp.msg_register(itchatmp.content.TEXT)
            def text_reply(msg):
                return msg['Content']


if __name__ == '__main__':
    sw = send_message_to_wechat()
    sw.wechat_login()
    itchatmp.run()  # 扫描二维码并登陆
Esempio n. 6
0
@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    return msg_handler.msg_handle(msg)


def encrypt_passwords():
    import buu_model, buu_database
    database_op = buu_database.class_database_op()
    exist_cards = buu_model.class_model.Card.select()

    for card in exist_cards:
        database_op.save_card_info(card.user.id, card.user_name, card.password)


buu_model.class_model.init()

msg_handler = buu_msg_handle.class_msg_handle()

class_database_op = buu_database.class_database_op()
# class_database_op.flush_redis()

buu_thread_card.class_init_thread_supervisor()

buu_thread_lib.class_init_thread_supervisor()

buu_thread_keepalive.class_init_thread()

# encrypt_passwords()

itchatmp.run(port=6490)
Esempio n. 7
0
# coding=utf8
import random
import itchatmp
from itchatmp.content import (TEXT, MUSIC, IMAGE, VOICE, VIDEO, THUMB, NEWS,
                              CARD, SAFE)
from mp_base import get_response, text_list
from poet_base import query_luck, query_page, query_luck_word

# **************************************************

# 一小瓶陶瓷订阅号
itchatmp.update_config(
    itchatmp.WechatConfig(token='xxx', appId='xxx', appSecret='xxx'))


@itchatmp.msg_register(TEXT)
def text_reply(msg):
    if "1" in msg["Content"]:
        reply = random.choice(text_list)
    elif "2" in msg["Content"]:
        reply = query_luck()
    elif "3" in msg["Content"]:
        reply = query_luck_word()
    else:
        reply = get_response(msg['Content'])
    return reply


itchatmp.run(port=8899)
Esempio n. 8
0
        'output': 'json',
        'pois': '1',
        'ak': config['baidu']['ak']
    }
    try:
        r = session.get('http://api.map.baidu.com/geocoder/v2/', params=params)
        if r.ok:
            print(r.text)
            data = json.loads(r.text)
            if data['status'] == 0:
                # success
                # 将位置保存到数据库
                city_name = data['result']['addressComponent']['city'][:-1]
                city = db.query(models.City).filter_by(name=city_name).first()
                if city:
                    user.city_id = city.id
                    return f'成功将您的城市更新为{city_name}'
                return '不支持的城市'
            else:
                # todo save into log
                return '解析地理位置失败'
    except:
        # todo save into log
        return ' 链接 GPS 解析失败'


if __name__ == '__main__':
    # models.Base.metadata.create_all(models.engine)
    itchatmp.run(port=8000)
    print(itchatmp.send('123', config['wechat']['admin']))
Esempio n. 9
0
    # print(msg)
    # 设置延迟回复
    time.sleep(0.2)
    if msg["MsgType"] == "text":
        if msg["Content"] == u'【收到不支持的消息类型,暂无法显示】':
            # 图片回复
            reply = pictureReply()
        else:
            reply = get_response(msg["Content"])
        return reply
    if msg["MsgType"] == "image":
        # reply = pictureReply()
        reply = u"接收到图片"
        return reply
    if msg["MsgType"] == "event":
        # print("hhh")
        if msg["Event"] == "subscribe":
            # print("关注")
            reply = u"你好,欢迎关注squirrel"
            return reply
        if msg["Event"] == "unsubscribe":
            # print("取消关注")
            return
        else:
            return
    else:
        return


app = itchatmp.run(isWsgi=True)
Esempio n. 10
0
File: main.py Progetto: daiybh/wxBot
                city = db.query(models.City).filter_by(name=city_name).first()
                if city:
                    user.city_id = city.id
                    return f'成功将您的城市更新为{city_name}'
                return '不支持的城市'
            else:
                # todo save into log
                return '解析地理位置失败'
    except:
        # todo save into log
        return ' 链接 GPS 解析失败'


def get_fn(handler):
    db = models.DBSession()
    sXml = ''
    for row in db.query(models.User).all():
        print(row, row.name)
        sXml += "<li>" + row.name + "</li>"

    db.commit()
    db.close()
    return "main_get_fun" + sXml


if __name__ == '__main__':
    # models.Base.metadata.create_all(models.engine)
    itchatmp.run(port=80, getFunc=get_fn)
    r = itchatmp.messages.send_all(itchatmp.content.TEXT, "bye")
    print(r)
Esempio n. 11
0
@itchatmp.msg_register(itchatmp.content.EVENT)
def subscribe_reply(msg):
    user_id = msg['FromUserName']
    if msg['Event'] == 'subscribe':
        print("receive event: subscribe")
        return reply_to_user(ChatBot().reply_to_subscribe(user_id), user_id)
    elif msg['Event'] == 'SCAN':
        print("receive event: SCAN")
        return reply_to_user(
            ChatBot().reply_to_order_pay(user_id, msg['EventKey']), user_id)
    # elif msg['Event'] == 'CLICK' :
    #     print("receive event: CLICK")
    #     role_id = msg['EventKey']
    #     USER.set_role(user_id, role_id)
    #     return USER.role_modified_reply(role_id)
    return ''


#########################################################
# @itchatmp.msg_register(itchatmp.content.IMAGE)
# def image_reply(msg):
#     user_id = msg['FromUserName']
#     media_id = msg['MediaId']
#     image_url = msg['PicUrl']
#     picture_id = get_picture_id(media_id)
#     return reply_to_user(ChatBot().reply_to_media(user_id, picture_id, image_url, media_id), user_id)

#########################################################
# register_menu()
itchatmp.run(port=config.HTTP_PORT)
Esempio n. 12
0
    if msg['Event'] == 'CLICK':

        if msg['EventKey'] == 'subscribed_event':
            print("handle subscribed_event for {} {}".format(nickname, openId))
            # get tag list
            tag_list = itchatmp.users.get_user_info(openId)['tagid_list']
            subscribed = [tag_dict_id2name[t] for t in tag_list]
            content = "您目前已订阅的事件有:\n{}".format(','.join(subscribed))
            return content

        if msg['EventKey'] == 'subscribe_event':
            print("handle subscribe_event for {} {}".format(nickname, openId))
            event_names = ','.join(EVENT_NAME_C2E.keys())
            content = '回复 E+事件名 可订阅该事件,您将在每天上午8点半左右' \
                      '获得一条含有该事件列表的消息推送。\n\n' \
                      '比如回复: E增持, 便可订阅增持事件。\n\n' \
                      '目前支持的事件有:\n{}。'.format(event_names)
            return content

        if msg['EventKey'] == 'about_us':
            print("handle about_us for {} {}".format(nickname, openId))
            content = "YearOne(新晋元年)是一家创业中的量化对冲基金公司。" \
                      "创始团队具有多年、多市场、多交易标的的投资经验,并以" \
                      "最严格的合规性与职业道德准准则来要求自己,通过借助" \
                      "交叉学科的力量持续创新,不停改进自己的投资方法。"
            return content


itchatmp.run(debug=True)