Example #1
0
	def get(self):
		wechat = WechatSimple()
		code = self.get_argument('code')
		snsret = wechat.oauth(code)
		#snsret = {'':''}
		#搞不明白为什么微信给的code为什么会失效,只看到企鹅给返回来两次code,然后尼玛code就失效了
		#只好补丁一下,尝试重连
		if 'openid' not in snsret:
			reconnectqq = self.get_cookie('reconnectqq', None)
			if reconnectqq is None:
				self.set_cookie('reconnectqq', '0', expires=datetime.datetime.utcnow() + datetime.timedelta(minutes=1))
				#print 'create cookie'
				return self.redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://huhushui.club/tor/user/login?response_type=code&scope=snsapi_base&state=1#wechat_redirect')
			elif reconnectqq == '0':
				self.set_cookie('reconnectqq', '1', expires=datetime.datetime.utcnow() + datetime.timedelta(minutes=1))
				#print 'reconnectqq'
				return self.redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://huhushui.club/tor/user/login?response_type=code&scope=snsapi_base&state=1#wechat_redirect')
			else:
				return self.write(u'对不起,我们和微信的服务器的沟通出现了一些问题。请尝试点击左上角的返回,然后再次点击按钮。')
		else:
			openid = snsret["openid"];
			weuser = db.WechatUser.find_one({'openid':openid})
			self.set_secure_cookie('openid',openid)
			self.set_cookie('nickname',weuser['nickname'])
			self.set_cookie('longitude',str(weuser['longitude']))
			self.set_cookie('latitude',str(weuser['latitude']))
			return self.redirect('/tor/user/redir')
Example #2
0
 def post(self):
     wechat = WechatSimple()
     if wechat.check_signature(signature=self.get_argument('signature'),
                               timestamp=self.get_argument('timestamp'),
                               nonce=self.get_argument('nonce')):
         wechat.parse_data(self.request.body)
         message = wechat.get_message()
         response = None
         if message.type == 'subscribe':
             jsoninfo = wechat.getUserInfo(message.source)
             self._update_user(jsoninfo)
             response = wechat.response_text(
                 jsoninfo['nickname'] +
                 u'您好,欢迎关注呼呼睡微信服务号。您可以点击按钮订房,也可以下载呼呼睡App进行订房。')
             return self.write(response)
         elif message.type == 'location':
             jsoninfo = {
                 'openid': message.source,
                 'latitude': message.latitude,
                 'longitude': message.longitude
             }
             self._update_user_location(jsoninfo)
         elif message.type == 'text':
             jsoninfo = wechat.getUserInfo(message.source)
             self._update_user(jsoninfo)
             response = wechat.response_text(jsoninfo['nickname'] +
                                             u'您好,请点击按钮订房,或者下载呼呼睡App。')
             return self.write(response)
         else:
             pass
Example #3
0
def InterfaceVerify(request):
	signature = request.GET.get('signature', None)
	timestamp = request.GET.get('timestamp', None)
	nonce = request.GET.get('nonce', None)
	echostr = request.GET.get('echostr', None)
	wechat = WechatSimple()
	if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
		return HttpResponse(echostr)
Example #4
0
def creatmenu(request):
	wechat = WechatSimple()
	retval = wechat.create_menu({
		'button':[
		{
			'type': 'view',
			'name': u'我要订房!',
			'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://ftpqy.vicp.net/wechat/booking/?action=viewtest&response_type=code&scope=snsapi_base&state=1#wechat_redirect'
		},
	]})
	return HttpResponse(json.dumps(retval))
Example #5
0
 def get(self):
     wechat = WechatSimple()
     code = self.get_argument('code')
     snsret = wechat.oauth(code)
     #snsret = {'':''}
     #搞不明白为什么微信给的code为什么会失效,只看到企鹅给返回来两次code,然后尼玛code就失效了
     #只好补丁一下,尝试重连
     if 'openid' not in snsret:
         reconnectqq = self.get_cookie('reconnectqq', None)
         if reconnectqq is None:
             self.set_cookie('reconnectqq',
                             '0',
                             expires=datetime.datetime.utcnow() +
                             datetime.timedelta(minutes=1))
             #print 'create cookie'
             return self.redirect(
                 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://huhushui.club/tor/user/login?response_type=code&scope=snsapi_base&state=1#wechat_redirect'
             )
         elif reconnectqq == '0':
             self.set_cookie('reconnectqq',
                             '1',
                             expires=datetime.datetime.utcnow() +
                             datetime.timedelta(minutes=1))
             #print 'reconnectqq'
             return self.redirect(
                 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://huhushui.club/tor/user/login?response_type=code&scope=snsapi_base&state=1#wechat_redirect'
             )
         else:
             return self.write(
                 u'对不起,我们和微信的服务器的沟通出现了一些问题。请尝试点击左上角的返回,然后再次点击按钮。')
     else:
         openid = snsret["openid"]
         weuser = db.WechatUser.find_one({'openid': openid})
         self.set_secure_cookie('openid', openid)
         self.set_cookie('nickname', weuser['nickname'])
         self.set_cookie('longitude', str(weuser['longitude']))
         self.set_cookie('latitude', str(weuser['latitude']))
         return self.redirect('/tor/user/redir')
Example #6
0
 def get(self):
     retval = WechatSimple().create_menu({
         'button': [
             {
                 'type':
                 'view',
                 'name':
                 u'今晚速订',
                 'url':
                 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx57a085415d1caaed&redirect_uri=http://huhushui.club/tor/user/login?response_type=code&scope=snsapi_base&state=1#wechat_redirect'
             },
         ]
     })
     return self.write(json.dumps(retval, ensure_ascii=False))
Example #7
0
	def post(self):
		wechat = WechatSimple()
		if wechat.check_signature(
				signature=self.get_argument('signature'), 
				timestamp=self.get_argument('timestamp'), 
				nonce=self.get_argument('nonce')):
			wechat.parse_data(self.request.body)
			message = wechat.get_message()
			response = None
			if message.type == 'subscribe':
				jsoninfo = wechat.getUserInfo(message.source)
				self._update_user(jsoninfo)
				response = wechat.response_text(jsoninfo['nickname']+u'您好,欢迎关注呼呼睡微信服务号。您可以点击按钮订房,也可以下载呼呼睡App进行订房。')
				return self.write(response)
			elif message.type == 'location':
				jsoninfo = {'openid':message.source, 'latitude':message.latitude, 'longitude':message.longitude}
				self._update_user_location(jsoninfo)
			elif message.type == 'text':
				jsoninfo = wechat.getUserInfo(message.source)
				self._update_user(jsoninfo)
				response = wechat.response_text(jsoninfo['nickname']+u'您好,请点击按钮订房,或者下载呼呼睡App。')
				return self.write(response)
			else:
				pass
Example #8
0
 def get(self):
     if WechatSimple().check_signature(
             signature=self.get_argument('signature'),
             timestamp=self.get_argument('timestamp'),
             nonce=self.get_argument('nonce')):
         return self.write(self.get_argument('echostr'))
Example #9
0
 def get(self):
     return self.write(
         json.dumps(WechatSimple().get_menu(), ensure_ascii=False))
Example #10
0
def ProcessRequest(request):
	signature = request.GET.get('signature')
	timestamp = request.GET.get('timestamp')
	nonce = request.GET.get('nonce')
	wechat = WechatSimple()
	body_text = request.body
	if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
		wechat.parse_data(body_text)
		message = wechat.get_message()

		response = None
		if message.type == 'text':
			if message.content == u'订房':
				response = wechat.response_text(u'您好,请点击按钮订房,或者下载呼呼睡App:http://ftpqy.vicp.net/admin/')
			else:
				response = wechat.response_text(u'文字')
		elif message.type == 'image':
			response = wechat.response_text(u'图片')
		elif message.type == 'event':
			response = wechat.response_text(u'消息')
		elif message.type == 'subscribe':
			update_user(openid=message.source, subscribe_date=timezone.now(), subscribe=1)
			response = wechat.response_text(u'您好,欢迎关注呼呼睡微信服务号。您可以点击按钮订房,也可以下载呼呼睡App进行订房。')
		elif message.type == 'location':
			update_user(openid=message.source, latitude=message.latitude, longitude=message.longitude)
			response = wechat.response_text(message.type)
		else:
			response = wechat.response_text(message.type)
		
		return HttpResponse(response)
Example #11
0
def getmenu(request):
	wechat = WechatSimple()
	return HttpResponse(json.dumps(wechat.get_menu()))