├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── conf └── camelstore.dev.com.nginx.conf └── docs ├── assets └── image │ ├── iis-welcome.png │ ├── key-setting-ui.jpeg │ └── runserver-test.jpg ├── deploy-on-ubuntu.md ├── deploy-on-windows.md ├── deploy ├── nginx.conf ├── supervisor.conf └── uwsgi.ini ├── dev-on-macos.md ├── dev-on-windows.md └── third-party-config.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | .DS_Store 131 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "admin"] 2 | path = admin 3 | url = https://github.com/gzqichang/camel-store-admin.git 4 | [submodule "wxapp"] 5 | path = wxapp 6 | url = https://github.com/gzqichang/camel-store-wxapp.git 7 | [submodule "api"] 8 | path = api 9 | url = https://github.com/gzqichang/camel-store-api.git 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # camel-store 2 | 骆驼小店-可免费商用,新一代开源小程序商城。 3 | 4 | 主要技术栈:Python/Django/Django-rest-framework/React.js/WePy/Ant design pro等。 5 | 6 | 官网:[http://luotuoxiaodian.com/](http://luotuoxiaodian.com/)。 7 | 8 | ------------ 9 | 10 | ## 概述 11 | 12 | 现在项目分为 4 个 github 项目仓库, 13 | 14 | 1. `camel-store`,也就是本仓库,主要是发布统一版本、存放项目文档,以及作为大局沟通渠道。 15 | 1. `docs` 目录放的是文档。 16 | 1. `CSEPs` 目录放的是骆驼小店增强改进提案(Camel-Store Enhancement Proposals),是向 `Python` 项目的 PEP 学习的一种项目管理手段,对此不太了解的朋友可以看看这篇[python中的PEP是什么?怎么理解?(转)](https://www.cnblogs.com/abella/p/10056875.html)。 17 | 1. `admin`、`api`、`wxapp`,三个目录是通过 submodules 方式引入的三个项目,分别对应管理后台、API和小程序三端。 18 | 1. [`admin`](https://github.com/gzqichang/camel-store-admin)是项目管理后台,由基于`Ant design pro`开发,使用的是`React.js`框架。 19 | 1. [`api`](https://github.com/gzqichang/camel-store-api)是API部分,使用`Python`编程语言开发,主要使用了`Django`和`Django-rest-framework`框架。 20 | 1. [`wxapp`](https://github.com/gzqichang/camel-store-wxapp)是小程序部分,使用了`WePY`框架。 21 | 22 | ## 技术理念 23 | 24 | 这不是一个库,是一个应用项目,所以追求的是下载、安装/编译、配置,然后就可以提供商业服务。所以它整体是难以在代码级别被集成到别的项目中去的,它的技术理念是对扩展、替换开放,并提供相应的机制(但目前做得还不够好)。如果通过修改已有代码的方式来实现自己的业务逻辑,可能会导致难以升级到新的版本。 25 | 26 | 27 | ## 在本机体验 28 | 文档在编写中,先看一下 [docs](docs)。 29 | 30 | 1. [Dev on macOS](docs/dev-on-macos.md) 31 | 1. [Dev on Windows](docs/dev-on-windows.md) 32 | 33 | ## 服务器部署 34 | 35 | 1. [Deploy on Ubuntu](docs/deploy-on-ubuntu.md) 36 | 1. [Deploy on Windows](docs/deploy-on-windows.md) 37 | 38 | ## 参与开发 39 | 40 | 类似其他 github 项目,针对`admin`、`api`、`wxapp`三个仓库进行 fork,修改和测试后,欢迎提交 PR。 41 | 42 | ## 官方支持 43 | 44 | 暂无。 45 | -------------------------------------------------------------------------------- /conf/camelstore.dev.com.nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | server{ 4 | listen 8080; 5 | server_name camelstore.dev.com; 6 | client_max_body_size 50m; 7 | 8 | location / { 9 | proxy_pass $scheme://127.0.0.1:8001; 10 | proxy_set_header X-Forwarded-Proto $scheme; 11 | proxy_set_header Host $http_host; 12 | proxy_set_header X-Real-IP $remote_addr; 13 | } 14 | location /api/ { 15 | proxy_pass $scheme://127.0.0.1:8000; 16 | proxy_set_header X-Forwarded-Proto $scheme; 17 | proxy_set_header Host $http_host; 18 | proxy_set_header X-Real-IP $remote_addr; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/assets/image/iis-welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzqichang/camel-store/bbd5cc14b5d166540f0197793c1441df4ff683fd/docs/assets/image/iis-welcome.png -------------------------------------------------------------------------------- /docs/assets/image/key-setting-ui.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzqichang/camel-store/bbd5cc14b5d166540f0197793c1441df4ff683fd/docs/assets/image/key-setting-ui.jpeg -------------------------------------------------------------------------------- /docs/assets/image/runserver-test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzqichang/camel-store/bbd5cc14b5d166540f0197793c1441df4ff683fd/docs/assets/image/runserver-test.jpg -------------------------------------------------------------------------------- /docs/deploy-on-ubuntu.md: -------------------------------------------------------------------------------- 1 | # 在 Ubuntu18 下部署 2 | ## 1.基础安装 3 | #### 1.1 更新ubuntu的软件源 4 | 新建ubuntu虚拟机用户可能需要先把 `/etc/apt/sources.list` 中的源文件替换成国内镜像源 5 | ``` 6 | $ sudo apt-get update // 更新安装源(Source) 7 | $ sudo apt-get upgrade // 更新已安装的软件包 8 | $ sudo apt-get dist-upgrade // 更新已安装的软件包(识别并处理依赖关系的改变) 9 | ``` 10 | #### 1.2 安装数据库postgresql 11 | 需要建立一个数据库来存储`camel-store`的数据。 12 | 文档中约定使用的数据库名为 `camelstore`,其为用户 `camelstore` 所有。 13 | ``` 14 | # 安装postgresql 15 | $ sudo apt-get install postgresql 16 | 17 | # 创建数据库 18 | $ sudo -u postgres psql 19 | # 修改postgres用户的密码 20 | postgres=# ALTER USER postgres WITH PASSWORD 'POSTGRES_PASSWORD'; 21 | 22 | # 创建此项目的的数据库及其拥有者 23 | postgres=# create user camelstore with password 'YOUR_PASSWORD'; 24 | CREATE ROLE 25 | postgres=# create database camelstore owner camelstore; 26 | CREATE DATABASE 27 | ``` 28 | #### 1.3 Python 29 | `camel-store` 至少需要 Python 3.6 或更高的版本,目前使用较多的是 3.6/3.7,建议使用`pyenv`进行python版本的管理,使用`pyenv-virtualenv`创建对应的虚拟环境, 使用`pipenv`管理虚拟环境。 30 | 在此均以 3.7.4 为例。 31 | ``` 32 | # 安装 pyenv 33 | $ git clone https://github.com/pyenv/pyenv.git ~/.pyenv 34 | $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile 35 | $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile 36 | $ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile 37 | $ source .bash_profile 38 | 39 | # 安装 pyenv-virtualenv 40 | $ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv 41 | $ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile 42 | $ source .bash_profile 43 | 44 | # 在安装python前需要安装的一些依赖包 45 | $ sudo apt-get install libc6-dev gcc 46 | $ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm 47 | 48 | # 安装python 3.7.4 49 | $ pyenv install 3.7.4 50 | 51 | # 创建虚拟环境 52 | $ pyenv virtualenv 3.7.4 camel-store 53 | 54 | # 此时通过命令 pyenv versions 应当可以看到下载的python版本和根据该版本创建的虚拟环境 55 | 56 | # 安装pipenv 57 | $ sudo pip install pipenv 58 | # 如果因为网络原因不能下载,可使用国内源如: 59 | $ sudo pip install pipenv -i https://pypi.tuna.tsinghua.edu.cn/simple 60 | ``` 61 | 62 | ## 2. 项目代码 63 | #### 2.1 通过git拉取代码 64 | ``` 65 | # 安装git 66 | $ sudo apt-get install git 67 | ``` 68 | 建议在 `/home/ubuntu/project/camel-store/` 目录下,运行 `git clone https://github.com/gzqichang/camel-store.git --recurse-submodules` 把本仓库拉取到本地,记得需要加入 `--recurse-submodules` 参数。 69 | 70 | #### 2.2 使项目自动激活虚拟环境 71 | 在 `/home/ubuntu/project/camel-store/` 目录下创建文件`.python-version`,在文件内写入在步骤1.3中建立的虚拟环境名称camel-store。每当进入此目录时,应当能发现都可以自动激活虚拟环境。 72 | 73 | #### 2.3 api部分 74 | 进入api目录。 75 | 1. 安装依赖库: 76 | 1. 运行 `pipenv sync`,安装虚拟环境。 77 | 2. 运行`django-admin --version`查看当前django版本是否为2.2版本,目前项目尚未支持django 3.0及以上版本。 78 | 2. 安装本地依赖库: 79 | `cd packages` 进入依赖包的目录,然后分别进入 qapi、qcache、qsmstoken、quser 目录,逐一运行 `python3 setup.py develop` 安装开发版本。 80 | 3. 开始配置项目: 81 | 1. `cd conf/settings` 82 | 2. `cp local.py.tpl local.py` 生成本地配置环境。 83 | 3. 选择喜欢的编辑器,打开 `local.py` 文件,并把 `SECRET_KEY` 和 `DEFAULT_DB` 等项填好,记得 `SECRET_KEY` 要使用几十个字符的随机字符串。 84 | 4. 回退到 `api` 目录。 85 | 5. 运行`python3 manage.py check`测试代码是否有问题 86 | 6. 运行 `python3 manage.py migrate` 创建各种数据表,然后运行 87 | 1. `python3 manage.py init_staff` 创建初始用户数据 88 | 2. `python3 manage.py format_groups` 创建初始分组数据 89 | 3. `python3 manage.py updateconfig` 修改配置,相关的参数看一下帮助。 90 | 4. `python3 manage.py wechatconfig` 修改配置,相关的参数看一下帮助。 91 | 5. `python3 manage.py changepassword admin` 修改之前生成的 admin 账号的密码。 92 | 6. 运行 `python3 manage.py runserver`,此时程序应当能跑起来。 93 | 4. 第三方配置,也是在 `local.py` 文件中,详见[第三方配置](third-party-config.md)。 94 | 95 | #### 2.4 admin部分 96 | 1. 安装软件 97 | ``` 98 | # 安装node.js和npm 99 | $ sudo apt-get install nodejs-legacy 100 | $ sudo apt-get install npm 101 | # 安装用于管理node.js的版本的模块n 102 | $ sudo npm install -g n 103 | # 通过n模块安装最新版node.js 104 | $ sudo n latest 105 | # 升级npm为最新版本 106 | $ sudo npm install npm@latest -g 107 | # 查看版本 108 | $ sudo node -v 109 | $ sudo npm -v 110 | ``` 111 | 2. 进入admin目录。 112 | 1. 运行`npm install`安装项目依赖的模块,这里视网络的情况,估计要一点时间。 113 | 2. 运行`npm run build` 114 | 115 | #### 2.5 部署文件 116 | ###### 2.5.1 创建配置文件 117 | 在 `/home/ubuntu/project/camel-store/` 目录下创建文件夹deploy,在deploy目录下放置3个文件 `nginx.conf`, `supervisor.conf`,`uwsgi.ini`。 118 | 119 | 如果文件所在目录与文档项目目录不一致,需要自行修改其中路径。 120 | nginx.conf文件中的server_name 需要填入自己的SERVER_NAME或者HOST。 121 | 122 | ###### 2.5.2 软连接配置文件 123 | 此处并非覆盖原有的nginx.conf和supervisor.conf 124 | 此处命名只为方便判断具体配置文件 125 | ``` 126 | $ sudo ln -s /home/ubuntu/camel-store/deploy/nginx.conf /etc/nginx/sites-enabled/camel-store.conf 127 | $ sudo ln -s /home/ubuntu/camel-store/deploy/supervisor.conf /etc/supervisor/conf.d/camel-store.conf 128 | ``` 129 | ###### 2.5.3 启动nginx 130 | ``` 131 | # 安装nginx 132 | $ sudo apt-get install nginx 133 | ``` 134 | 1. 运行`nginx -t`校验配置文件是否正确。 135 | 2. 运行`sudo service nginx start`以启动nginx, 如已启动,重启nginx则运行`sudo nginx -s reload` 136 | 137 | ###### 2.5.4 校验uwsgi 138 | 在deploy目录下运行`uwsgi --ini uwsgi.ini`,如正常运行,可ctrl+c键退出。 139 | 140 | ###### 2.5.5 启动supervisor 141 | 用supervisor管理uwsgi进程。 142 | ``` 143 | # 安装supervisor 144 | $ sudo apt-get install supervisor 145 | ``` 146 | 运行`sudo supervisorctl reload` 147 | 148 | **** 149 | 至此,在ubuntu环境中基本部署完成。 -------------------------------------------------------------------------------- /docs/deploy-on-windows.md: -------------------------------------------------------------------------------- 1 | # 在 Windows Server 下部署生产环境 2 | 3 | 本文基于 Windows Server 2012 R2 和 IIS 8.5 编写,如果使用其他版本,请注意兼容性。 4 | 5 | 本文的配置方法至少要求 IIS 7。 6 | 7 | 本文所指的命令行一般是指`PowerShell`,用户应当熟悉其的一般操作。 8 | 9 | ## 基础 10 | 11 | 需要提前安装并配置好下列软件 12 | 13 | ### IIS 14 | 15 | 必须安装和启用 IIS,成功后打开浏览器访问 [http://127.0.0.1/](http://127.0.0.1/),可以看到类似下图的页面表示已经安装和启用 IIS,反之则应先修正 IIS 的安装和启用。 16 | 17 | ![](assets/image/iis-welcome.png) 18 | 19 | 20 | ### PostgreSQL 21 | 22 | `camel-store`使用的数据库是`PostgreSQL`,暂时不支持`MySQL`等其他数据库。 23 | 24 | 建议使用10版本。 25 | 26 | #### 安装 27 | 28 | 数据库有两种方式,一种是购买云厂商的云数据库,使用这种方式一般性能更好,也更简单,不过要开销会增加一些。每个厂商的云数据库购买方式大同小异,在此不详述。 29 | 30 | 这里讲述本机安装的`乞丐版`方式,首先去[`postgresql`](https://www.postgresql.org/)官网下载适合你服务器的安装包,然后一路next,无惊无险安装完成。 31 | 32 | Windows Server 2012 与普通 windows 版本最大的不同,在于其文件 / 目录控制权限更严。在此假定它装到了`C:\pgsql`目录下,所以在新建一个数据库的数据存放目录,比如`C:\pgsql\data`, 右键点击文件夹,选择“属性”、“安全”、“编辑”、“Users”,把“完全控制”一行的“允许”选中。确认保存。 33 | 34 | 打开`PowerShell`窗口,进入`C:\pgsql\bin`目录,执行 35 | 36 | 37 | ``` 38 | .\pg_ctl.exe start -D ..\data 39 | ``` 40 | 41 | 应该可以看到服务器运行成功之类的字样,表示数据库已经正确运行了。 42 | 43 | #### 配置 44 | 45 | 你需要简单学习一下`PostgreSQL`的操作。 46 | 47 | 建立一个数据库,来存储 `camel-store` 的数据。 48 | 49 | 文档中约定使用的数据库名为 `camelstore`,其为用户 `camelstore` 所有。 50 | 51 | ### 其它软件 52 | 53 | - [`git`](https://git-scm.com/) - 代码管理工具 54 | - [`node & npm`](https://nodejs.org/en/download/) - npm 包管理工具 55 | - [`python`](https://www.python.org/downloads/windows/) - 建议安装 3.7 版本 56 | 1. 安装的时候,有两个地方要特别注意,一是要勾选 `Add to PATH`,二是一定要把它安装到没有空格的路径下,比如 `c:\python37` 57 | - `wfastcgi` - 微软出的Python应用容器 58 | 1. 安装完`python`后在命令行运行 `pip install wfastcgi` 安装。 59 | 1. 再运行一下 `wfastcgi-enable ` 命令启用它,成功运行后,会输出一个目录,务必要记录起来,api部分会用到。 60 | 61 | ## 签出代码 62 | 63 | 1. 建议在 `C:\inetpub\wwwroot` 目录下,运行 `git clone https://github.com/gzqichang/camel-store.git --recurse-submodules` 把本仓库拉取到本地,记得需要加入 `--recurse-submodules` 参数。 64 | 1. 进入 `camel-store` 目录。 65 | 66 | ## api 部分 67 | 68 | 进入 `api` 目录,安装各种依赖。 69 | 70 | 1. 运行一下 `pip install -r .\requirements.txt` 71 | 1. 运行一下 `django-admin version` 看看是不是 2.2 版本。目前我们还不支持 3.0 或更高版本。 72 | 73 | `cd packages` 进入依赖包的目录,然后分别进入 `qapi`、`qcache`、`qsmstoken`、`quser` 目录,逐一运行 `python setup.py develop` 安装开发版本。 74 | 75 | 接下开始配置项目。 76 | 77 | 1. `cd conf/settings` 78 | 1. `copy local.py.tpl local.py` 生成本地配置环境。 79 | 1. 选择喜欢的编辑器,打开 `local.py` 文件,并把 `SECRET_KEY` 和 `DEFAULT_DB` 等项填好,记得 `SECRET_KEY` 要使用几十个字符的随机字符串。 80 | 1. 回退到 `api` 目录。 81 | 1. 运行 `python manager.py collectstatic`收集静态文件。 82 | 1. 运行 `python manage.py migrate` 创建各种数据表,然后运行 83 | 1. `python manage.py init_staff` 创建初始用户数据 84 | 1. `python manage.py format_groups` 创建初始分组数据 85 | 1. `python manage.py updateconfig` 修改配置。 86 | 1. `python manage.py wechatconfig` 修改配置。 87 | 1. `python manage.py changepassword admin` 修改之前生成的 admin 账号的密码。 88 | 89 | 这时候可以运行一下`python manage.py runserver`,然后用浏览器访问一下[http://127.0.0.1:8000/api/sitemap/](http://127.0.0.1:8000/api/sitemap/),如果看到的界面和下图差不多,表示项目在这台机器上成功运行,按`Ctrl-C`结束测试进程,就可以进行下一步了。 90 | 91 | ![](assets/image/runserver-test.jpg) 92 | 93 | 94 | 第三方配置,也是在 `local.py` 文件中,详见[第三方配置](third-party-config.md)。 95 | 96 | ## 准备 HTTPS 证书 97 | 98 | 因为小程序要求服务器提供`https`服务,所以我们的生产环境部署后是全站`https`的,需要准备 HTTPS 证书。 99 | 100 | HTTPS 证书在各在云厂商都有销售,一般来说,好像单域名证书是免费的,泛域名证书需要接近2000元/年。 101 | 102 | > 如果是测试一下camel-store,并不是真实商用,可以在[https://letsencrypt.org/](https://letsencrypt.org/zh-cn/)申请一个,可以免费使用3个月。 103 | 104 | 105 | 106 | 107 | 在 `api` 目录下,新建一个文本文件 `web.config`,写入以下内容: 108 | 109 | ``` 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | ``` 138 | 139 | 1. `scriptProcessor` 的值,要改为前文说过的运行 `wfastcgi` 输出的那个值。 140 | 1. `PYTHONPATH` 的 `value` 要改为 `manage.py` 的那个目录。 141 | 1. `WSGI_LOG` 的 `value` 改为存放log日志信息的目录路径。 142 | 143 | 另外,为了让静态文件的处理不经过Python这一层,建议往 `staticfiles` 和 `media` 目录下各放一个 `web.config` 文件,内容都是: 144 | 145 | ``` 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | ``` 155 | 156 | 如果改过前面的 `web.config` 文件中的 `name` 值,这里也要对应。这样就可以在获取静态文件的时候快一点了。 157 | 158 | ## admin 部分 159 | 160 | 进入 `admin` 目录。 161 | 162 | 1. 运行 `npm install` 安装项目依赖的模块,这里视网络的情况,估计要一点时间。 163 | 1. 运行 `npm run build`。 164 | 165 | 进入 `admin\dist` 目录, 新建一个文本文件 `web.config`,写入以下内容: 166 | 167 | ``` 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | ``` 197 | 198 | ## IIS 199 | 200 | `ARR` 配置 201 | 202 | 1. 在 `C:\Windows\System32\inetsrv\config` 目录下,打开 `applicationHost.config` 文件,找到以下内容,如果 `enabled` 的值为 `false` 的话,需要把值改为 `true`。 203 | 204 | ``` 205 | 206 | ``` 207 | 208 | 在 `IIS` 中新建2个网站。 209 | 210 | 1. 一个用 `wfastcgi` 跑 `api` 这个 python 应用,在 127.0.0.1:8000 监听,物理路径:`camel-store\api` 目录。 211 | 1. 添加虚拟目录,物理路径:`camel-store\api\staticfiles` 目录。 212 | 1. 打开浏览器,访问一下 `http://127.0.0.1:8000/api/sitemap/`, 如果可以看到 rest-framework 的界面,表示 api 已经正常运行。 213 | 214 | 1. 另一个就是做静态文件服务和转发对 api/ 的请求到 127.0.0.1:8000,在 *:80 监听,物理路径:`camel-store\admin\dist` 目录,把域名分配过去就好。 215 | 1. 打开 `URL重写` 功能,右侧的 `操作` 下方点击打开 `查看服务器变量`,打开后在右侧的 `操作` 下方点击 `添加`,添加服务器变量,名称为:`HTTP_X_FORWARDED_HOST`。 216 | 1. 打开浏览器,访问分配过去的域名应该可以看到 admin 的登陆界面,输入账号密码,可以成功登陆。 217 | 218 | --------------- 219 | 220 | 至此,部署完成。可以访问 `http://camel-store-win.gzqichang.com/`。 -------------------------------------------------------------------------------- /docs/deploy/nginx.conf: -------------------------------------------------------------------------------- 1 | upstream camelstore{ 2 | server unix:///home/ubuntu/project/camel-store/deploy/camel-store.sock; # for a file socket 3 | } 4 | 5 | server { 6 | listen 80; 7 | #listen 443 ssl; 8 | server_name YOUR_SERVER_NAME_OR_YOUR_HOST; 9 | 10 | charset utf-8; 11 | 12 | # max upload size 13 | client_max_body_size 50M; # adjust to taste 14 | # gzip 15 | gzip on; 16 | gzip_min_length 1k; 17 | gzip_comp_level 2; 18 | gzip_vary on; 19 | 20 | 21 | # Django media 22 | location /api/media { 23 | alias /home/ubuntu/project/camel-store/camel-store/api/media; 24 | expires 10d; 25 | } 26 | 27 | location /api/static { 28 | alias /home/ubuntu/project/camel-store/camel-store/api/staticfiles; 29 | expires 10d; 30 | } 31 | 32 | location /api { 33 | uwsgi_pass camelstore; 34 | include uwsgi_params; 35 | } 36 | 37 | location / { 38 | add_header Cache-Control ; 39 | alias /home/ubuntu/project/camel-store/camel-store/admin/dist/; 40 | index index.html index.htm; 41 | } 42 | 43 | location ~ ^.+\.txt$ { 44 | root /home/ubuntu/txt/; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /docs/deploy/supervisor.conf: -------------------------------------------------------------------------------- 1 | [program:camelstore] 2 | command = /home/ubuntu/.pyenv/versions/camel-store/bin/uwsgi --ini /home/ubuntu/project/camel-store/deploy/uwsgi.ini 3 | stopsignal=QUIT 4 | autostart=true 5 | autorestart=true 6 | user = ubuntu 7 | stdout_logfile=/var/log/supervisor/camelstore_access.log 8 | stderr_logfile=/var/log/supervisor/camelstore_error.log -------------------------------------------------------------------------------- /docs/deploy/uwsgi.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | env = LC_ALL=zh_CN.UTF-8 3 | uid = ubuntu 4 | gid = ubuntu 5 | master = True 6 | vacuum = True 7 | processes = 2 8 | threads = 2 9 | chmod-socket = 666 10 | 11 | chdir = /home/ubuntu/project/camel-store/camel-store/api/ 12 | wsgi-file = conf/wsgi.py 13 | socket = /home/ubuntu/project/camel-store/deploy/camel-store.sock 14 | home = /home/ubuntu/.pyenv/versions/3.7.4/envs/camel-store 15 | pidfile = /home/ubuntu/project/camel-store/deploy/camel-store.pid 16 | py-autoreload = 1 17 | 18 | ;log-maxsize = 50000000 # 50M 19 | ;max-requests = 1000 20 | ;socket-timeout = 120 21 | ;post-buffering = 100M 22 | ;harakiri = 1200 23 | ;buffer-size = 65535 24 | ;listen = 2048 25 | ;reload-mercy = 4 26 | preload=True 27 | enable-threads=True -------------------------------------------------------------------------------- /docs/dev-on-macos.md: -------------------------------------------------------------------------------- 1 | # 在 macOS 下建立开发环境 2 | 3 | ## 基础 4 | 5 | 使用 `brew install git nginx postgresql pyenv pipenv npm` 安装基础软件,在此需要小心,有不少配置事项,建议一个一个软件来安装,以免遗漏重要的信息。 6 | 7 | ## PostgreSQL 8 | 9 | 需要建立一个数据库,来存储 `camel-store` 的数据。 10 | 11 | 文档中约定使用的数据库名为 `camelstore`,其为用户 `camelstore` 所有。 12 | 13 | > 建议使用 [`pgAdmin`](https://www.pgadmin.org/) 这个应用来完成新建数据库和用户的操作。 14 | 15 | ## Python 16 | 17 | `camel-store` 至少需要 `Python 3.6` 或更高的版本,目前使用较多的是 3.6/3.7,建议使用 `pyenv` 进行本机的多版本管理。 18 | 19 | 运行 `pyenv install 3.7.4` 安装你心仪的 `Python` 版本,`pyenv` 的基本使用建议参考它的手册,在此均以 3.7.4 为例。 20 | 21 | ## git 22 | 23 | 1. 运行 `git clone https://github.com/gzqichang/camel-store.git --recurse-submodules` 把本仓库拉取到本地,记得需要加入 `--recurse-submodules` 参数。 24 | 1. 进入 `camel-store` 目录 25 | 26 | ## nginx 27 | 28 | 因为使用 `react.js` 编写管理后台,当调试 admin 的时候,需要 `nginx` 来分发静态资源请求和 api 请求。 29 | 30 | 1. 运行 `sudo ln -s $PWD/conf/camelstore.dev.com.nginx.conf /usr/local/etc/nginx/servers/camelstore.dev.com.nginx.conf` 31 | 1. 运行 `brew services restart nginx` 重启 Web 服务,以更新配置。 32 | 1. 运行 `echo "127.0.0.1 camelstore.dev.com" | sudo tee -a /etc/hosts` 把域名加到 hosts 文件。 33 | 34 | ## api 部分 35 | 36 | 进入 `api` 目录。 37 | 38 | 运行 `pyenv local 3.7.4` 把工作目录的 `Python` 设置为我们需要的版本。 39 | 1. 运行 `pip install -U pip setuptools` 升级包管理工具。 40 | 41 | 要安装各种依赖。 42 | 43 | 1. 运行 `pipenv sync` 安装虚拟环境。 44 | 1. 运行 `pipenv shell` 进入虚拟环境。 45 | 1. 运行一下 `django-admin -v` 看看是不是 2.2 版本。目前我们还不支持 3.0 或更高版本。 46 | 47 | `cd packages` 进入依赖包的目录,然后分别进入 `qapi`、`qcache`、`qsmstoken`、`quser` 目录,逐一运行 `python setup.py develop` 安装开发版本。 48 | 49 | 接下开始配置项目。 50 | 51 | 1. `cd conf/settings` 52 | 1. `cp local.py.tpl local.py` 生成本地配置环境。 53 | 1. 选择喜欢的编辑器,打开 `local.py` 文件,并把 `SECRET_KEY` 和 `DEFAULT_DB` 等项填好,记得 `SECRET_KEY` 要使用几十个字符的随机字符串。 54 | 1. 回退到 `api` 目录。 55 | 1. 运行 `python manage.py migrate` 创建各种数据表,然后运行 56 | 1. `python manage.py init_staff` 创建初始用户数据 57 | 1. `python manage.py format_groups` 创建初始分组数据 58 | 1. `python manage.py updateconfig` 修改配置,相关的参数看一下帮助。 59 | 1. `python manage.py wechatconfig` 修改配置,相关的参数看一下帮助。 60 | 1. `python manage.py changepassword admin` 修改之前生成的 admin 账号的密码。 61 | 1. 运行 `python manage.py runserver` 跑起来看看。 62 | 1. 打开浏览器,访问一下 `http://localhost:8000/api/`, 如果可以看到 rest-framework 的界面,表示 api 已经正常运行。 63 | 1. 再访问一下 `http://camelstore.dev.com:8080/api/`, 理论上来说,应该可以看到同样的页面。如果不能访问,可能是 `nginx` 的监听端口不是 8080。 64 | 65 | 第三方配置,也是在 `local.py` 文件中,详见[第三方配置](third-party-config.md)。 66 | 67 | ## admin 部分 68 | 69 | 进入 `admin` 目录。 70 | 71 | 1. 运行 `npm install` 安装项目依赖的模块,这里视网络的情况,估计要一点时间。 72 | 1. 运行 `npm start` 把 admin 跑起来, 73 | 1. 打开浏览器,访问 `http://camelstore.dev.com:8080/` 应该可以看到 admin 的登陆界面,输入账号密码,可以成功登陆。 74 | 75 | ## wxapp 部分 76 | 77 | 进入 `wxapp` 目录。 78 | 79 | 1. 运行 `npm install` 安装项目依赖的模块,这里视网络的情况,估计要一点时间。 80 | 1. 运行 `npm run build` 编译 `wpy` 文件。 81 | 1. 用`微信开发者工具`打开项目,可以在模拟器中看到小程序界面。 82 | 83 | 默认数据接口是 `http://camelstore.dev.com:8080`,你可以在 `src/service/index.js` 文件中找到以下语句 84 | ``` 85 | export const baseUrl = 'http://camelstore.dev.com:8080'; 86 | ``` 87 | 修改 `baseUrl` 的值即可访问其他接口。 88 | 89 | 90 | ## 其它 91 | 92 | > 推荐安装 [`fork`](https://git-fork.com/) 这个 git GUI 工具来完成其它日常操作,非常好用。 93 | 94 | --------------- 95 | 96 | 至此,开发环境建立完成。 -------------------------------------------------------------------------------- /docs/dev-on-windows.md: -------------------------------------------------------------------------------- 1 | # 在 Windows系统 下建立开发环境 2 | 3 | ## 基础 4 | 5 | 需要提前安装并配置好下列软件 6 | 7 | - [`git`](https://git-scm.com/) - 代码管理工具 8 | - [`nginx`](http://nginx.org/en/download.html) - web server 9 | - [`postgresql`](https://www.postgresql.org/) - 数据库 (建议安装10版本) 10 | - [`node & npm`](https://nodejs.org/en/download/) - npm 包管理工具 11 | - [`python`](https://www.python.org/downloads/windows/) - 建议安装 3.7 版本。 12 | 13 | 14 | ## PostgreSQL 15 | 16 | 需要建立一个数据库,来存储 `camel-store` 的数据。 17 | 18 | 文档中约定使用的数据库名为 `camelstore`,其为用户 `camelstore` 所有。 19 | 20 | > 建议使用 [`pgAdmin`](https://www.pgadmin.org/) 这个应用来完成新建数据库和用户的操作。 21 | 22 | ## git 23 | 24 | 1. 运行 `git clone https://github.com/gzqichang/camel-store.git --recurse-submodules` 把本仓库拉取到本地,记得需要加入 `--recurse-submodules` 参数。 25 | 1. 进入 `camel-store` 目录 26 | 27 | 28 | ## nginx 29 | 30 | 因为使用 `react.js` 编写管理后台,当调试 admin 的时候,需要 `nginx` 来分发静态资源请求和 api 请求。 31 | 32 | 1. 在`nginx`配置文件夹新增`camelstore.dev.com.nginx.conf`文件,写入以下内容: 33 | 34 | ``` 35 | server{ 36 | listen 8080; 37 | server_name camelstore.dev.com; 38 | location / { 39 | proxy_pass $scheme://localhost:8001; 40 | proxy_set_header X-Forwarded-Proto $scheme; 41 | proxy_set_header Host $http_host; 42 | proxy_set_header X-Real-IP $remote_addr; 43 | } 44 | location /api/ { 45 | proxy_pass $scheme://localhost:8000; 46 | proxy_set_header X-Forwarded-Proto $scheme; 47 | proxy_set_header Host $http_host; 48 | proxy_set_header X-Real-IP $remote_addr; 49 | } 50 | } 51 | ``` 52 | 2. 用记事本打开 `nginx.conf` 文件,在 http { } 里面加入 `include camelstore.dev.com.conf;`,以引用 `camelstore.dev.com.conf` 文件里的配置。 53 | 3. 用 `nginx -t` 命令校验配置文件是否正确。 54 | 4. 运行 `nginx` 以启动nginx,如已启动,则重启 `nginx -s reload`。 55 | 5. 以管理员身份运行 `echo 127.0.0.1 camelstore.dev.com >> C:\Windows\System32\drivers\etc\hosts` 把域名加到 hosts 文件。 56 | 57 | 1. 也可以管理员身份用记事本打开 `C:\Windows\System32\drivers\etc\hosts` , 末尾添加一行配置 `127.0.0.1 camelstore.dev.com`。 58 | 59 | ## api 部分 60 | 61 | 进入 `api` 目录。 62 | 63 | 1. 运行 `pip install -U pip setuptools pipenv` 安装升级包管理工具。 64 | 65 | 要安装各种依赖。 66 | 67 | 1. 运行 `pipenv sync` 安装虚拟环境。 68 | 1. 运行 `pipenv shell` 进入虚拟环境。 69 | 1. 运行一下 `django-admin version` 看看是不是 2.2 版本。目前我们还不支持 3.0 或更高版本。 70 | 71 | `cd packages` 进入依赖包的目录,然后分别进入 `qapi`、`qcache`、`qsmstoken`、`quser` 目录,逐一运行 `python setup.py develop` 安装开发版本。 72 | 73 | 接下开始配置项目。 74 | 75 | 1. `cd conf/settings` 76 | 1. `copy local.py.tpl local.py` 生成本地配置环境。 77 | 1. 选择喜欢的编辑器,打开 `local.py` 文件,并把 `SECRET_KEY` 和 `DEFAULT_DB` 等项填好,记得 `SECRET_KEY` 要使用几十个字符的随机字符串。 78 | 1. 回退到 `api` 目录。 79 | 1. 运行 `python manage.py migrate` 创建各种数据表,然后运行 80 | 1. `python manage.py init_staff` 创建初始用户数据 81 | 1. `python manage.py format_groups` 创建初始分组数据 82 | 1. `python manage.py updateconfig` 修改配置,相关的参数看一下帮助。 83 | 1. `python manage.py wechatconfig` 修改配置,相关的参数看一下帮助。 84 | 1. `python manage.py changepassword admin` 修改之前生成的 admin 账号的密码。 85 | 1. 运行 `python manage.py runserver` 跑起来看看。 86 | 1. 打开浏览器,访问一下 `http://localhost:8000/api/sitemap/`, 如果可以看到 rest-framework 的界面,表示 api 已经正常运行。 87 | 1. 再访问一下 `http://camelstore.dev.com:8080/api/sitemap/`, 理论上来说,应该可以看到同样的页面。如果不能访问,可能是 `nginx` 的监听端口不是 8080。 88 | 89 | 第三方配置,也是在 `local.py` 文件中,详见[第三方配置](third-party-config.md)。 90 | 91 | ## admin 部分 92 | 93 | 进入 `admin` 目录。 94 | 95 | 1. 运行 `npm install` 安装项目依赖的模块,这里视网络的情况,估计要一点时间。 96 | 1. 运行 `npm start` 把 admin 跑起来, 97 | 1. 打开浏览器,访问 `http://camelstore.dev.com:8080/` 应该可以看到 admin 的登陆界面,输入账号密码,可以成功登陆。 98 | 99 | ## wxapp 部分 100 | 101 | 进入 `wxapp` 目录。 102 | 103 | 1. 运行 `npm install` 安装项目依赖的模块,这里视网络的情况,估计要一点时间。 104 | 1. 运行 `npm i -g wepy-cli` 安排脚手架. 105 | 1. 运行 `npm run build` 编译 `wpy` 文件。 106 | 1. 用 `微信开发者工具` 打开项目 (在 `camel-store\wxapp\dist` 目录),可以在模拟器中看到小程序界面。 107 | 108 | 默认数据接口是 `http://camelstore.dev.com:8080`,你可以在 `src/service/index.js` 文件中找到以下语句 109 | ``` 110 | export const baseUrl = 'http://camelstore.dev.com:8080'; 111 | ``` 112 | 修改 `baseUrl` 的值即可访问其他接口。 113 | 114 | 115 | ## 其它 116 | 117 | > 推荐安装 [`fork`](https://git-fork.com/) 这个 git GUI 工具来完成其它日常操作,非常好用。 118 | 119 | --------------- 120 | 121 | 至此,开发环境建立完成。 -------------------------------------------------------------------------------- /docs/third-party-config.md: -------------------------------------------------------------------------------- 1 | # 第三方服务的配置 2 | 3 | 开始配置这一块之前,应当已经完成开发环境的配置,并已经做了一些基本的业务操作,如在管理后台添加商品,或者在小程序浏览商品等。因为我们已经假定本文档的读者已经比较熟悉`camel-store`了。 4 | 5 | > 因为这一块的配置和生产服的配置是一样的,所以独立出来了。 6 | 7 | ## 腾讯位置服务(腾讯地图LBS) 8 | 9 | 前往[腾讯位置服务](https://lbs.qq.com/index.html)注册一个账号,个人也可。 10 | 11 | 在“key与配额”中创建新密钥(key),之后,打开该key的配置界面,在“启用产品”中勾选“WebServiceAPI”,并选择“签名校验”的安全方案。如下图: 12 | 13 | ![key的配置界面](./assets/image/key-setting-ui.jpeg) 14 | 15 | 然后把上图的 KEY 和 Secret key( SK )配置到 `local.py` 文件,如下: 16 | 17 | ``` 18 | #腾讯地图api KEY 19 | TENCENT_LBS_KEY = '7HSBZ-7JWEX-*****-*****-*****-YUBTJ' 20 | TENCENT_LBS_SK = 'vUlg4PsYm*****h1IHVBRUlZmj4*****' 21 | ``` 22 | 23 | ## 小程序的基础配置 24 | 25 | 小程序 APPID:每个小程序的唯一标识,不可变更; 26 | 小程序密钥:查看流程:打开微信小程序后台,点击右侧 “开发选项 - 开发设置” 进行查看; 27 | 28 | 配置到 `local.py` 文件,如下: 29 | 30 | ``` 31 | WX_CONFIG = { 32 | 'WXAPP_APPID': 'wx**********b1956c', 33 | 'WXAPP_APPSECRET': '882cf1f5e343c45b074375**********', 34 | } 35 | ``` 36 | 37 | ## 微信支付配置 38 | 39 | 需要先去[微信支付](https://pay.weixin.qq.com/)申请,通过审核后,可以拿到商户号和商户Key,配置到 `local.py` 文件,如下: 40 | 41 | ``` 42 | #微信支付相关 43 | WX_PAY_APP_ID = "" 44 | WX_PAY_WXA_APP_ID = "wx**********b1956c" # 小程序 appid 45 | WX_PAY_API_KEY = "4060ac22342f11e5816000**********" # 商户 key 46 | WX_PAY_MCH_ID = "12********" # 商户号 47 | WX_PAY_SUB_MCH_ID = "" 48 | WX_PAY_MCH_CERT = os.path.join(BASE_DIR, "conf/cert_file/********apiclient_cert.pem") # 商户证书路径 49 | WX_PAY_MCH_KEY = os.path.join(BASE_DIR, "conf/cert_file/********apiclient_key.pem") # 商户证书私钥路径 50 | WX_PAY_NOTIFY_URL = "http://camelstore.dev.com/api/trade/468468418416846841684a6efaefa/" # 支付结果通知回调 51 | ``` 52 | 53 | 注:一般情况下,`WX_PAY_APP_ID`和`WX_PAY_SUB_MCH_ID`留空即可。 54 | 55 | 这里要注意一下,`WX_PAY_NOTIFY_URL`需要一个外网域名,所以一般来说,本机开发环境没有办法被外部回调,所以如果在`微信开发工具`测试,只能测试到订单付款页面,付款后因为订单不知道付款状态,所以会一直保持在“待支付”状态。 56 | 57 | 在开发环境中,记得要把`WX_PAY_NOTIFY_URL`的测试网址`http://camelstore.dev.com/`替换掉,上例中用的是 http,生产环境如果是 https,切记要注意加上s。 58 | 59 | ----------- 60 | 至此,基本上能在本机走完全部流程。 --------------------------------------------------------------------------------