├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.rst ├── dist ├── django-wechat-pay-0.0.1.tar.gz ├── django-wechat-pay-0.0.2.tar.gz ├── django-wechat-pay-0.0.3.tar.gz ├── django-wechat-pay-0.0.4.tar.gz ├── django-wechat-pay-0.0.5.tar.gz ├── django-wechat-pay-0.0.6.tar.gz ├── django_wechat_pay-0.0.1-py3-none-any.whl ├── django_wechat_pay-0.0.2-py3-none-any.whl ├── django_wechat_pay-0.0.3-py3-none-any.whl ├── django_wechat_pay-0.0.4-py3-none-any.whl ├── django_wechat_pay-0.0.5-py3-none-any.whl └── django_wechat_pay-0.0.6-py3-none-any.whl ├── django_wechat_pay.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── requires.txt └── top_level.txt ├── setup.py └── wechat_pay ├── __init__.py ├── api.py ├── apps.py ├── templates └── wechat_pay │ └── pay.html ├── tests.py ├── urls.py └── views.py /.gitignore: -------------------------------------------------------------------------------- 1 | # vim 2 | .swp 3 | 4 | # python files 5 | __pycache__ 6 | *.py[cod] 7 | 8 | # django 9 | migrations/ 10 | 11 | # scss cache files 12 | *.css.map 13 | .sass-cache/ 14 | 15 | # setuptools 16 | build/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/LICENSE -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include wechat_pay/templates * 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | 基于django的微信支付功能模块 2 | ============================ 3 | 4 | 5 | 快速开始: 6 | --------- 7 | 8 | 安装django-wechat-pay: 9 | 10 | .. code-block:: 11 | 12 | pip install django-wechat-pay 13 | 14 | 15 | 修改settings.py文件: 16 | 17 | .. code-block:: 18 | 19 | INSTALLED_APPS = ( 20 | ... 21 | 'wechat', 22 | 'wechat_pay', 23 | ... 24 | ) 25 | 26 | 27 | 28 | 在settings.py文件底部添加: 29 | 30 | .. code-block:: 31 | 32 | # wechat config 33 | WECHAT = [ 34 | { 35 | 'appid': 'demo', 36 | 'appsecret': 'demo', 37 | 'token': 'demo', 38 | 'mch_id': 'demo', 39 | 'key': 'demo', 40 | 'body': 'demo', 41 | }, 42 | ] 43 | 44 | 45 | 版本更改: 46 | --------- 47 | - v0.1 第一版 48 | -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.1.tar.gz -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.2.tar.gz -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.3.tar.gz -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.4.tar.gz -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.5.tar.gz -------------------------------------------------------------------------------- /dist/django-wechat-pay-0.0.6.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django-wechat-pay-0.0.6.tar.gz -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/django_wechat_pay-0.0.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/dist/django_wechat_pay-0.0.6-py3-none-any.whl -------------------------------------------------------------------------------- /django_wechat_pay.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: django-wechat-pay 3 | Version: 0.0.6 4 | Summary: django wechat pay, fixed view error 5 | Home-page: https://github.com/ChanMo/django-wechat-pay/ 6 | Author: ChanMo 7 | Author-email: chen.orange@aliyun.com 8 | License: BSD License 9 | Description: 基于django的微信支付功能模块 10 | ============================ 11 | 12 | 13 | 快速开始: 14 | --------- 15 | 16 | 安装django-wechat-pay: 17 | 18 | .. code-block:: 19 | 20 | pip install django-wechat-pay 21 | 22 | 23 | 修改settings.py文件: 24 | 25 | .. code-block:: 26 | 27 | INSTALLED_APPS = ( 28 | ... 29 | 'wechat', 30 | 'wechat_pay', 31 | ... 32 | ) 33 | 34 | 35 | 36 | 在settings.py文件底部添加: 37 | 38 | .. code-block:: 39 | 40 | # wechat config 41 | WECHAT = [ 42 | { 43 | 'appid': 'demo', 44 | 'appsecret': 'demo', 45 | 'token': 'demo', 46 | 'mch_id': 'demo', 47 | 'key': 'demo', 48 | 'body': 'demo', 49 | }, 50 | ] 51 | 52 | 53 | 版本更改: 54 | --------- 55 | - v0.1 第一版 56 | 57 | Platform: UNKNOWN 58 | Classifier: Environment :: Web Environment 59 | Classifier: Framework :: Django 60 | Classifier: Intended Audience :: Developers 61 | Classifier: License :: OSI Approved :: BSD License 62 | Classifier: Operating System :: OS Independent 63 | Classifier: Programming Language :: Python 64 | Classifier: Programming Language :: Python :: 3 65 | Classifier: Programming Language :: Python :: 3.2 66 | Classifier: Programming Language :: Python :: 3.3 67 | Classifier: Topic :: Internet :: WWW/HTTP 68 | Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content 69 | -------------------------------------------------------------------------------- /django_wechat_pay.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | MANIFEST.in 3 | README.rst 4 | setup.py 5 | django_wechat_pay.egg-info/PKG-INFO 6 | django_wechat_pay.egg-info/SOURCES.txt 7 | django_wechat_pay.egg-info/dependency_links.txt 8 | django_wechat_pay.egg-info/requires.txt 9 | django_wechat_pay.egg-info/top_level.txt 10 | wechat_pay/__init__.py 11 | wechat_pay/api.py 12 | wechat_pay/apps.py 13 | wechat_pay/tests.py 14 | wechat_pay/urls.py 15 | wechat_pay/views.py 16 | wechat_pay/templates/wechat_pay/pay.html -------------------------------------------------------------------------------- /django_wechat_pay.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /django_wechat_pay.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | django-wechat-base 2 | -------------------------------------------------------------------------------- /django_wechat_pay.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | wechat_pay 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from io import open 3 | from setuptools import setup 4 | 5 | with open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8') as readme: 6 | README = readme.read() 7 | 8 | # allow setup.py to be run from any path 9 | os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) 10 | 11 | setup( 12 | name = 'django-wechat-pay', 13 | version = '0.0.6', 14 | packages = ['wechat_pay'], 15 | include_package_data = True, 16 | install_requires = ['django-wechat-base'], 17 | license = 'BSD License', 18 | description = 'django wechat pay, fixed view error', 19 | long_description = README, 20 | url = 'https://github.com/ChanMo/django-wechat-pay/', 21 | author = 'ChanMo', 22 | author_email = 'chen.orange@aliyun.com', 23 | classifiers = [ 24 | 'Environment :: Web Environment', 25 | 'Framework :: Django', 26 | 'Intended Audience :: Developers', 27 | 'License :: OSI Approved :: BSD License', # example license 28 | 'Operating System :: OS Independent', 29 | 'Programming Language :: Python', 30 | # Replace these appropriately if you are stuck on Python 2. 31 | 'Programming Language :: Python :: 3', 32 | 'Programming Language :: Python :: 3.2', 33 | 'Programming Language :: Python :: 3.3', 34 | 'Topic :: Internet :: WWW/HTTP', 35 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /wechat_pay/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChanMo/django-wechat-pay/2382e6e520bacf33443109fbb79cbffef65293c5/wechat_pay/__init__.py -------------------------------------------------------------------------------- /wechat_pay/api.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from django.utils.encoding import python_2_unicode_compatible 3 | import time 4 | import json 5 | from django.conf import settings 6 | from wechat.api import Base 7 | import xmltodict 8 | 9 | class Pay(Base): 10 | """ Pay Class """ 11 | mch_id = '' 12 | key = '' 13 | prepay_id = '' 14 | 15 | def __init__(self): 16 | super(Pay, self).__init__() 17 | self.mch_id = settings.WECHAT[0]['mch_id'] 18 | self.key = settings.WECHAT[0]['key'] 19 | 20 | def set_prepay_id(self, data): 21 | data['xml'].update({ 22 | 'trade_type': 'JSAPI', 23 | 'appid': self.appid, 24 | 'mch_id': self.mch_id, 25 | 'nonce_str': self.get_random(), 26 | }) 27 | data['xml']['sign'] = self.get_sign(data['xml']) 28 | url = 'https://api.mch.weixin.qq.com/pay/unifiedorder' 29 | message = self.dict_to_xml(data) 30 | result = self.get_data(url, message, 'string') 31 | data = dict(xmltodict.parse(result)) 32 | self.prepay_id = data['xml']['prepay_id'] 33 | 34 | def get_pay_data(self): 35 | data = { 36 | 'appId': self.appid, 37 | 'timeStamp': str(int(time.time())), 38 | 'nonceStr': self.get_random(), 39 | 'package': 'prepay_id=%s' % self.prepay_id, 40 | 'signType': 'MD5', 41 | } 42 | sign = {'paySign': self.get_sign(data),} 43 | data.update(sign) 44 | data = json.dumps(data) 45 | return data 46 | -------------------------------------------------------------------------------- /wechat_pay/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class WechatPayConfig(AppConfig): 5 | name = 'wechat_pay' 6 | -------------------------------------------------------------------------------- /wechat_pay/templates/wechat_pay/pay.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微信安全支付 5 | 6 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /wechat_pay/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from .api import Pay as PayApi 3 | 4 | class Pay(TestCase): 5 | def setUp(self): 6 | pay = PayApi() 7 | data = { 8 | 'xml': { 9 | 'title': 'test', 10 | } 11 | } 12 | pay.set_prepay_id(data) 13 | 14 | def test_set_prepay_id(self): 15 | print(pay.prepay_id) 16 | 17 | def test_get_pay_data(): 18 | print(pay.get_pay_data()) 19 | -------------------------------------------------------------------------------- /wechat_pay/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from .import views 3 | 4 | urlpatterns = [ 5 | url(r'^$', views.PayView.as_view(), name='pay'), 6 | #url(r'^notify/$', views.NotifyView.as_view(), name='notify'), 7 | ] 8 | -------------------------------------------------------------------------------- /wechat_pay/views.py: -------------------------------------------------------------------------------- 1 | import time 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.utils.decorators import method_decorator 4 | from django.shortcuts import render, get_object_or_404 5 | from django.http import HttpResponse 6 | from django.views.generic.base import View 7 | from django.core.urlresolvers import reverse 8 | from django.conf import settings 9 | import xmltodict 10 | from wechat_member.views import WxMemberView 11 | from .api import Pay as PayApi 12 | 13 | class PayView(View): 14 | """ 15 | wechat base pay view 16 | receive post data: order_id, price, title, notify_url, redirect_url 17 | ..remove WxMemberView 18 | """ 19 | def get(self, request, *args, **kwargs): 20 | try: 21 | order_id = request.GET['order_id'] 22 | price = request.GET['price'] 23 | notify_url = request.GET['notify_url'] 24 | redirect_url = request.GET['redirect_url'] 25 | openid = request.GET['openid'] # get instead 26 | except KeyError: 27 | return HttpResponse("PARAM ERROR") 28 | 29 | out_trade_no = str(int(time.time())) + str(order_id) 30 | total_fee = str(int(float(price) * 100)) 31 | param = { 32 | 'xml': { 33 | #'openid': request.session['wx_member']['openid'], 34 | 'openid': openid, 35 | 'body': settings.WECHAT[0]['body'], 36 | 'out_trade_no': out_trade_no, 37 | 'total_fee': total_fee, 38 | 'spbill_create_ip': request.META['REMOTE_ADDR'], 39 | 'notify_url': notify_url, 40 | } 41 | } 42 | pay = PayApi() 43 | pay.set_prepay_id(param) 44 | data = { 45 | 'data': pay.get_pay_data(), 46 | 'redirect_uri': redirect_url, 47 | } 48 | return render(request, 'wechat_pay/pay.html', data) 49 | 50 | 51 | class WxPayNotifyView(View): 52 | """ 53 | Receive wechat service data 54 | valid and send order_id, pay_number to notify_url 55 | """ 56 | @method_decorator(csrf_exempt) 57 | def dispatch(self, request, *args, **kwargs): 58 | return super(WxPayNotifyView, self).dispatch(request, *args, **kwargs) 59 | 60 | def post(self, request, *args, **kwargs): 61 | pay = PayApi() 62 | data = request.body 63 | data = dict(xmltodict.parse(data)['xml']) 64 | result = {} 65 | sign = data['sign'] 66 | del data['sign'] 67 | #check_sign = wx.get_sign(data) 68 | if sign: 69 | order_id = data['out_trade_no'][10:] 70 | pay_number = data['transaction_id'] 71 | result = self.handle_order(order_id, pay_number) 72 | else: 73 | result['return_code'] = 'FAIL' 74 | result['return_msg'] = 'ERROR' 75 | 76 | result_xml = pay.dict_to_xml(result) 77 | return HttpResponse(result_xml) 78 | 79 | def handle_order(self, order_id, pay_number): 80 | """ Need user extends, for order """ 81 | return {'return_code':'SUCCESS','return_msg':'OK'} 82 | --------------------------------------------------------------------------------