Skip to main content

Django WeChat OAuth2/Share/Token API

Project description

Django WeChat OAuth2/Share/Token API

Installation

pip install django-we

Urls.py

urlpatterns = [
    url(r'^we/', include('django_we.urls', namespace='wechat')),
]

or:

from django.conf.urls import include, url
from django_we import views as we_views

# WeChat OAuth2
urlpatterns = [
    url(r'^o$', we_views.we_oauth2, name='shorten_o'),
    url(r'^oauth$', we_views.we_oauth2, name='shorten_oauth'),
    url(r'^oauth2$', we_views.we_oauth2, name='shorten_oauth2'),
    url(r'^we_oauth2$', we_views.we_oauth2, name='we_oauth2'),
    url(r'^base_redirect$', we_views.base_redirect, name='base_redirect'),
    url(r'^userinfo_redirect$', we_views.userinfo_redirect, name='userinfo_redirect'),
    url(r'^direct_base_redirect$', we_views.direct_base_redirect, name='direct_base_redirect'),
    url(r'^direct_userinfo_redirect$', we_views.direct_userinfo_redirect, name='direct_userinfo_redirect'),
]

# WeChat Share
urlpatterns += [
    url(r'^ws$', we_views.we_share, name='shorten_we_share'),
    url(r'^weshare$', we_views.we_share, name='we_share'),
]

# WeChat JSAPI Signature
urlpatterns += [
    url(r'^js$', we_views.we_jsapi_signature_api, name='shorten_we_jsapi_signature_api'),
    url(r'^jsapi_signature$', we_views.we_jsapi_signature_api, name='we_jsapi_signature_api'),
]

# WeChat Token
urlpatterns += [
    url(r'^token$', we_views.we_access_token, name='we_token'),
    url(r'^access_token$', we_views.we_access_token, name='we_access_token'),
]

Settings.py

INSTALLED_APPS = (
    ...
    'django_we',
    ...
)

# Wechat Settings
WECHAT = {
    'JSAPI': {
        'token': '5201314',
        'appID': '',
        'appsecret': '',
        'mchID': '',
        'apiKey': '',
        'mch_cert': '',
        'mch_key': '',
        'redpack': {
            'SEND_NAME': '',
            'NICK_NAME': '',
            'ACT_NAME': '',
            'WISHING': '',
            'REMARK': '',
        }
    },
}

# Wechat OAuth Cfg
DJANGO_WE_OAUTH_CFG = 'JSAPI'  # Default ``JSAPI``

# Based on Urls.py
# WECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/we_oauth2?scope={}&redirect_url={}'
# WECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/o?scope={}&r={}'  # Shorten URL
WECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/o?r={}'  # Shorten URL Farther, Scope default ``snsapi_userinfo``
WECHAT_BASE_REDIRECT_URI = 'https://we.com/we/base_redirect'
WECHAT_USERINFO_REDIRECT_URI = 'https://we.com/we/userinfo_redirect'
WECHAT_DIRECT_BASE_REDIRECT_URI = 'https://we.com/we/direct_base_redirect'
WECHAT_DIRECT_USERINFO_REDIRECT_URI = 'https://we.com/we/direct_userinfo_redirect'

# Temp Share Page to Redirect
WECHAT_OAUTH2_REDIRECT_URL = ''

Wechat_Only

# Settings.py
MIDDLEWARE = [
    ...
    'detect.middleware.UserAgentDetectionMiddleware',
    ...
]

WECHAT_ONLY = True  # Default False

# Usage
from django_we.decorators import wechat_only

@wechat_only
def xxx(request):
    """ Docstring """

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-we-1.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

django_we-1.2.0-py2.py3-none-any.whl (8.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-we-1.2.0.tar.gz.

File metadata

  • Download URL: django-we-1.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-we-1.2.0.tar.gz
Algorithm Hash digest
SHA256 269fcff8fadb2087f8cd5886c2aacec300ffffe8da82ac272f4348f138f452f4
MD5 560737230d759b1fdbb2f1c9b0607dc4
BLAKE2b-256 48ba11184ed16dab334fd5d6d887448cf0e28d19946cfb942b362f103fbb33d7

See more details on using hashes here.

File details

Details for the file django_we-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_we-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4b0dcbdae02ae081b79ffab73a69f06c4e837ff0c5c330f42dc1e2af5561b412
MD5 12869e17a6e77b4d59c9286344bf4631
BLAKE2b-256 f9460f89ca0061590d606566f639e5da479f55b217f1d6ae48d6ef67ef976250

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page