Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanMo committed May 25, 2016
1 parent 99a07b8 commit d544f23
Show file tree
Hide file tree
Showing 41 changed files with 583 additions and 125 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include LICENSE
include README.rst
recursive-include wechat/locale *
recursive-include wechat/templates *
recursive-include docs *
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

.. code-block::
pip install django-wechat
pip install django-wechat-base
把wechat模块添加到你的settings.py里面:

Expand Down Expand Up @@ -60,6 +60,7 @@

版本更改:
---------
- v0.4 添加多语言支持
- v0.3 使js配置信息可编辑,添加Qrcode类
- v0.2 添加WxMemberView
- v0.1 第一版
1 change: 1 addition & 0 deletions build/lib.linux-x86_64-2.7/wechat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
default_app_config = 'wechat.apps.WechatConfig'

15 changes: 12 additions & 3 deletions build/lib.linux-x86_64-2.7/wechat/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import json

from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
from django.contrib import messages
from . import models
from .models import Menu, Text, News
from django.conf.urls import patterns, include, url
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from . import api


class MenuAdmin(admin.ModelAdmin):
list_display = ('top', 'name', 'type', 'value')
list_display = ('name', 'top', 'type', 'value')

def get_urls(self):
urls = super(MenuAdmin, self).get_urls()
Expand All @@ -22,7 +24,14 @@ def sync_menu(self, request):
menu_list = models.menu_list()
wx = api.Menu()
content = wx.sync_menu(menu_list)
return HttpResponse(json.dumps(content))
if content['errcode'] == 0:
messages.add_message(request, messages.SUCCESS,\
_('wechat menu sync success'))
else:
messages.add_message(request, messages.ERROR,\
_('wechat menu sync error'))
return HttpResponseRedirect('/admin/wechat/menu/')
#return HttpResponse(json.dumps(content))

def get_form(self, request, obj=None, **kwargs):
form = super(MenuAdmin, self).get_form(request, obj, **kwargs)
Expand Down
44 changes: 22 additions & 22 deletions build/lib.linux-x86_64-2.7/wechat/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
import os
import hashlib
import urllib
Expand All @@ -11,6 +9,7 @@
import string
import collections

from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import localtime
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
Expand All @@ -23,7 +22,7 @@


class Base(object):
'微信接口基类'
'base class'
base_url = 'https://api.weixin.qq.com/cgi-bin/'
appid = ''
appsecret = ''
Expand Down Expand Up @@ -70,7 +69,7 @@ def get_random(self, length=32):
# get sign
def get_sign(self, data):
data = collections.OrderedDict(sorted(data.items()))
s = u''
s = ''
for item in data:
s = s + item + '=' + data[item] + '&'
s = s[0:-1]
Expand Down Expand Up @@ -130,34 +129,36 @@ def push_message(self, data):


class Response(Base):
'微信回复'
'response class'
domain = ''
receive_data = ''

def __init__(self, request):
self.domain = settings.WECHAT_DOMAIN
data = request.body
data = dict(xmltodict.parse(data)['xml'])
self.receive_data = data

def set_keyword(self):
"""
把微信发送过来的数据转化为统一关键字
:param data: 微信数据(dict)
:return: 关键字(str)
set wechat message transfer to a keyword
:param data: wechat data(dict)
:return: keyword(str)
"""
data = self.receive_data
try:
keyword = data['Content']
except KeyError:
try:
if data['MsgType'] == u'event':
if data['Event'] == u'subscribe':
keyword = u'关注'
elif data['Event'] == u'CLICK':
if data['MsgType'] == 'event':
if data['Event'] == 'subscribe':
keyword = 'subscribe'
elif data['Event'] == 'CLICK':
keyword = data['EventKey']
else:
keyword = data['Event']
except KeyError:
keyword = u'默认'
keyword = 'default'

self.keyword = keyword

Expand All @@ -171,7 +172,7 @@ def get_response(self):
text = Text.objects.get(keyword=self.keyword)
msg = self.response_text(text)
except Text.DoesNotExist:
text = Text.objects.get(keyword=u'默认')
text = Text.objects.get(keyword='default')
msg = self.response_text(text)
return msg

Expand Down Expand Up @@ -201,7 +202,7 @@ def response_news(self, obj):
'item': {
'Title': obj.title,
'Description': obj.description,
'PicUrl': 'http://123.56.144.246' + obj.pic.url,
'PicUrl': 'http://' + self.domain + obj.pic.url,
'Url': obj.url,
}
}
Expand All @@ -212,8 +213,7 @@ def response_news(self, obj):


class Member(Base):
'会员相关'

'member'
def get_code_url(self, redirect_uri, state):
redirect_uri = urllib.quote(redirect_uri, safe='')
# url = 'https://open.weixin.qq.com/connect/oauth2/authorize'
Expand Down Expand Up @@ -255,7 +255,7 @@ def get_user_info(self, code):


class Pay(Base):
'支付相关'
'pay'
mch_id = ''
key = ''

Expand All @@ -267,7 +267,7 @@ def __init__(self):

def set_prepay_id(self, data):
data['xml'].update({
'trade_type': u'JSAPI',
'trade_type': 'JSAPI',
'appid': self.appid,
'mch_id': self.mch_id,
'nonce_str': unicode(self.get_random()),
Expand All @@ -287,8 +287,8 @@ def get_pay_data(self):
'appId': self.appid,
'timeStamp': unicode(int(time.time())),
'nonceStr': self.get_random(),
'package': u'prepay_id=%s' % self.prepay_id,
'signType': u'MD5',
'package': 'prepay_id=%s' % self.prepay_id,
'signType': 'MD5',
}
sign = {'paySign': self.get_sign(data),}
data.update(sign)
Expand Down Expand Up @@ -342,7 +342,7 @@ def get_js_sign(self, url, noncestr, timestamp):
'timestamp': timestamp,
}
data = collections.OrderedDict(sorted(data.items()))
s = u''
s = ''
for item in data:
s = s + item + '=' + data[item] + '&'
s = s[0:-1]
Expand Down
7 changes: 3 additions & 4 deletions build/lib.linux-x86_64-2.7/wechat/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
from django.utils.translation import ugettext_lazy as _
from django.apps import AppConfig

class WechatConfig(AppConfig):
name = u'wechat'
verbose_name = u'微信'
name = 'wechat'
verbose_name = _('wechat')
Binary file not shown.
111 changes: 111 additions & 0 deletions build/lib.linux-x86_64-2.7/wechat/locale/zh_Hans/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-05-18 16:19+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"

#: admin.py:29
msgid "wechat menu sync success"
msgstr "菜单更新成功"

#: admin.py:32
msgid "wechat menu sync error"
msgstr "菜单更新失败"

#: apps.py:6
msgid "wechat"
msgstr "微信"

#: models.py:7 models.py:12
msgid "root menu"
msgstr "主菜单"

#: models.py:8
msgid "view menu"
msgstr "网页链接"

#: models.py:9
msgid "click menu"
msgstr "消息回复"

#: models.py:13
msgid "name"
msgstr "名称"

#: models.py:14
msgid "type"
msgstr "类型"

#: models.py:16
msgid "value"
msgstr "值"

#: models.py:18
msgid "sort"
msgstr "排序"

#: models.py:25
msgid "menu"
msgstr "菜单"

#: models.py:26
msgid "menus"
msgstr "菜单"

#: models.py:31 models.py:46
msgid "keyword"
msgstr "关键字"

#: models.py:32
msgid "content"
msgstr "内容"

#: models.py:33 models.py:51
msgid "created time"
msgstr "创建时间"

#: models.py:34 models.py:52
msgid "updated time"
msgstr "更新时间"

#: models.py:40 models.py:41
msgid "text response"
msgstr "文本回复"

#: models.py:47
msgid "title"
msgstr "标题"

#: models.py:48
msgid "description"
msgstr "描述"

#: models.py:49
msgid "image"
msgstr "图片"

#: models.py:50
msgid "link"
msgstr "链接"

#: models.py:58 models.py:59
msgid "news response"
msgstr "图文回复"

#: templates/admin/wechat/menu/change_list.html:6
msgid "upload menu"
msgstr "上传菜单"

0 comments on commit d544f23

Please sign in to comment.