class="lines-num lines-num-old">
+ wx.downloadImage({
+ serverId: serverId, // 需要下载的图片的服务器端ID,由uploadImage接口获得
+ isShowProgressTips: download_params.isShowProgressTips || 1, // 默认为1,显示进度提示
+ success: function (res) {
+ images.localId.push(res.localId)
+ if (JSWE.wxDownloadImageSuccess) {JSWE.wxDownloadImageSuccess(res, serverId)}
+ }
+ })
+ }
+
+ function downloadImages(download_params) {
+ var serverIds = download_params.serverIds, isShowProgressTips = download_params.isShowProgressTips || 1
+ images.localIds = []
+ for (var idx in serverIds) {downloadImage({serverId: serverIds[idx], isShowProgressTips: isShowProgressTips})}
+ }
+
+ function getLocalImgData(localId) {
+ wx.getLocalImgData({
+ localId: localId, // 图片的localID
+ success: function (res) {
+ // var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
+ if (JSWE.wxGetLocalImgDataSuccess) {JSWE.wxGetLocalImgDataSuccess(res)}
+ }
+ })
+ }
+
+ // 9 微信原生接口
+ // 9.1.1 扫描二维码并返回结果
+ // 9.1.2 扫描二维码并返回结果
+ function scanQRCode(scan_params) {
+ if ('undefined' === typeof scan_params) scan_params = {}
+ wx.scanQRCode({
+ needResult: scan_params.needResult || 0, // 默认为0,0扫描结果由微信处理,1直接返回扫描结果
+ scanType: scan_params.scanType || ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
+ success: function (res) { // 当 needResult 为 1 时,扫码返回的结果
+ if (JSWE.wxScanQRCodeSuccess) {JSWE.wxScanQRCodeSuccess(res)}
+ }
+ })
+ }
+
+ // QRCode & BarCode is different
+ function parseScanQRCodeResultStr(resultStr) {
+ var strs = resultStr.split(',')
+ return strs[strs.length - 1]
+ }
+
+ // 10 微信支付接口
+ // 10.1 发起一个支付请求
+ function chooseWXPay(wxpay_params) {
+ wx.chooseWXPay({
+ timestamp: wxpay_params.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
+ nonceStr: wxpay_params.nonceStr, // 支付签名随机串,不长于 32 位
+ package: wxpay_params.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
+ signType: wxpay_params.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
+ paySign: wxpay_params.paySign, // 支付签名
+ success: function (res) {
+ // 支付成功后的回调函数
+ if (JSWE.wxPaySuccess) {JSWE.wxPaySuccess(res)}
+ }
+ })
+ }
+
+ // xx 微信原生企业红包接口
+ // xx.1 发起一个发送原生企业红包请求
+ function openEnterpriseRedPacket(wxredpack_params) {
+ wx.openEnterpriseRedPacket({
+ timeStamp: wxredpack_params.timeStamp, // 红包签名时间戳,注意原生企业红包接口timeStamp字段名需大写其中的S字符,而支付接口timeStamp字段名无需大写其中的S字符。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
+ nonceStr: wxredpack_params.nonceStr, // 红包签名随机串,不长于 32 位
+ package: encodeURIComponent(wxredpack_params.package), // 发放红包接口返回的prepay_id参数值,提交格式如:prepay_id=***)
+ signType: wxredpack_params.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
+ paySign: wxredpack_params.paySign, // 红包签名
+ success: function (res) {
+ // 发送原生企业红包成功后的回调函数
+ if (JSWE.wxEnterpriseRedPacketSuccess) {JSWE.wxEnterpriseRedPacketSuccess(res)}
+ }
+ })
+ }
+
+ var v = {
+ version: '1.0.5',
+
+ // Basic Vars
+ config: config,
+ wxData: wxData,
+ jsApiList: jsApiList,
+
+ isEmpty: isEmpty,
+ isNotEmpty: isNotEmpty,
+
+ // Weixin Function
+ isOpenInWeixin: isOpenInWeixin,
+ getWeixinVersion: getWeixinVersion,
+ isWeixinVersion: isWeixinVersion,
+
+ // Menu Function
+ hideOptionMenu: hideOptionMenu,
+ showOptionMenu: showOptionMenu,
+ hideMenuItems: hideMenuItems,
+ showMenuItems: showMenuItems,
+ hideAllNonBaseMenuItem: hideAllNonBaseMenuItem,
+ showAllNonBaseMenuItem: showAllNonBaseMenuItem,
+ closeWindow: closeWindow,
+
+ // Share Function
+ initWxData: initWxData,
+ changeWxData: changeWxData,
+ fixedWxData: fixedWxData,
+
+ // Voice Function
+ voice: voice,
+ translateVoice: translateVoice,
+ startRecord: startRecord,
+ stopRecord: stopRecord,
+ playVoice: playVoice,
+ pauseVoice: pauseVoice,
+ stopVoice: stopVoice,
+ uploadVoice: uploadVoice,
+ downloadVoice: downloadVoice,
+
+ // Image Function
+ images: images,
+ chooseImage: chooseImage,
+ previewImage: previewImage,
+ uploadImage: uploadImage,
+ uploadImages: uploadImages,
+ downloadImage: downloadImage,
+ downloadImages: downloadImages,
+ getLocalImgData: getLocalImgData,
+
+ // Scan Function
+ scanQRCode: scanQRCode,
+ parseScanQRCodeResultStr: parseScanQRCodeResultStr,
+
+ // Pay Function
+ chooseWXPay: chooseWXPay,
+
+ // EnterpriseRedPacket Function
+ openEnterpriseRedPacket: openEnterpriseRedPacket
+ }
+ e.JSWE = e.V = v
+})(window)
@@ -0,0 +1,5 @@ |
||
| 1 |
+{% extends "admin/change_form.html" %}
|
|
| 2 |
+{% load i18n %}
|
|
| 3 |
+ |
|
| 4 |
+{% block submit_buttons_bottom %}
|
|
| 5 |
+{% endblock %}
|
@@ -0,0 +1,36 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+"""kodo URL Configuration |
|
| 4 |
+ |
|
| 5 |
+The `urlpatterns` list routes URLs to views. For more information please see: |
|
| 6 |
+ https://docs.djangoproject.com/en/1.11/topics/http/urls/ |
|
| 7 |
+Examples: |
|
| 8 |
+Function views |
|
| 9 |
+ 1. Add an import: from my_app import views |
|
| 10 |
+ 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') |
|
| 11 |
+Class-based views |
|
| 12 |
+ 1. Add an import: from other_app.views import Home |
|
| 13 |
+ 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') |
|
| 14 |
+Including another URLconf |
|
| 15 |
+ 1. Import the include() function: from django.conf.urls import url, include |
|
| 16 |
+ 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
|
| 17 |
+""" |
|
| 18 |
+from django.conf import settings |
|
| 19 |
+from django.conf.urls import include, url |
|
| 20 |
+from django.conf.urls.static import static |
|
| 21 |
+from django.contrib import admin |
|
| 22 |
+ |
|
| 23 |
+ |
|
| 24 |
+urlpatterns = [ |
|
| 25 |
+ url(r'^admin/', admin.site.urls), |
|
| 26 |
+ url(r'^api/', include('api.urls', namespace='api')),
|
|
| 27 |
+ # url(r'^s/', include('django_short_url.urls', namespace='django_short_url')),
|
|
| 28 |
+ url(r'^uniapi/', include('django_uniapi.urls', namespace='uniapi')),
|
|
| 29 |
+ url(r'^we/', include('django_we.urls', namespace='wechat')),
|
|
| 30 |
+] |
|
| 31 |
+ |
|
| 32 |
+urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
|
| 33 |
+urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
|
| 34 |
+ |
|
| 35 |
+# AdminSite |
|
| 36 |
+admin.site.site_header = 'My administration' |
@@ -0,0 +1,17 @@ |
||
| 1 |
+""" |
|
| 2 |
+WSGI config for kodo project. |
|
| 3 |
+ |
|
| 4 |
+It exposes the WSGI callable as a module-level variable named ``application``. |
|
| 5 |
+ |
|
| 6 |
+For more information on this file, see |
|
| 7 |
+https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ |
|
| 8 |
+""" |
|
| 9 |
+ |
|
| 10 |
+import os |
|
| 11 |
+ |
|
| 12 |
+from django.core.wsgi import get_wsgi_application |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kodo.settings")
|
|
| 16 |
+ |
|
| 17 |
+application = get_wsgi_application() |
@@ -0,0 +1,23 @@ |
||
| 1 |
+#!/usr/bin/env python |
|
| 2 |
+import os |
|
| 3 |
+import sys |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+if __name__ == "__main__": |
|
| 7 |
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kodo.settings")
|
|
| 8 |
+ try: |
|
| 9 |
+ from django.core.management import execute_from_command_line |
|
| 10 |
+ except ImportError: |
|
| 11 |
+ # The above import may fail for some other reason. Ensure that the |
|
| 12 |
+ # issue is really that Django is missing to avoid masking other |
|
| 13 |
+ # exceptions on Python 2. |
|
| 14 |
+ try: |
|
| 15 |
+ import django |
|
| 16 |
+ except ImportError: |
|
| 17 |
+ raise ImportError( |
|
| 18 |
+ "Couldn't import Django. Are you sure it's installed and " |
|
| 19 |
+ "available on your PYTHONPATH environment variable? Did you " |
|
| 20 |
+ "forget to activate a virtual environment?" |
|
| 21 |
+ ) |
|
| 22 |
+ raise |
|
| 23 |
+ execute_from_command_line(sys.argv) |
@@ -0,0 +1,22 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.contrib import admin |
|
| 4 |
+ |
|
| 5 |
+from mch.models import BrandInfo, DistributorInfo, ModelInfo |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class BrandInfoAdmin(admin.ModelAdmin): |
|
| 9 |
+ list_display = ('brand_id', 'brand_name', 'brand_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+class ModelInfoAdmin(admin.ModelAdmin): |
|
| 13 |
+ list_display = ('model_id', 'model_name', 'model_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+class DistributorInfoAdmin(admin.ModelAdmin): |
|
| 17 |
+ list_display = ('distributor_id', 'distributor_name', 'distributor_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 18 |
+ |
|
| 19 |
+ |
|
| 20 |
+admin.site.register(BrandInfo, BrandInfoAdmin) |
|
| 21 |
+admin.site.register(ModelInfo, ModelInfoAdmin) |
|
| 22 |
+admin.site.register(DistributorInfo, DistributorInfoAdmin) |
@@ -0,0 +1,8 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.apps import AppConfig |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class MchConfig(AppConfig): |
|
| 8 |
+ name = 'mch' |
@@ -0,0 +1,68 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.3 on 2017-12-30 13:37 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+import shortuuidfield.fields |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class Migration(migrations.Migration): |
|
| 10 |
+ |
|
| 11 |
+ initial = True |
|
| 12 |
+ |
|
| 13 |
+ dependencies = [ |
|
| 14 |
+ ] |
|
| 15 |
+ |
|
| 16 |
+ operations = [ |
|
| 17 |
+ migrations.CreateModel( |
|
| 18 |
+ name='BrandInfo', |
|
| 19 |
+ fields=[ |
|
| 20 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 21 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 22 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 23 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 24 |
+ ('brand_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 25 |
+ ('brand_name', models.CharField(blank=True, help_text='\u54c1\u724c\u540d\u79f0', max_length=255, null=True, verbose_name='brand_name')),
|
|
| 26 |
+ ('brand_descr', models.TextField(blank=True, help_text='\u54c1\u724c\u63cf\u8ff0', max_length=255, null=True, verbose_name='brand_descr')),
|
|
| 27 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 28 |
+ ], |
|
| 29 |
+ options={
|
|
| 30 |
+ 'verbose_name': '\u54c1\u724c\u4fe1\u606f', |
|
| 31 |
+ 'verbose_name_plural': '\u54c1\u724c\u4fe1\u606f', |
|
| 32 |
+ }, |
|
| 33 |
+ ), |
|
| 34 |
+ migrations.CreateModel( |
|
| 35 |
+ name='DistributorInfo', |
|
| 36 |
+ fields=[ |
|
| 37 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 38 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 39 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 40 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 41 |
+ ('distributor_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u7ecf\u9500\u5546\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 42 |
+ ('distributor_name', models.CharField(blank=True, help_text='\u7ecf\u9500\u5546\u540d\u79f0', max_length=255, null=True, verbose_name='distributor_name')),
|
|
| 43 |
+ ('distributor_descr', models.TextField(blank=True, help_text='\u7ecf\u9500\u5546\u63cf\u8ff0', max_length=255, null=True, verbose_name='distributor_descr')),
|
|
| 44 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 45 |
+ ], |
|
| 46 |
+ options={
|
|
| 47 |
+ 'verbose_name': '\u7ecf\u9500\u5546\u4fe1\u606f', |
|
| 48 |
+ 'verbose_name_plural': '\u7ecf\u9500\u5546\u4fe1\u606f', |
|
| 49 |
+ }, |
|
| 50 |
+ ), |
|
| 51 |
+ migrations.CreateModel( |
|
| 52 |
+ name='ModelInfo', |
|
| 53 |
+ fields=[ |
|
| 54 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 55 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 56 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 57 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 58 |
+ ('model_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 59 |
+ ('model_name', models.CharField(blank=True, help_text='\u578b\u53f7\u540d\u79f0', max_length=255, null=True, verbose_name='model_name')),
|
|
| 60 |
+ ('model_descr', models.TextField(blank=True, help_text='\u578b\u53f7\u63cf\u8ff0', max_length=255, null=True, verbose_name='model_descr')),
|
|
| 61 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 62 |
+ ], |
|
| 63 |
+ options={
|
|
| 64 |
+ 'verbose_name': '\u578b\u53f7\u4fe1\u606f', |
|
| 65 |
+ 'verbose_name_plural': '\u578b\u53f7\u4fe1\u606f', |
|
| 66 |
+ }, |
|
| 67 |
+ ), |
|
| 68 |
+ ] |
@@ -0,0 +1,75 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.db import models |
|
| 4 |
+from django.utils.translation import ugettext_lazy as _ |
|
| 5 |
+from models_ext import BaseModelMixin |
|
| 6 |
+from shortuuidfield import ShortUUIDField |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class BrandInfo(BaseModelMixin): |
|
| 10 |
+ brand_id = ShortUUIDField(_(u'brand_id'), max_length=32, help_text=u'品牌唯一标识', db_index=True, unique=True) |
|
| 11 |
+ brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') |
|
| 12 |
+ brand_descr = models.TextField(_(u'brand_descr'), max_length=255, blank=True, null=True, help_text=u'品牌描述') |
|
| 13 |
+ |
|
| 14 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 15 |
+ |
|
| 16 |
+ class Meta: |
|
| 17 |
+ verbose_name = _(u'品牌信息') |
|
| 18 |
+ verbose_name_plural = _(u'品牌信息') |
|
| 19 |
+ |
|
| 20 |
+ def __unicode__(self): |
|
| 21 |
+ return unicode(self.pk) |
|
| 22 |
+ |
|
| 23 |
+ @property |
|
| 24 |
+ def data(self): |
|
| 25 |
+ return {
|
|
| 26 |
+ 'brand_id': self.brand_id, |
|
| 27 |
+ 'brand_name': self.brand_name, |
|
| 28 |
+ 'brand_descr': self.brand_descr, |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ |
|
| 32 |
+class ModelInfo(BaseModelMixin): |
|
| 33 |
+ model_id = ShortUUIDField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True, unique=True) |
|
| 34 |
+ model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称') |
|
| 35 |
+ model_descr = models.TextField(_(u'model_descr'), max_length=255, blank=True, null=True, help_text=u'型号描述') |
|
| 36 |
+ |
|
| 37 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 38 |
+ |
|
| 39 |
+ class Meta: |
|
| 40 |
+ verbose_name = _(u'型号信息') |
|
| 41 |
+ verbose_name_plural = _(u'型号信息') |
|
| 42 |
+ |
|
| 43 |
+ def __unicode__(self): |
|
| 44 |
+ return unicode(self.pk) |
|
| 45 |
+ |
|
| 46 |
+ @property |
|
| 47 |
+ def data(self): |
|
| 48 |
+ return {
|
|
| 49 |
+ 'model_id': self.model_id, |
|
| 50 |
+ 'model_name': self.model_name, |
|
| 51 |
+ 'model_descr': self.model_descr, |
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+ |
|
| 55 |
+class DistributorInfo(BaseModelMixin): |
|
| 56 |
+ distributor_id = ShortUUIDField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True, unique=True) |
|
| 57 |
+ distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称') |
|
| 58 |
+ distributor_descr = models.TextField(_(u'distributor_descr'), max_length=255, blank=True, null=True, help_text=u'经销商描述') |
|
| 59 |
+ |
|
| 60 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 61 |
+ |
|
| 62 |
+ class Meta: |
|
| 63 |
+ verbose_name = _(u'经销商信息') |
|
| 64 |
+ verbose_name_plural = _(u'经销商信息') |
|
| 65 |
+ |
|
| 66 |
+ def __unicode__(self): |
|
| 67 |
+ return unicode(self.pk) |
|
| 68 |
+ |
|
| 69 |
+ @property |
|
| 70 |
+ def data(self): |
|
| 71 |
+ return {
|
|
| 72 |
+ 'distributor_id': self.distributor_id, |
|
| 73 |
+ 'distributor_name': self.distributor_name, |
|
| 74 |
+ 'distributor_descr': self.distributor_descr, |
|
| 75 |
+ } |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.test import TestCase |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Create your tests here. |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.shortcuts import render |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Create your views here. |
@@ -0,0 +1,9 @@ |
||
| 1 |
+#!/bin/bash |
|
| 2 |
+ |
|
| 3 |
+# Ignoring autogenerated files |
|
| 4 |
+# -- Migration directories |
|
| 5 |
+# Ignoring error codes |
|
| 6 |
+# -- E128 continuation line under-indented for visual indent |
|
| 7 |
+# -- E501 line too long |
|
| 8 |
+ |
|
| 9 |
+pycodestyle --exclude=build,migrations,.tox --ignore=E128,E501 . |
@@ -0,0 +1,18 @@ |
||
| 1 |
+Django==1.11.3 |
|
| 2 |
+StatusCode==1.0.0 |
|
| 3 |
+django-admin==1.1.0 |
|
| 4 |
+django-detect==1.0.5 |
|
| 5 |
+django-json-render==1.0.0 |
|
| 6 |
+django-json-response==1.1.5 |
|
| 7 |
+django-models-ext==1.0.5 |
|
| 8 |
+django-short-url==1.0.2 |
|
| 9 |
+django-uniapi==1.0.0 |
|
| 10 |
+django-we==1.1.2 |
|
| 11 |
+furl==1.0.1 |
|
| 12 |
+hiredis==0.2.0 |
|
| 13 |
+mysqlclient==1.3.12 |
|
| 14 |
+pywe-oauth==1.0.5 |
|
| 15 |
+pywe-pay==1.0.11 |
|
| 16 |
+redis==2.10.6 |
|
| 17 |
+redis-extensions==1.1.6 |
|
| 18 |
+rsa==3.4.2 |
@@ -0,0 +1,13 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+import base64 |
|
| 4 |
+ |
|
| 5 |
+from CodeConvert import CodeConvert as cc |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+def b64_encrypt(plaintext): |
|
| 9 |
+ return base64.urlsafe_b64encode(cc.Convert2Utf8(plaintext)) |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+def b64_decrypt(ciphertext): |
|
| 13 |
+ return cc.Convert2Unicode(base64.urlsafe_b64decode(ciphertext)) |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+import base64 |
|
| 4 |
+ |
|
| 5 |
+import rsa |
|
| 6 |
+from CodeConvert import CodeConvert as cc |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+pubkey = rsa.PublicKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537) |
|
| 10 |
+privkey = rsa.PrivateKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537, 316971401565576878144472516350155768882090601834219605321449556369521730928872332388800749109622843453327077688969025635980606763507018292148749534091473, 4517492317789178911663214752269837474466539823144998211438927363654134055916886851, 1711997816918835594017245862832442114582648667392542139046338517030653261) |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+def rsa_encrypt(plaintext): |
|
| 14 |
+ return base64.urlsafe_b64encode(rsa.encrypt(cc.Convert2Utf8(plaintext), pubkey)) |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+def rsa_decrypt(ciphertext): |
|
| 18 |
+ return rsa.decrypt(base64.urlsafe_b64decode(cc.Convert2Utf8(ciphertext)), privkey) |
@@ -0,0 +1,72 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from StatusCode import BaseStatusCode, StatusCodeField |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+class ProfileStatusCode(BaseStatusCode): |
|
| 7 |
+ """ 4001xx 用户相关错误码 """ |
|
| 8 |
+ PROFILE_NOT_FOUND = StatusCodeField(400101, 'Profile Not Found', description=u'用户不存在') |
|
| 9 |
+ |
|
| 10 |
+ |
|
| 11 |
+class PhoneStatusCode(BaseStatusCode): |
|
| 12 |
+ """ 4002xx 手机相关错误码 """ |
|
| 13 |
+ INVALID_PHONE = StatusCodeField(400200, 'Invalid Phone', description=u'非法手机号') |
|
| 14 |
+ PHONE_NOT_FOUND = StatusCodeField(400201, 'Phone Not Found', description=u'手机号不存在') |
|
| 15 |
+ PHONE_ALREADY_EXISTS = StatusCodeField(400202, 'Phone Already Exists', description=u'手机号已存在') |
|
| 16 |
+ |
|
| 17 |
+ |
|
| 18 |
+class OrderStatusCode(BaseStatusCode): |
|
| 19 |
+ """ 4040xx 订单/支付相关错误码 """ |
|
| 20 |
+ UNIFIED_ORDER_FAIL = StatusCodeField(404000, 'Unified Order Fail', description=u'统一下单失败') |
|
| 21 |
+ ORDER_NOT_FOUND = StatusCodeField(404001, 'Order Not Found', description=u'订单不存在') |
|
| 22 |
+ # 订单支付状态 |
|
| 23 |
+ ORDER_NOT_PAY = StatusCodeField(404011, 'Order Not Pay', description=u'订单未支付') |
|
| 24 |
+ ORDER_PAYING = StatusCodeField(404012, 'Order Paying', description=u'订单支付中') |
|
| 25 |
+ ORDER_PAY_FAIL = StatusCodeField(404013, 'Order Pay Fail', description=u'微信支付失败') |
|
| 26 |
+ # 通知校验状态 |
|
| 27 |
+ SIGN_CHECK_FAIL = StatusCodeField(404090, 'Sign Check Fail', description=u'签名校验失败') |
|
| 28 |
+ FEE_CHECK_FAIL = StatusCodeField(404091, 'FEE Check Fail', description=u'金额校验失败') |
|
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+class PayStatusCode(BaseStatusCode): |
|
| 32 |
+ """ 4041xx 支付相关错误码 """ |
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+class WithdrawStatusCode(BaseStatusCode): |
|
| 36 |
+ """ 4042xx 提现相关错误码 """ |
|
| 37 |
+ BALANCE_INSUFFICIENT = StatusCodeField(404200, 'Balance Insufficient', description=u'提现金额不足') |
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+class TokenStatusCode(BaseStatusCode): |
|
| 41 |
+ """ 4090xx 票据相关错误码 """ |
|
| 42 |
+ TOKEN_NOT_FOUND = StatusCodeField(409001, 'Token Not Found', description=u'票据不存在') |
|
| 43 |
+ |
|
| 44 |
+ |
|
| 45 |
+class SignatureStatusCode(BaseStatusCode): |
|
| 46 |
+ """ 4091xx 签名校验错误 """ |
|
| 47 |
+ SIGNATURE_ERROR = StatusCodeField(409101, 'Signature Error', description=u'签名错误') |
|
| 48 |
+ |
|
| 49 |
+ |
|
| 50 |
+class GVCodeStatusCode(BaseStatusCode): |
|
| 51 |
+ """ 4095xx 图形验证码相关错误码 """ |
|
| 52 |
+ GRAPHIC_VCODE_ERROR = StatusCodeField(409101, 'Graphic VCode Error', description=u'图形验证码错误') |
|
| 53 |
+ |
|
| 54 |
+ |
|
| 55 |
+class SVCodeStatusCode(BaseStatusCode): |
|
| 56 |
+ """ 4092xx 短信验证码相关错误码 """ |
|
| 57 |
+ SMS_QUOTA_LIMIT = StatusCodeField(409200, 'SMS Quota Limit', description=u'短信次数超限') |
|
| 58 |
+ SMS_VCODE_ERROR = StatusCodeField(409201, 'SMS VCode Error', description=u'验证码错误,请稍后重试') |
|
| 59 |
+ SMS_VCODE_HAS_SEND = StatusCodeField(409202, 'SMS VCode Has Send', description=u'验证码已发送,请勿重复获取') |
|
| 60 |
+ |
|
| 61 |
+ |
|
| 62 |
+class InsufficientStatusCode(BaseStatusCode): |
|
| 63 |
+ """ 4095xx 不足相关错误码 """ |
|
| 64 |
+ BALANCE_INSUFFICIENT = StatusCodeField(409501, 'Balance Insufficient', description=u'余额不足') |
|
| 65 |
+ INTEGRAL_INSUFFICIENT = StatusCodeField(409502, 'Integral Insufficient', description=u'积分不足') |
|
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+class PermissionStatusCode(BaseStatusCode): |
|
| 69 |
+ """ 4099xx 权限相关错误码 """ |
|
| 70 |
+ PERMISSION_DENIED = StatusCodeField(409900, 'Permission Denied', description=u'权限不足') |
|
| 71 |
+ UPLOAD_PERMISSION_DENIED = StatusCodeField(409910, 'Upload Permission Denied', description=u'上传权限不足') |
|
| 72 |
+ UPDATE_PERMISSION_DENIED = StatusCodeField(409930, 'Update Permission Denied', description=u'更新权限不足') |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.http import JsonResponse |
|
| 4 |
+from StatusCode import StatusCodeField |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+def response_data(status_code=200, message=None, description=None, data={}, **kwargs):
|
|
| 8 |
+ return dict({
|
|
| 9 |
+ 'status': status_code, |
|
| 10 |
+ 'message': message, |
|
| 11 |
+ 'description': description, |
|
| 12 |
+ 'data': data, |
|
| 13 |
+ }, **kwargs) |
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+def response(status_code=200, message=None, description=None, data={}, **kwargs):
|
|
| 17 |
+ message, description = (message or status_code.message, description or status_code.description) if isinstance(status_code, StatusCodeField) else (message, description) |
|
| 18 |
+ return JsonResponse(response_data(status_code, message, description, data, **kwargs), safe=False) |
@@ -0,0 +1,6 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.conf import settings |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+r = settings.REDIS_CACHE |
@@ -0,0 +1 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+ |
|
| 4 |
+def userinfo_save(userinfo): |
|
| 5 |
+ """ Save profile or something else """ |
|
| 6 |
+ # from account.models import UserInfo |
|
| 7 |
+ # from django.conf import settings |
|
| 8 |
+ # |
|
| 9 |
+ # unique_identifier = userinfo.get(settings.WECHAT_UNIQUE_IDENTIFICATION, '') |
|
| 10 |
+ # |
|
| 11 |
+ # user, created = UserInfo.objects.select_for_update().get_or_create(**{settings.WECHAT_UNIQUE_IDENTIFICATION: unique_identifier})
|
|
| 12 |
+ # user.unionid = userinfo.get('unionid', '')
|
|
| 13 |
+ # user.openid = userinfo.get('openid', '')
|
|
| 14 |
+ # user.nickname = userinfo.get('nickname', '')
|
|
| 15 |
+ # user.avatar = userinfo.get('headimgurl', '')
|
|
| 16 |
+ # user.save() |
|
| 17 |
+ # |
|
| 18 |
+ # return user |