2
头图

This article mainly records the installation process of the Coupons project in the Linux environment

Coupons is a Taobao guest project that is completely open source from front-end to back-end. Currently, the project has been packaged into App, WeChat applet, QQ applet, and Web site; in theory, other applets are supported and may need to be fine-tuned.

Github address:
Project address: https://github.com/silently9527/coupons

Effect preview

image.png image.png image.png image.png
image.png image.png image.png image.png

1. Operating environment

Java

  1. Use yum to search for the installation package yum search openjdk
  2. Here we choose to install the Java8 development environment and execute the following commands

    yum -y install java-1.8.0-openjdk.x86_64
  3. Verify that the installation is successful

    java -version

Enter the following content to indicate a successful installation

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)

Maven

For the installation process of Maven, refer to 16137fd11e7ae0 https://silently9527.cn/?p=65

MySQL

For the detailed installation tutorial of Mysql, please refer to https://silently9527.cn/?p=63

Redis

For the detailed installation tutorial of Redis, please refer to https://silently9527.cn/?p=64

Nginx

For the detailed installation tutorial of Nginx, please refer to https://silently9527.cn/?p=66


2. Register a third-party account

1. Register a Dataoke account

The product data used in the MallCoupons back-end project is provided by Dataoke API;

First, you need to register for account 16137fd11e7b81 https://www.dataoke.com/

Enter the Dataoke open platform to create an application, and add all the API interfaces to the application with one click

2. Open MobTech's free SMS service (not required, you need to package the app to use it)

MallCoupons is logged in via mobile phone number and verification code in the App. MobTech provides a free SMS verification code service.

Register a MobTech account https://www.mob.com/

Enter the developer platform and create an application

3. Register QQ applet (not required, according to personal needs)

4. Register WeChat Mini Program (not required, according to personal needs)


Three, download the source code and unzip

wget https://codeload.github.com/silently9527/coupons/zip/refs/heads/master
unzip coupons-master.zip

Fourth, create a database and initialize

  1. Enter the password to log in to the MySQL database

    mysql --port=3309 -uroot -p
  2. Create database mall-coupons
create database mall-coupons default character set utf8mb4 collate utf8mb4_unicode_ci;
  1. Execute the following command to initialize the database
use mall-coupons;
source /Users/xxx/Downloads/coupons-master/doc/scheme.sql
Replace the file path after the source command with your own path;

Five, back-end project packaging

  1. Enter the coupons-master/server/src/main/resources directory of the unzipped project

    cd coupons-master/server/src/main/resources
  2. vim edit file application-prod.properties , modify the necessary parameters in the file
#填写前面淘客注册应用的 AppKey、AppSecret
dataoke.appKey=
dataoke.appSecret=

#填写前面注册QQ小程序的appId、appSecret
spring.social.qq.app-id=
spring.social.qq.app-secret=

#填写前面注册微信小程序的appId、appSecret
spring.social.wechat.app-id=
spring.social.wechat.app-secret=

# 配置MySQL数据库的地址
spring.datasource.url=jdbc:mysql://localhost:3306/mall-coupons?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=xxx

# 配置Redis服务器地址
spring.redis.host=
spring.redis.password=
spring.redis.port=

# mob短信服务的appkey,需要打包收集app的才需要
mob.service.appkey=
  1. Package the Java project

    mvn clean package -DskipTests

When Build Success appears, it means that the packaging is complete

After the packaging is complete, the current directory will generate the target directory, cd target enter the directory, check whether there is a generated file mall-coupons-server-0.0.1-SNAPSHOT.jar

  1. Start and run mall-coupons-server-0.0.1-SNAPSHOT.jar
java -Djava.security.egd=file:/dev/./urandom -jar mall-coupons-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod > ./mall-coupons-server.log  &

Six, Nginx configuration

  1. Enter the directory /etc/nginx/conf.d and create the configuration file coupon.conf
cd /etc/nginx/conf.d
touch coupon.conf
  1. Edit the configuration file coupon.conf and enter the following:
upstream coupons-services {
    server localhost:9090 weight=10;
}

server {
    listen       80;
    server_name  你的域名;
    include /etc/nginx/default.d/*.conf;

    location / {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,x-auth-token'; 
        if ($request_method = 'OPTIONS') {
            return 204;
        }
        proxy_pass http://coupons-services/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10000m;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port $server_port;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
  1. Restart nginx
systemctl restart nginx

Seven, front-end project packaging

  1. The source code directory of the front-end project coupons-master/client
    Import the front-end code into HBuilder, how to use HBuilder to import the project and package can refer to the official document https://uniapp.dcloud.io/quickstart-hx
  2. Modify the template id for sending SMS (only needed to package the app), pages/public/login.vue configures the id of the SMS template, the template id here needs to be applied on the SMS platform mob

  1. Purchase the mob-integrated plug-in at the plug-in center of uniapp; MobTech SMS native plug-in https://ext.dcloud.net.cn/plugin?id=2189
  2. Then configure appkey in HBuilder
  3. Configure the request address of the background api, edit client/config.js enter the domain name address of your server
module.exports = {
    // APIHOST: "http://localhost:9090"
}
The documents related to the coupons project have been updated to the blog: https://silently9527.cn/

Herman
632 声望3.7k 粉丝

知识星球:Herman's Notes