本文整理汇总了Python中wechatpy.create_reply函数的典型用法代码示例。如果您正苦于以下问题:Python create_reply函数的具体用法?Python create_reply怎么用?Python create_reply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_reply函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sub_event
def sub_event(msg):
reply = TextReply(message=msg)
new_uid = reply.target
if views.check_band_user(new_uid) == False:
views.insert_band_user(new_uid)
return HttpResponse(create_reply("太平洋手环保太平,欢迎您使用太平洋手环!", message=msg))
else:
return HttpResponse(create_reply("欢迎您重归太平洋手环!", message=msg))
示例2: handle
def handle(self, message):
if not self.check_match(message):
return
parts = message.content.strip().split()
if len(parts) == 1 or len(parts) > 2:
return create_reply('IP地址无效', message)
ip = parts[1]
pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
if not re.match(pattern, ip):
return create_reply('IP地址无效', message)
result = self.q.lookup(ip)
if result is None:
return create_reply('未找到', message)
else:
return create_reply(result[0], message)
示例3: subEvent
def subEvent(msg):
data = tools.client.user.get(msg.source)
try:
username = data["nickname"]
users = User.objects.filter(openId=msg.source)
if len(users) > 0:
user = users[0]
else:
user = User(name=data["nickname"],sex=int(data["sex"]),openId=msg.source,comment=u"现在还是空的><")
user.save()
team = Team(name=basic_tools.teamName(None, username),type=0)
team.save()
team.members.add(user)
user.name = username
user.uid = int(random.random() * 100)
if "headimgurl" in data:
user.image = data["headimgurl"]
user.save()
date = basic_tools.getDate()
#如果DayData不存在,则创建
if DayData.objects.filter(user=user,date=date).count() == 0:
dayData = DayData(user=user,date=date)
basic_tools.updateDayData(dayData, user)
dayData.save()
except:
username = ""
return HttpResponse(create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))
示例4: unsubEvent
def unsubEvent(msg):
# try:
# user = User.objects.get(openId=msg.source)
# user.delete()
# except:
# user = None
return HttpResponse(create_reply(u"Hello World!I am 用户取关事件", message=msg))
示例5: wechat
def wechat():
signature = request.args.get('signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
echo_str = request.args.get('echostr', '')
try:
check_signature(TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
if request.method == 'GET':
return echo_str
else:
msg = parse_message(request.data)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return reply.render()
示例6: wechat
def wechat():
signature = request.args.get('signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
encrypt_type = request.args.get('encrypt_type', 'raw')
msg_signature = request.args.get('msg_signature', '')
try:
check_signature(TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
if request.method == 'GET':
echo_str = request.args.get('echostr', '')
return echo_str
# POST request
if encrypt_type == 'raw':
# plaintext mode
msg = parse_message(request.data)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return reply.render()
else:
# encryption mode
from wechatpy.crypto import WeChatCrypto
crypto = WeChatCrypto(TOKEN, AES_KEY, APPID)
try:
msg = crypto.decrypt_message(
request.data,
msg_signature,
timestamp,
nonce
)
except (InvalidSignatureException, InvalidAppIdException):
abort(403)
else:
msg = parse_message(msg)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return crypto.encrypt_message(reply.render(), nonce, timestamp)
示例7: wechat
def wechat():
signature = request.args.get('signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
echo_str = request.args.get('echostr', '')
encrypt_type = request.args.get('encrypt_type', '')
msg_signature = request.args.get('msg_signature', '')
print('signature:', signature)
print('timestamp: ', timestamp)
print('nonce:', nonce)
print('echo_str:', echo_str)
print('encrypt_type:', encrypt_type)
print('msg_signature:', msg_signature)
try:
check_signature(TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
if request.method == 'GET':
return echo_str
else:
print('Raw message: \n%s' % request.data)
crypto = WeChatCrypto(TOKEN, EncodingAESKey, AppId)
try:
msg = crypto.decrypt_message(
request.data,
msg_signature,
timestamp,
nonce
)
print('Descypted message: \n%s' % msg)
except (InvalidSignatureException, InvalidAppIdException):
abort(403)
msg = parse_message(msg)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return crypto.encrypt_message(
reply.render(),
nonce,
timestamp
)
示例8: post
def post(self, request):
message = request.data
handler_name = self.handlers.get(message.type, '')
if callable(handler_name):
handler = handler_name
else:
handler = getattr(self, handler_name, self.message_not_handled)
reply = handler(message)
result = create_reply(reply, message)
return result.render()
示例9: textHandle
def textHandle(msg):
if msg.type == "text":
textstr = msg.content.encode("utf-8")
if (
(textstr == "我是谁")
or (textstr == "我是谁?")
or (textstr == "我是谁?")
or (textstr == "你猜我是谁?")
or (textstr == "你猜我是谁?")
):
return HttpResponse(
create_reply("你是:".decode("utf-8") + "%s" % User.objects.get(openid=msg.source).name, message=msg)
)
if textstr == "运动步数":
tools.customSendArticle(
msg.source,
u"运动步数",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/sports.png",
"http://" + tools.IP + "/" + msg.source + "/steps/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
if textstr == "睡眠状况":
tools.customSendArticle(
msg.source,
u"睡眠状况",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/sleep.jpg",
"http://" + tools.IP + "/" + msg.source + "/sleep/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
if textstr.find("帮我将签名改为:") == 0:
if len(textstr) > 54:
return HttpResponse(create_reply("您的签名太长啦> <".decode("utf-8"), message=msg))
else:
User.objects.filter(openid=msg.source).update(sign=textstr[24:])
return HttpResponse(create_reply("修改成功".decode("utf-8"), message=msg))
if textstr.find("帮我将签名改为:") == 0:
if len(textstr) > 52:
return HttpResponse(create_reply("您的签名太长啦> <".decode("utf-8"), message=msg))
else:
User.objects.filter(openid=msg.source).update(sign=textstr[22:])
return HttpResponse(create_reply("修改成功".decode("utf-8"), message=msg))
tools.customSendArticle(
msg.source,
u"或许你要寻求的服务能在这里找到?",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/help.png",
"http://" + tools.IP + "/handbook/",
)
return HttpResponse(create_reply("抱歉,我们找不到您要的服务".decode("utf-8"), message=msg))
示例10: text_handle
def text_handle(request):
msg = parse_message(request.body)
reply = TextReply(message=msg)
content = msg.content
new_uid = reply.target
if content == "来数据":
views.update_database_randomly(new_uid)
return HttpResponse(create_reply("注入了数据!", message=msg))
elif content == "xp好帅":
views.test2(new_uid)
return HttpResponse(create_reply("获得了浇水次数和施肥次数!!", message=msg))
if new_uid in sessions and sessions[new_uid] == 1:
if content == "退出":
sessions[reply.target] = 0
return HttpResponse(create_reply("生命之树期待与您再次相会", message=msg))
rebot_key = "da0d72f6aacebe4301f685e2c11f22c0"
url = "http://www.tuling123.com/openapi/api?key=%s&info=%s" % (rebot_key,urllib.parse.quote(content))
# return HttpResponse(create_reply(u"生命之树期待与您再次相会", message=msg))
response = urllib.request.urlopen(url).read() #调用urllib2向服务器发送get请求url
reply_text = json.loads(response.decode("utf-8"))['text']
reply_text.replace('图灵机器人','生命之树')
# reply_text.replace(u'图灵机器人'.encode('utf-8'),u'生命之树')
return HttpResponse(create_reply(reply_text, message=msg))
if(views.check_band_user(new_uid) == False):
views.insert_band_user(new_uid)
return HttpResponse(create_reply(u"太平洋手环保太平,欢迎您使用太平洋手环!", message=msg))
else:
return HttpResponse(create_reply(u"欢迎您重归太平洋手环!", message=msg))
示例11: click_event
def click_event(request):
reply = TextReply(message = request)
if request.key == 'ranklist': #排行榜
t = get_template('ranklist.xml')
html = t.render(Context({'to_user': reply.target, 'from_user': reply.source, "create_time": reply.time}))
return HttpResponse(html, content_type="application/xml")
elif request.key == "talk_with_tree":
# request.session["talk_flag"] = True
return HttpResponse(create_reply(u"你好,我是你粗大的生命之树。能和你聊聊天真好。\n\n回复‘退出’可退出交谈模式", message=request))
elif request.key == "get_today_mission":
i = random.uniform(0, 2)
if i < 1:
i = 1
else:
i = 0
str = "欢迎您领取每日任务。完成每日任务可获得大量肥料与水的奖励。\n\n您今天的任务是【" + mission_detail[i]["description"] + "】"
print (str)
return HttpResponse(create_reply(str, message=request))
elif request.key == "set_today_mission":
print (views.check_today_mission(reply.target))
if views.check_today_mission(reply.target):
return HttpResponse(create_reply(u"恭喜您完成了今天的每日任务!您的奖励已到账!", message=request))
else:
return HttpResponse(create_reply(u"您的每日任务尚未完成,继续努力吧~", message=request))
elif request.key == "hit_card":
if views.check_today_plan(reply.target):
return HttpResponse(create_reply(u"本日打卡成功!", message=request))
else:
return HttpResponse(create_reply(u"您本日的运动计划尚未完成,继续努力吧!", message=request))
示例12: clickEvent
def clickEvent(msg):
if msg.key == "V1000_FRIEND":
tools.customSendArticle(
msg.source,
u"好友排行",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/rank.jpg",
"http://" + tools.IP + "/" + msg.source + "/friend/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
if msg.key == "V1000_HELP":
tools.customSendArticle(
msg.source,
u"产品简介",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/help.png",
"http://" + tools.IP + "/handbook/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
if msg.key == "V1000_STEP":
tools.customSendArticle(
msg.source,
u"运动步数",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/sports.png",
"http://" + tools.IP + "/" + msg.source + "/steps/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
if msg.key == "V1000_SLEEP":
tools.customSendArticle(
msg.source,
u"睡眠状况",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/sleep.jpg",
"http://" + tools.IP + "/" + msg.source + "/sleep/",
)
return HttpResponse(create_reply("谢谢查询".decode("utf-8"), message=msg))
return HttpResponse(create_reply(u"Hello World!I am 点击菜单跳转链接事件", message=msg))
示例13: textHandle
def textHandle(msg):
tools.customSendText(msg.source, u"我是主动发送的信息")
if tools.tmp_media_id:
tools.customSendImage(msg.source, None, tools.tmp_media_id)
else:
tools.tmp_media_id = tools.uploadMedia("image", "test.jpg")["media_id"]
tools.customSendImage(msg.source, None, tools.tmp_media_id)
#tools.customSendImage(msg.source, "test.jpg")
tools.customSendArticle(msg.source, u"我是单条的文章", u"圣光会制裁你的!", "http://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=http%3A%2F%2Fimg1.91.com%2Fuploads%2Fallimg%2F141208%2F723-14120P95G23Q.jpg", "http://www.hearthstone.com.cn/landing")
articles = []
articles.append({"title":u"我是多条文章_0", "description":u"过来好好打一架,胆小鬼!", "image":"http://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=http%3A%2F%2Fdynamic-image.yesky.com%2F300x-%2FuploadImages%2F2014%2F014%2F9N1OO1139Y57_big_500.png", "url":"http://www.hearthstone.com.cn/landing"})
articles.append({"title":u"我是多条文章_1", "description":u"信仰圣光吧!", "image":"http://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=http%3A%2F%2Fdb.hs.tuwan.com%2Fcard%2Fpremium%2FEX1_383.png", "url":"http://www.hearthstone.com.cn/landing"})
articles.append({"title":u"我是多条文章_2", "description":u"你~需要我的帮助么", "image":"http://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=http%3A%2F%2Fimg.douxie.com%2Fupload%2Fupload%2F2014%2F02%2F12%2Ftb_52fadff8ed62f.jpg", "url":"http://www.hearthstone.com.cn/landing"})
tools.customSendArticles(msg.source, articles)
return HttpResponse(create_reply("Hello World!I am text\nyour openid is:%s" % msg.source, message=msg))
示例14: message_entries
def message_entries():
signature = request.args.get('signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
encrypt_type = request.args.get('encrypt_type', 'raw')
msg_signature = request.args.get('msg_signature', '')
try:
check_signature(Config.TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
# 微信验证
if request.method == 'GET':
echo_str = request.args.get('echostr', '')
return echo_str
# POST request
if encrypt_type == 'raw':
# plaintext mode
msg = parse_message(request.data)
# 事件处理
if msg.type == 'event':
# 关注事件
if msg.event == 'subscribe':
mfc = MenuFunc(msg.source)
mfc.subscribecreatemenu()
reply = create_reply(msg.event, msg)
elif msg.type == 'text':
reply = create_reply(msg.content, msg)
elif msg.type == 'image':
reply = create_reply('对不起,暂时不支持图片消息', msg)
else:
reply = create_reply(msg.type, msg)
return reply.render()
else:
# encryption mode
from wechatpy.crypto import WeChatCrypto
crypto = WeChatCrypto(Config.TOKEN, Config.AES_KEY, Config.APPID)
try:
msg = crypto.decrypt_message(
request.data,
msg_signature,
timestamp,
nonce
)
except (InvalidSignatureException, InvalidAppIdException):
abort(403)
else:
msg = parse_message(msg)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return crypto.encrypt_message(reply.render(), nonce, timestamp)
示例15: subEvent
def subEvent(msg):
try:
User.objects.get(openid=msg.source)
except:
User.objects.create(openid=msg.source, likenum=0, coins=0, sign="真懒,啥也没留下")
tools.updateInfo(msg.source)
menu = (
'{"button":[{"type":"click","name":"好友排行","key":"V1000_FRIEND"},'
+ '{"type":"click","name":"产品简介","key":"V1000_HELP"},'
+ '{"name":"健康数据","sub_button":[{"type":"click","name":"运动步数","key":"V1000_STEP"},{"type":"click","name":"睡眠状况","key":"V1000_SLEEP"}]}]}'
)
tools.menuCreate(menu)
tools.customSendArticle(
msg.source,
u"或许这些能对您有帮助",
u"",
"https://raw.githubusercontent.com/wmc54321/wrist/hj/%E4%BA%8C%E5%90%88%E4%B8%80/wrist/static/images/help.png",
"http://" + tools.IP + "/handbook/",
)
return HttpResponse(create_reply(u"感谢您的关注", message=msg))