Django Python Wechat

Source: Internet
Author: User

About Django Development

Using a third-party package WECHAT-PYTHON-SDK

#From wechat_sdk import Wechatbasic#From wechat_sdk.exceptions import parseerror#From wechat_sdk.messages import eventmessage#From Wechat_sdk.context.framework.django import Databasecontextstorewechat_instance=Wechatbasic (Token='spreadassistant.chltec.com', AppID='wxacbc8e8621b5140e', Appsecret='11d1e1723475771e958d1252f6ad045a') @csrf_exemptdefPortal (Request):ifRequest.method = ='GET':        #Legality of inspection        #extracting basic information from request (signature, timestamp, nonce, XML)Signature = Request. Get.get ('Signature') Timestamp= Request. Get.get ('timestamp') nonce= Request. Get.get ('nonce')        if  notWechat_instance.check_signature (Signature=signature, Timestamp=timestamp, nonce=nonce):returnHttpresponsebadrequest ('Verify Failed')        returnHttpResponse (Request. Get.get ('Echostr',"'), content_type="Text/plain")    #POST    #parse the XML data for this request    Try: Wechat_instance.parse_data (Data=request.body)exceptParseError:returnHttpresponsebadrequest ('Invalid XML Data')    #get the parsed request informationMessage =wechat_instance.get_message ()ifisinstance (Message, textmessage):Print 'Receive text message'    elifisinstance (Message, voicemessage):Print 'Receive voice messages'    elifisinstance (Message, imagemessage):Print 'Receive picture message'    elifisinstance (Message, videomessage):Print 'receive a video message'    elifisinstance (Message, linkmessage):Print 'Receive link message'    elifisinstance (Message, locationmessage):Print 'Receive geo-location messages'    elifisinstance (Message, eventmessage):Print 'Receive event message'        #focus on events (including common concerns and scan QR codes for attention events)        #if both key and ticket are not empty, it is a matter of concern to scan the QR code        ifMessage.type = ='Subscribe':            Print 'It's a matter of concern .'        elifMessage.type = ='Unsubscribe':            Print 'This is the cancellation of the attention event'        elifMessage.type = ='Scan':            Print 'This is already concerned about user scanning QR code! '        elifMessage.type = =' Location':            Print 'This is the escalation location .'        elifMessage.type = ='Click':            Print 'This is a custom menu click'        elifMessage.type = ='View':            Print 'This is a custom menu jump link'        elifMessage.type = ='Templatesendjobfinish':            Print 'This is a template message'Reply_text='already responded.'Response= Wechat_instance.response_text (content=reply_text)returnHttpResponse (Response, content_type="Application/xml")

The above code idea is clear, so make a record, but see Https://github.com/doraemonext/wechat-python-sdk said the project has stopped development, recommend the use of https://github.com/ jxtech/wechatpy/as a substitute.

Django Python Wechat

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.