import itchat, requests, json def get_response(msg):#應答程序 url = 'http://www.tuling123.com/openapi/api/v2'#圖靈機器人接口地址 send_msg = {#發送給圖靈機器人的消息格式(json),參考api文檔 "reqType": 0,#文本格式 "perception": { "inputText": { "text": msg #發送的文本內容 }, }, "userInfo": { "apiKey": " ",#機器人apiKey "userId": "363282"#標示用戶 } } try: r = requests.post(url, data = json.dumps(send_msg)).json()#把收到的微信消息發送給圖靈機器人 return r['results'][0]['values']['text']#返回圖靈機器人說的消息,個人微信號只是個搬運工 except: return @itchat.msg_register('Text')#定義消息類型爲文本 def text_reply(msg): return get_response(msg['Text']) itchat.auto_login(True)#掃碼登入微信,和登入網頁版微信同樣 itchat.run()#自動應答