<commit_before># -*- coding:utf-8 -*-
#from django.shortcuts import render
from mezzanine.utils.views import render
from django.http import HttpResponse
import hashlib, lxml, time
from lxml import etree

# Create your views here.
def wechatInterface(request):
	if request.method=="GET":
		signature=request.GET.get("signature")
		timestamp=request.GET.get("timestamp")
		nonce=request.GET.get("nonce")
		echostr=request.GET.get("echostr")
		token="zh<PASSWORD>"
		list=[token,timestamp,nonce]
		list.sort()
		sha1=hashlib.sha1()
		map(sha1.update,list)
		hashcode=sha1.hexdigest()
		if hashcode == signature:
			return HttpResponse(echostr)
		return HttpResponse("error!")
	elif request.method=="POST":
		xml_str=request.body
		xml=etree.fromstring(xml_str)
		toUser=xml.find("ToUserName").text
		fromUser=xml.find("FromUserName").text
		createTime=xml.find("CreateTime").text
		msgType=xml.find("MsgType").text
		if msgType=="event":
			content=xml.find("Event").text
			if content=="subscribe":
				replyContent=u"欢迎使用智能硬件服务号，您将可以通过本服务号控制您的智能硬件，相关功能正在玩命开发中，敬请期待！"
				reply='''
					<xml>
					<ToUserName><![CDATA[%s]]></ToUserName>
					<FromUserName><![CDATA[%s]]></FromUserName>
					<CreateTime><![CDATA[%s]]></CreateTime>
					<MsgType><![CDATA[text]]></MsgType>
					<Content><![CDATA[%s]]></Content>
					</xml>'''%(fromUser,toUser,str(int(time.time())),replyContent)
				return HttpResponse(reply, content_type="application/xml")<commit_msg>wechat welcome MSG<commit_after># -*- coding:utf-8 -*-
#from django.shortcuts import render
from mezzanine.utils.views import render
from django.http import HttpResponse
import hashlib, lxml, time
from lxml import etree

# Create your views here.
def wechatInterface(request):
	signature=request.GET.get("signature")
	timestamp=request.GET.get("timestamp")
	nonce=request.GET.get("nonce")
	echostr=request.GET.get("echostr")
	token="<PASSWORD>"
	list=[token,timestamp,nonce]
	list.sort()
	sha1=hashlib.sha1()
	map(sha1.update,list)
	hashcode=sha1.hexdigest()
	if hashcode == signature:
		if request.method=="GET":
			return HttpResponse(echostr)
		elif request.method=="POST":
			xml_str=request.body
			xml=etree.fromstring(xml_str)
			toUser=xml.find("ToUserName").text
			fromUser=xml.find("FromUserName").text
			createTime=xml.find("CreateTime").text
			msgType=xml.find("MsgType").text
			if msgType=="event":
				content=xml.find("Event").text
				if content=="subscribe":
					replyContent=u"欢迎使用智能硬件服务号，您将可以通过本服务号控制您的智能硬件，相关功能正在玩命开发中，敬请期待！"
					reply='''
						<xml>
						<ToUserName><![CDATA[%s]]></ToUserName>
						<FromUserName><![CDATA[%s]]></FromUserName>
						<CreateTime><![CDATA[%s]]></CreateTime>
						<MsgType><![CDATA[text]]></MsgType>
						<Content><![CDATA[%s]]></Content>
						</xml>'''%(fromUser,toUser,str(int(time.time())),replyContent)
					return HttpResponse(reply, content_type="application/xml")
{'fraction_non_alphanumeric': 0.17365684575389947, 'fraction_numerical': 0.0034662045060658577, 'mean_word_length': 5.54421768707483, 'pattern_counts': {'":': 8, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6241269', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1076, 'n_words': 143}