微信公眾平台SDK Python


微信公眾平台SDK

項目背景

從2014年開始玩微信公眾平台,試用過其中大多數的功能,如:消息回復、自定義菜單、公眾號中的支付,頁面授權等。之前的程序中都是直接調用公眾平台的接口,這樣復用功能無法實現。現將功能獨立出單獨模塊

目前完成

  • 獲取access_token方法
  • 獲取微信服務器IP地址
  • 自定義菜單中的查詢、創建、刪除(不包括個性化菜單接口)
  • 消息管理中的接收普通消息、接收事件推送
  • 消息管理中的被動回復用戶消息
  • 添加tornado代碼的demo實例

使用示例

獲取access_token方法

from wechat.base import get_access_token_dict  get_access_token_dict(APPID, APPSECRET) 

消息處理基類

繼承基礎的消息處理類BaseHandler, 重寫對應方法即可。 如文本、圖片、視頻等對應的處理方法分別問on_text、on_image、on_video。

from wechat.message import *  class MessageHandler(BaseHandler):    def on_text(self, xml_dict):        from_user = xml_dict['FromUserName']       to_user = xml_dict['ToUserName']       create_time = xml_dict['CreateTime']       content = xml_dict['Content']        text_response = TextResponse(from_user=from_user, to_user=to_user, create_time=create_time, content=content)       return text_response 

自定義菜單接口

from wechat.menu.client import Client  client = Client(access_token['access_token'])  # 創建菜單 client.create_menu(data)  # 獲取菜單 client.get_menu()  # 刪除菜單 client.delete_menu() 

下一步計划

  1. 繼續補充其他常用接口

感興趣的同學可以加入到項目中一起完善

 

github: https://github.com/lyroge/wechat_sdk

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM