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