-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New]Add new JS-SDK example
wxjs
. [ci skip]
- Loading branch information
Showing
15 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="uth-8"> | ||
</head> | ||
<body> | ||
<div id="div"></div> | ||
<script type="text/javascript" src="./static/js/jquery-1.11.2.min.js"></script> | ||
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> | ||
<script type="text/javascript"> | ||
(function(window, $){ | ||
var fInitWeixin = function(d){ | ||
wx.config({ | ||
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 | ||
appId: 'wxe82ac2393d60e1e3', // 必填,公众号的唯一标识 | ||
timestamp: d.timestamp, // 必填,生成签名的时间戳 | ||
nonceStr: d.noncestr, // 必填,生成签名的随机串 | ||
signature: d.signature,// 必填,签名,见附录1 | ||
jsApiList: ['onMenuShareTimeline'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 | ||
}); | ||
} | ||
$.ajax({ | ||
type: 'post', | ||
url: 'main/ajax/get_signature', | ||
dataType: 'json', | ||
data: {url: location.href}, | ||
success: function(d){ | ||
fInitWeixin(d) | ||
fShare() | ||
} | ||
}) | ||
var fShare = function(){ | ||
wx.onMenuShareTimeline({ | ||
title: '分享测试', // 分享标题 | ||
link: 'www.qq.com', // 分享链接 | ||
imgUrl: '', // 分享图标 | ||
success: function () { | ||
$.ajax({ | ||
type: 'get', | ||
url: 'main/ajax/log', | ||
dataType: 'json', | ||
success: function(d){ | ||
$('#div').html('成功') | ||
} | ||
}) | ||
}, | ||
cancel: function () { | ||
// 用户取消分享后执行的回调函数 | ||
} | ||
}); | ||
} | ||
})(window, jQuery) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf.urls import patterns, url | ||
|
||
|
||
urlpatterns = patterns( | ||
'main.views', | ||
url(r'ajax/get_signature$', 'jsapi_signature'), | ||
url(r'ajax/log$', 'log'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
import time | ||
|
||
from django.conf import settings | ||
from django.http import JsonResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.shortcuts import render | ||
|
||
from wechatpy import WeChatClient | ||
|
||
|
||
def index(request): | ||
return render(request, 'index.html') | ||
|
||
|
||
@csrf_exempt | ||
def jsapi_signature(request): | ||
noncestr = '123456' | ||
timestamp = int(time.time()) | ||
url = request.POST['url'] | ||
|
||
client = WeChatClient(settings.WECHAT_APPID, settings.WECHAT_SECRET) | ||
ticket = client.jsapi.get_ticket() | ||
signature = client.jsapi.get_jsapi_signature( | ||
noncestr, | ||
ticket['ticket'], | ||
timestamp, | ||
url | ||
) | ||
ret_dict = { | ||
'noncestr': noncestr, | ||
'timestamp': timestamp, | ||
'url': url, | ||
'signature': signature, | ||
} | ||
return JsonResponse(ret_dict) | ||
|
||
|
||
def log(request): | ||
print('Hello World!') | ||
return JsonResponse({ | ||
'status': 'ok', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wxjs.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Django>=1.7 | ||
wechatpy>=0.7.1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
Django settings for wxjs project. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.7/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.7/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '9oz3&e_nhw5v(f4nq7o!*qxele-)831&ng))-8!29trs5y#j)6' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
TEMPLATE_DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'main', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'wxjs.urls' | ||
|
||
WSGI_APPLICATION = 'wxjs.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.7/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.7/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
WECHAT_APPID = 'wxe82ac2393d60e1e3' | ||
WECHAT_SECRET = 'f03b742ff5b9ba2bbb2a7b7bb15266d7' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf.urls import patterns, include, url | ||
from django.contrib import admin | ||
|
||
urlpatterns = patterns('', | ||
# Examples: | ||
# url(r'^$', 'wxjs.views.home', name='home'), | ||
# url(r'^blog/', include('blog.urls')), | ||
|
||
url(r'^admin/', include(admin.site.urls)), | ||
url(r'^$', 'main.views.index'), | ||
url(r'^main/', include('main.urls')), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
WSGI config for wxjs project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wxjs.settings") | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
application = get_wsgi_application() |