# django-we
Django WeChat OAuth2/Share/Token API
## Installation
```shell
pip install django-we
```
## Urls.py
```python
urlpatterns = [
url(r'^we/', include('django_we.urls', namespace='django_we')),
]
```
or
```python
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
```python
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 = ''
```
# Callbacks
* [See django_we_callback_settings.py](https://github.com/django-xxx/django-project-templet-cn/blob/master/templet/templet/django_we_callback_settings.py)
## Wechat_Only
* Settings.py
```python
MIDDLEWARE = [
...
'detect.middleware.UserAgentDetectionMiddleware',
...
]
WECHAT_ONLY = True # Default False
```
* Usage
```python
from django_we.decorators import wechat_only
@wechat_only
def xxx(request):
""" Docstring """
```
Raw data
{
"_id": null,
"home_page": "https://github.com/django-xxx/django-we",
"name": "django-we",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django-we",
"author": "Hackathon",
"author_email": "kimi.huang@brightcells.com",
"download_url": "https://files.pythonhosted.org/packages/00/ee/c27d79df3b60811e34bdfb46b1588caca68f94265d75022ffa69df621d3e/django-we-1.5.7.tar.gz",
"platform": null,
"description": "# django-we\nDjango WeChat OAuth2/Share/Token API\n\n## Installation\n```shell\npip install django-we\n```\n\n## Urls.py\n```python\nurlpatterns = [\n url(r'^we/', include('django_we.urls', namespace='django_we')),\n]\n```\nor\n```python\nfrom django.conf.urls import include, url\nfrom django_we import views as we_views\n\n# WeChat OAuth2\nurlpatterns = [\n url(r'^o$', we_views.we_oauth2, name='shorten_o'),\n url(r'^oauth$', we_views.we_oauth2, name='shorten_oauth'),\n url(r'^oauth2$', we_views.we_oauth2, name='shorten_oauth2'),\n url(r'^we_oauth2$', we_views.we_oauth2, name='we_oauth2'),\n url(r'^base_redirect$', we_views.base_redirect, name='base_redirect'),\n url(r'^userinfo_redirect$', we_views.userinfo_redirect, name='userinfo_redirect'),\n url(r'^direct_base_redirect$', we_views.direct_base_redirect, name='direct_base_redirect'),\n url(r'^direct_userinfo_redirect$', we_views.direct_userinfo_redirect, name='direct_userinfo_redirect'),\n]\n\n# WeChat Share\nurlpatterns += [\n url(r'^ws$', we_views.we_share, name='shorten_we_share'),\n url(r'^weshare$', we_views.we_share, name='we_share'),\n]\n\n# WeChat JSAPI Signature\nurlpatterns += [\n url(r'^js$', we_views.we_jsapi_signature_api, name='shorten_we_jsapi_signature_api'),\n url(r'^jsapi_signature$', we_views.we_jsapi_signature_api, name='we_jsapi_signature_api'),\n]\n\n# WeChat Token\nurlpatterns += [\n url(r'^token$', we_views.we_access_token, name='we_token'),\n url(r'^access_token$', we_views.we_access_token, name='we_access_token'),\n]\n```\n\n## Settings.py\n```python\nINSTALLED_APPS = (\n ...\n 'django_we',\n ...\n)\n\n# Wechat Settings\nWECHAT = {\n 'JSAPI': {\n 'token': '5201314',\n 'appID': '',\n 'appsecret': '',\n 'mchID': '',\n 'apiKey': '',\n 'mch_cert': '',\n 'mch_key': '',\n 'redpack': {\n 'SEND_NAME': '',\n 'NICK_NAME': '',\n 'ACT_NAME': '',\n 'WISHING': '',\n 'REMARK': '',\n }\n },\n}\n\n# Wechat OAuth Cfg\nDJANGO_WE_OAUTH_CFG = 'JSAPI' # Default ``JSAPI``\n\n# Based on Urls.py\n# WECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/we_oauth2?scope={}&redirect_url={}'\n# WECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/o?scope={}&r={}' # Shorten URL\nWECHAT_OAUTH2_REDIRECT_URI = 'https://we.com/we/o?r={}' # Shorten URL Farther, Scope default ``snsapi_userinfo``\nWECHAT_BASE_REDIRECT_URI = 'https://we.com/we/base_redirect'\nWECHAT_USERINFO_REDIRECT_URI = 'https://we.com/we/userinfo_redirect'\nWECHAT_DIRECT_BASE_REDIRECT_URI = 'https://we.com/we/direct_base_redirect'\nWECHAT_DIRECT_USERINFO_REDIRECT_URI = 'https://we.com/we/direct_userinfo_redirect'\n\n# Temp Share Page to Redirect\nWECHAT_OAUTH2_REDIRECT_URL = ''\n```\n\n# Callbacks\n* [See django_we_callback_settings.py](https://github.com/django-xxx/django-project-templet-cn/blob/master/templet/templet/django_we_callback_settings.py)\n\n## Wechat_Only\n* Settings.py\n ```python\n MIDDLEWARE = [\n ...\n 'detect.middleware.UserAgentDetectionMiddleware',\n ...\n ]\n\n WECHAT_ONLY = True # Default False\n ```\n* Usage\n ```python\n from django_we.decorators import wechat_only\n\n @wechat_only\n def xxx(request):\n \"\"\" Docstring \"\"\"\n ```\n",
"bugtrack_url": null,
"license": "",
"summary": "Django WeChat OAuth2/Share/Token API",
"version": "1.5.7",
"split_keywords": [
"django-we"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f42fbe1026be0a0d41024a8dfba77f870ff99b91b980947122022a959e099703",
"md5": "3be755d35df6e17af9872b56fe030190",
"sha256": "f58bd0cdd524e487cc7a8a5ae8cfcebc0b6e6e7bc228711bda88989b1acb8600"
},
"downloads": -1,
"filename": "django_we-1.5.7-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "3be755d35df6e17af9872b56fe030190",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 14797,
"upload_time": "2023-02-03T07:24:07",
"upload_time_iso_8601": "2023-02-03T07:24:07.310170Z",
"url": "https://files.pythonhosted.org/packages/f4/2f/be1026be0a0d41024a8dfba77f870ff99b91b980947122022a959e099703/django_we-1.5.7-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "00eec27d79df3b60811e34bdfb46b1588caca68f94265d75022ffa69df621d3e",
"md5": "89d93f6b68a53c117d2ad31e8876dd53",
"sha256": "4574e6cdd223a2295d8aecc45b0749a091e84a3367a802b9152bb7a1462c2e05"
},
"downloads": -1,
"filename": "django-we-1.5.7.tar.gz",
"has_sig": false,
"md5_digest": "89d93f6b68a53c117d2ad31e8876dd53",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12398,
"upload_time": "2023-02-03T07:24:09",
"upload_time_iso_8601": "2023-02-03T07:24:09.310602Z",
"url": "https://files.pythonhosted.org/packages/00/ee/c27d79df3b60811e34bdfb46b1588caca68f94265d75022ffa69df621d3e/django-we-1.5.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-03 07:24:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "django-xxx",
"github_project": "django-we",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-we"
}