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()
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']
# coding=utf-8 import itchat import itchatmp import admin_config import msg_handler itchatmp.update_config( itchatmp.WechatConfig(token=admin_config.token, appId=admin_config.appId, appSecret=admin_config.appSecret)) @itchatmp.msg_register(itchatmp.content.INCOME_MSG) def text_reply(msg): msg_type = msg['MsgType'] if msg_type == 'text': print(msg) toUserName = msg['FromUserName'] content = msg['Content'] ret_msg = msg_handler.do_action(content) return ret_msg elif msg_type == 'event': print(msg) content = msg['Event'] if content == 'subscribe': return '欢迎关注本公众号,可以输入【指令】查看可以操作的内容。' return '' if __name__ == '__main__': itchatmp.run()
#!/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)
import itchatmp itchatmp.update_config( itchatmp.WechatConfig(token='yourToken', appId='yourAppId', appSecret='yourAppSecret')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): return msg['Content'] itchatmp.run()
import config from chatbot import ChatBot from register_menu import register_menu from user_id import UserId ######################################################### logger = logging.getLogger('wechat') USER = UserId() ######################################################### # for production environment ######################################################### itchatmp.update_config( itchatmp.WechatConfig( token=config.TOCKEN, appId=config.APP_ID, appSecret=config.APP_SECRET, encryptMode=itchatmp.content.SAFE if config.ENCRYPT else itchatmp.content.NORMAL, encodingAesKey=config.ENCODING_AES_KEY if config.ENCRYPT else '')) ######################################################### def get_image_name_from_url(tag, url): fileName = url.split('=')[-1] return fileName def fetch_image(tag, url): result = requests.get(url) if result.status_code != 200: logger.error('fetch image {} failed!'.format(url))
print(str(response)) sendMsg = response['text'] time.sleep(1) while True: url_get = 'https://api.weibo.com/webim/2/direct_messages/conversation.json?uid={}&source={}'.format( uid, source) response = requests.get(url_get, headers=headers).json() getMsg = response['direct_messages'][0]['text'] if sendMsg == getMsg: time.sleep(1) else: return getMsg itchatmp.update_config( itchatmp.WechatConfig(token='crystal901217', appId='wx4b4055dd0d06f37e', appSecret='84d49e751a3b04c56296444cca23d89c')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): print('from user:'******'FromUserName']) print('get message:' + "\n" + msg['Content']) if msg['Content'].startswith('垃圾分类'): trash_name = msg['Content'].replace('垃圾分类', '').strip() print('trash name:' + trash_name) return get_trash_category(trash_name) defaultReply = '[自动回复]已收到消息,谢谢' reply = tuling_get_response(msg['Content']) # tuling_get_response if reply: print('ai reply with:' + reply)
import itchatmp import test # 配置微信公众号信息 itchatmp.update_config(itchatmp.WechatConfig( token='pjhubs', appId = 'wx02fb9d00f976e7f0', appSecret = 'wx02fb9d00f976e7f0')) # 接收用户消息 @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): toUserName = msg['FromUserName'] content = msg['Content'] isContain = 0; # pjhubs.txt为有权限的用户列表 f = open("pjhubs.txt","r") lines = f.readlines() for line in lines: if line[:-1] == toUserName: isContain = 1; if isContain == 0: return '该系统并未对您开放,请联系PJ进行配置' else: if content == '添加': # test.addNewUnit('tempUnit', 1, 2) return '操作成功!' elif content == '开灯': return test.updateStatusWithHardware('hardware', 1, 'redLED', 1) elif content == '关灯':
# 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)
import redis # coding=utf-8 from pymongo import MongoClient import datetime import logging import itchatmp from itchatmp.content import TEXT,SAFE logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s') itchatmp.update_config(itchatmp.WechatConfig( token='xxx', copId='xxx', appSecret='xxx', encryptMode=itchatmp.content.SAFE, encodingAesKey='xxxxx', )) def getDate(): now = datetime.datetime.now().strftime("%Y%m%d") return now def getTime(): now = datetime.datetime.now().strftime("%Y-%m-%d ") return now class LOG: @staticmethod # 中间件--tcp服务 def middle(): logger = logging.getLogger('%s:%d' % ("MIDDLE", 9876))
import utils, os import buu_config import buu_msg_handle import buu_database import sys import buu_model import buu_thread_keepalive import buu_thread_card import buu_thread_lib import buu_command_dict itchatmp.update_config( itchatmp.WechatConfig( token=buu_config.config.weixin_token, appId=buu_config.config.weixin_appid, appSecret=buu_config.config.weixin_appsecret, encryptMode=itchatmp.content.SAFE, encodingAesKey=buu_config.config.weixin_encoding_aeskey, )) menu = buu_config.config.wechat_menu r = itchatmp.menu.create(menu) @itchatmp.msg_register(itchatmp.content.EVENT) def user_management(event): if event['Event'] == 'subscribe': return buu_command_dict.class_command_dict.step_0_tips('', '', 0)
import itchatmp import json import requests # 微信公众号Token token = 'RICKJIANG' itchatmp.update_config(itchatmp.WechatConfig( token=token, appId='your_appid', appSecret='your_appSecret')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): analysis_result = get_result(msg['Content']) print(analysis_result) text = analysis_result['text'] items = analysis_result['items'] items = items[0] return '哈喽,你分析的句子是:' + text + '\n它属于积极倾向的可能性是:' + str(items['positive_prob']) + '\n它属于消极倾向的可能性是:' + str( items['negative_prob']) # 调用百度API——情绪分析 def get_result(analysis_data): # 获取access_token host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials' \ '&client_id=your_client_id&client_secret=your_client_secret' r = requests.get(url=host) access_token = json.loads(r.text)['access_token']
@Created : 2017/3/8 @Last Modified : 2017/3/8 """ from pprint import pprint import itchatmp import requests import models import json from itchatmp.content import TEXT, SAFE, LOCATION from config import config itchatmp.update_config(itchatmp.WechatConfig( token=config['wechat']['token'], appId=config['wechat']['appid'], appSecret=config['wechat']['app_secret'])) session = requests.session() def command(cmd, user): c = cmd.split('_')[0] t = cmd.split('_')[1:] if c == 'name' and len(t) > 0: user.name = t[0] return f'你的名字设置为: {user.name}' elif c == 'help': return """使用说明: 修改名字: \\name_<你的新名字> 发送地理位置更新你所在的城市
# coding=utf8 import itchatmp import random, os, time from itchatmp.content import (TEXT, MUSIC, IMAGE, VOICE, VIDEO, THUMB, NEWS, CARD, SAFE) from tuling import get_response itchatmp.update_config( itchatmp.WechatConfig(token='squirrel', appId='wx28cd173c32454d59', appSecret='f740cea1c5027526c56ead4eb12814db'), ) word_faces = [ u"✪ω✪", u'✷(ꇐ‿ꇐ)✷', u"。◕‿◕。", u"(๑→ܫ←)", u"(-人-) [拜佛] ", u"(。﹏。*)", u"(*/ω\*)", u" ( *^-^)ρ(^0^* )", u"(●'◡'●)ノ♥", u"( ◔ ڼ ◔ )", u"( ´◔ ‸◔`)", u"(・ω< )★", u"(♥◠‿◠)ノ", u'(*^-^*)', u"(☍﹏⁰)", u"(。◕ˇ∀ˇ◕)", u"✪ω✪", u"~Ⴚ(●ტ●)Ⴢ~", u"(,,Ծ‸Ծ,,)", u"(๑◕ܫ←๑)b", u"v( ^-^(ё_ёゝ", u"(๑→ܫ←)", u"(˘❥˘)", u"(╬▔^▔)凸", u"(✿◡‿◡)", u"o( ̄▽ ̄)d", u"(;′⌒`)", u"(ˉ▽ ̄~) 切~~", u"╰(*°▽°*)╯", u" ( 。ớ ₃ờ)ھ", u"◔ ‸◔?", u"╮(๑•́ ₃•̀๑)╭", u"٩(๑´0`๑)۶", u"(//▽//)", u"(๑•́ ₃ •̀),", u"( ´◔ ‸◔`) ", u"(..•˘_˘•..)", u"๑乛◡乛๑ ", u"(๑→‿ฺ←๑)", u"♥(。→v←。)♥", u"(๑>ڡ<)☆", u"(╯’ – ‘)╯︵ ┻━┻", u"(•‾̑⌣‾̑•)✧˖°", u"(´∩`。) ", u" º·(˚ ˃̣̣̥᷄⌓˂̣̣̥᷅ )‧º·˚", u" (`◕‸◕´+) ", u"(o゚ω゚o)", u"(ΦωΦ)", u" (*′∇`*)", u"( ̄y▽ ̄)~*", u"------\(˙<>˙)/------", u"(#‵′)凸 ", u"(;°○° ) ", u" ٩(͡๏̯͡๏)۶ ", u"( _ _)ノ|扶墙", u"(^∀^)", u"(•̀ᴗ•́)و ̑̑ " ] def get_current_dir(): file_dir = os.path.dirname(os.path.abspath(__file__)) # print("当前目录:",file_dir) return file_dir
import itchatmp from itchatmp.content import TEXT itchatmp.update_config( itchatmp.WechatConfig(token='myniracler123', appId='wx99b26a5cca5da7f8', appSecret='77dd28bab1cb0383d5b8b8b4f63e5728')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): itchatmp.send("hello") return msg['Content'] itchatmp.run()
#!/opt/conda/bin/python3 # -*- coding: utf-8 -*- import itchatmp import lib.tuling as tuling import lib.wechat import traceback import settings from pprint import pprint import pymongo itchatmp.update_config(itchatmp.WechatConfig( token = settings.WC_CHAT_TOKEN, copId = settings.WC_CHAT_CORP_ID, appSecret = settings.WC_CHAT_SECRET, encryptMode = itchatmp.content.SAFE, encodingAesKey = settings.WC_CHAT_AESKEY)) r2d2 = tuling.tuling(settings.TULING) wc_api = lib.wechat.wechat_corp(settings.WC_CHAT_CORP_ID,\ settings.WC_CHAT_AGENT_ID,\ settings.WC_CHAT_SECRET) @itchatmp.msg_register(itchatmp.content.INCOME_MSG) def text_reply(msg): try: print(msg) #msg = json.loads(msg) if 'MsgType' not in msg: return
@Created : 2017/3/8 @Last Modified : 2017/3/8 """ from pprint import pprint import itchatmp import requests import models import json from itchatmp.content import TEXT, SAFE, LOCATION from config import config itchatmp.update_config( itchatmp.WechatConfig(token=config['wechat']['token'], appId=config['wechat']['appid'], appSecret=config['wechat']['app_secret'])) session = requests.session() def command(cmd, user): c = cmd.split('_')[0] t = cmd.split('_')[1:] if c == 'name' and len(t) > 0: user.name = t[0] return f'你的名字设置为: {user.name}' elif c == 'help': return """使用说明: 修改名字: \\name_<你的新名字> 发送地理位置更新你所在的城市
# -*- coding: utf-8 -*- """ This module demonstrates documentation as specified by the `Google Python Style Guide`_. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text. """ import itchatmp itchatmp.update_config( itchatmp.WechatConfig(token='WeiXinToken', appId='wx1e24d19a5e54862d', appSecret='af687455ff78f497bc4e0ed26930512a')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): """ Example function with PEP 484 type annotations. Args: msg: The first parameter. Returns: The return value. True for success, False otherwise. """ # text_reply return msg['content'] itchatmp.run()
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()
import itchatmp import os import sys import time import csv import re import hashlib import urllib.request import urllib.parse import json import chardet itchatmp.update_config( itchatmp.WechatConfig(token='token', appId='appId', appSecret='appSecret', encryptMode=itchatmp.content.SAFE, encodingAesKey='encodingAesKey')) text = { 'ToUserName': '******', 'FromUserName': '******', 'CreateTime': '时间', 'MsgType': '消息类型', 'Content': '消息内容' } whitelist = {'o6xE150NmUB1heMXnZx8uxpyViX0': '时空'} def dataRead(userDataFile, userData): if not os.path.exists(userDataFile):
import itchatmp itchatmp.update_config( itchatmp.WechatConfig(token='YearoneInvest', appId='wxb6c1126cee0cb7a6', appSecret='4bcf6c3e704f7f27af33f53daab5bc66')) leoId = 'o76L3w8Qg94y3efLpwm_Caor8oxw' def send_leo(message): r = itchatmp.send(message, leoId) print(r)
import itchatmp from itchatmp.content import TEXT itchatmp.update_config( itchatmp.WechatConfig(token='123', appId='wx4ee76049687c28b4', appSecret='fd31941e5cec53ae1bf2a2ce97c3a9bb')) @itchatmp.msg_register(itchatmp.content.TEXT) def text_reply(msg): print(msg) return 'I received: ' + msg['Text'] itchatmp.run()