大家好,我是程序员小孟。
现在有很多的产品或者工具都开始信息话了,寺庙或者佛教也需要小程序吗?
当然了!
前面我们还开发了很多寺庙相关的小程序。
今天要介绍的是一款寺庙系统,该系统可以作为小程序、H5网页、安卓端。
根据目录快速阅读
- 一,系统的用途
- 二,系统的功能需求
- 三,系统的技术栈
- 四,系统演示
- 五,系统的核心代码
一,系统的用途
该系统用于寺庙,在该系统中可以查询寺庙的信息,可以在线查看主持,在线看经,在线听经,在线预约,在线联系师傅等。
通过本系统实现了寺庙的宣传、用户线上听经、视经,信息的管理,提高了管理的效率。
二,系统的功能需求
用户:登录、注册、寺庙信息查看、在线听经、在线视经、在线预约祈福、在线留言、在线纪念馆查看
管理员:用户管理、寺庙信息管理、听经管理、视经管理、预约祈福审核、留言管理、纪念馆信息管理、数据统计等等。
三,系统的技术栈
因为客户没有技术方面的要求,那就按照我习惯用的技术开发的,无所谓什么最新不最新技术了。
小程序:uniapp
后台框架:SpringBoot,
数据库采用的Mysql,
后端的页面采用的Vue进行开发,
缓存用的Redis,
搜索引擎采用的是elasticsearch,
ORM层框架:MyBatis,
连接池:Druid,
分库分表:MyCat,
权限:SpringSecurity,
代码质量检查:sonar。
看下系统的功能框架图应该更加清楚:
四,系统演示
五,系统的核心代码
package com.example.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.ShifuInfo;
import com.example.entity.UserInfo;
import com.example.entity.Account;
import com.example.exception.CustomException;
import com.example.service.ShifuInfoService;
import com.example.service.UserInfoService;
import cn.hutool.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@RestController
public class AccountController {
@Resource
private UserInfoService userInfoService;
@Value("${appId}")
private String appId;
@Value("${appSecret}")
private String appSecret;
@Resource
private ShifuInfoService shifuInfoService;
@GetMapping("/logout")
public Result logout(HttpServletRequest request) {
request.getSession().setAttribute("user", null);
return Result.success();
}
@GetMapping("/auth")
public Result getAuth(HttpServletRequest request) {
Object user = request.getSession().getAttribute("user");
if(user == null) {
return Result.error("401", "未登录");
}
return Result.success((UserInfo)user);
}
/**
* 注册
*/
@PostMapping("/register")
public Result<UserInfo> register(@RequestBody UserInfo userInfo, HttpServletRequest request) {
UserInfo register = userInfoService.add(userInfo);
return Result.success(register);
}
@PostMapping("/findUserByUserName")
public Result<List<UserInfo>> findUserByUserName(@RequestBody UserInfo userInfo, HttpServletRequest request) {
if (StrUtil.isBlank(userInfo.getName()) || StrUtil.isBlank(userInfo.getPassword())) {
throw new CustomException(ResultCode.PARAM_ERROR);
}
List<UserInfo> register = userInfoService.findByUserName(userInfo);
return Result.success(register);
}
@PostMapping("/wxFindUserByOpenId")
public Result<UserInfo> wxFindUserByOpenId(@RequestBody UserInfo userInfo) {
if (StrUtil.isBlank(userInfo.getOpenId())) {
throw new CustomException(ResultCode.USER_OPENID_ERROR);
}
UserInfo login = userInfoService.wxFindUserByOpenId(userInfo.getOpenId());
return Result.success(login);
}
@PostMapping("/wxFindUserByUserName")
public Result<List<UserInfo>> wxFindUserByUserName(@RequestBody UserInfo userInfo, HttpServletRequest request) {
if (StrUtil.isBlank(userInfo.getName()) || StrUtil.isBlank(userInfo.getPassword())) {
throw new CustomException(ResultCode.PARAM_ERROR);
}
List<UserInfo> register = userInfoService.findByUserName2(userInfo);
return Result.success(register);
}
/**
* 登录
*/
@PostMapping("/endLogin")
public Result<UserInfo> login(@RequestBody UserInfo userInfo, HttpServletRequest request) {
if (StrUtil.isBlank(userInfo.getName()) || StrUtil.isBlank(userInfo.getPassword())) {
throw new CustomException(ResultCode.USER_ACCOUNT_ERROR);
}
UserInfo login = userInfoService.login(userInfo.getName(), userInfo.getPassword());
HttpSession session = request.getSession();
session.setAttribute("user", login);
session.setMaxInactiveInterval(120 * 60);
return Result.success(login);
}
@PostMapping("/wxlogin")
public Result<UserInfo> wxlogin(@RequestBody UserInfo userInfo, HttpServletRequest request) {
if (StrUtil.isBlank(userInfo.getName()) || StrUtil.isBlank(userInfo.getPassword())) {
throw new CustomException(ResultCode.USER_ACCOUNT_ERROR);
}
UserInfo login = userInfoService.wxlogin(userInfo.getName(), userInfo.getPassword());
HttpSession session = request.getSession();
session.setAttribute("user", login);
session.setMaxInactiveInterval(120 * 60);
return Result.success(login);
}
@PostMapping("/login2")
public Result<ShifuInfo> login2(@RequestBody UserInfo userInfo, HttpServletRequest request) {
if (StrUtil.isBlank(userInfo.getName()) || StrUtil.isBlank(userInfo.getPassword())) {
throw new CustomException(ResultCode.USER_ACCOUNT_ERROR);
}
ShifuInfo login = shifuInfoService.login(userInfo.getName(), userInfo.getPassword());
HttpSession session = request.getSession();
session.setAttribute("user", login);
session.setMaxInactiveInterval(120 * 60);
return Result.success(login);
}
/**
* 重置密码为123456
*/
@PutMapping("/resetPassword")
public Result<UserInfo> resetPassword(@RequestParam String username) {
return Result.success(userInfoService.resetPassword(username));
}
@PutMapping("/resetPassword2")
public Result<ShifuInfo> resetPassword2(@RequestParam String username) {
return Result.success(shifuInfoService.resetPassword(username));
}
@PutMapping("/updatePassword")
public Result updatePassword(@RequestBody UserInfo info, HttpServletRequest request) {
UserInfo account = (UserInfo) request.getSession().getAttribute("user");
if (account == null) {
return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);
}
String oldPassword = SecureUtil.md5(info.getPassword());
if (!oldPassword.equals(account.getPassword())) {
return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg);
}
account.setPassword(SecureUtil.md5(info.getNewPassword()));
userInfoService.update(account);
// 清空session,让用户重新登录
request.getSession().setAttribute("user", null);
return Result.success();
}
@PutMapping("/updatePassword2")
public Result updatePassword2(@RequestBody ShifuInfo info, HttpServletRequest request) {
ShifuInfo account = (ShifuInfo) request.getSession().getAttribute("user");
if (account == null) {
return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);
}
String oldPassword = SecureUtil.md5(info.getPassword());
if (!oldPassword.equals(account.getPassword())) {
return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg);
}
account.setPassword(SecureUtil.md5(info.getNewPassword()));
shifuInfoService.update(account);
// 清空session,让用户重新登录
request.getSession().setAttribute("user", null);
return Result.success();
}
@GetMapping("/mini/userInfo/{id}/{level}")
public Result<Account> miniLogin(@PathVariable Long id, @PathVariable Integer level) {
Account account = userInfoService.findByIdAndLevel(id, level);
return Result.success(account);
}
/**
* 修改密码
*/
@PutMapping("/changePassword")
public Result<Boolean> changePassword(@RequestParam Long id,
@RequestParam String newPassword) {
return Result.success(userInfoService.changePassword(id, newPassword));
}
@GetMapping("/getSession")
public Result<Map<String, String>> getSession(HttpServletRequest request) {
UserInfo account = (UserInfo) request.getSession().getAttribute("user");
if (account == null) {
return Result.success(new HashMap<>(1));
}
Map<String, String> map = new HashMap<>(1);
map.put("username", account.getName());
return Result.success(map);
}
@GetMapping("/wxAuthorization/{code}")
public Result wxAuthorization(@PathVariable String code) throws IOException, IOException {
System.out.println("code" + code);
String url = "https://api.weixin.qq.com/sns/jscode2session";
url += "?appid="+appId;//自己的appid
url += "&secret="+appSecret;//自己的appSecret
url += "&js_code=" + code;
url += "&grant_type=authorization_code";
url += "&connect_redirect=1";
String res = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
// DefaultHttpClient();
HttpGet httpget = new HttpGet(url); //GET方式
CloseableHttpResponse response = null;
// 配置信息
RequestConfig requestConfig = RequestConfig.custom() // 设置连接超时时间(单位毫秒)
.setConnectTimeout(5000) // 设置请求超时时间(单位毫秒)
.setConnectionRequestTimeout(5000) // socket读写超时时间(单位毫秒)
.setSocketTimeout(5000) // 设置是否允许重定向(默认为true)
.setRedirectsEnabled(false).build(); // 将上面的配置信息 运用到这个Get请求里
httpget.setConfig(requestConfig); // 由客户端执行(发送)Get请求
response = httpClient.execute(httpget); // 从响应模型中获取响应实体
HttpEntity responseEntity = response.getEntity();
System.out.println("响应状态为:" + response.getStatusLine());
if (responseEntity != null) {
res = EntityUtils.toString(responseEntity);
System.out.println("响应内容长度为:" + responseEntity.getContentLength());
System.out.println("响应内容为:" + res);
}
// 释放资源
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
JSONObject jo = new JSONObject(res);
String openid = jo.getStr("openid");
return Result.success(openid);
}
@GetMapping("/wxGetUserPhone/{code}")
public Result wxGetUserPhone(@PathVariable String code) throws IOException {
//获取access_token
System.out.println("code" + code);
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
url += "&appid="+appId;//自己的appid
url += "&secret="+appSecret;//自己的appSecret
String res = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
// DefaultHttpClient();
HttpGet httpget = new HttpGet(url); //GET方式
CloseableHttpResponse response = null;
// 配置信息
RequestConfig requestConfig = RequestConfig.custom() // 设置连接超时时间(单位毫秒)
.setConnectTimeout(5000) // 设置请求超时时间(单位毫秒)
.setConnectionRequestTimeout(5000) // socket读写超时时间(单位毫秒)
.setSocketTimeout(5000) // 设置是否允许重定向(默认为true)
.setRedirectsEnabled(false).build(); // 将上面的配置信息 运用到这个Get请求里
httpget.setConfig(requestConfig); // 由客户端执行(发送)Get请求
response = httpClient.execute(httpget); // 从响应模型中获取响应实体
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
res = EntityUtils.toString(responseEntity);
}
// 释放资源
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
JSONObject jo = new JSONObject(res);
String token = jo.getStr("access_token");
//解析手机号
url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+token;
httpClient = HttpClientBuilder.create().build();
// DefaultHttpClient();
HttpPost httppost = new HttpPost(url); //POST方式
JSONObject jsonObject = new JSONObject();
jsonObject.putOpt("code",code);
String jsonString = jsonObject.toJSONString(0);
StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
httppost.setEntity(entity);
// 配置信息
requestConfig = RequestConfig.custom() // 设置连接超时时间(单位毫秒)
.setConnectTimeout(5000) // 设置请求超时时间(单位毫秒)
.setConnectionRequestTimeout(5000) // socket读写超时时间(单位毫秒)
.setSocketTimeout(5000) // 设置是否允许重定向(默认为true)
.setRedirectsEnabled(false).build(); // 将上面的配置信息 运用到这个Get请求里
httppost.setConfig(requestConfig); // 由客户端执行(发送)Get请求
response = httpClient.execute(httppost); // 从响应模型中获取响应实体
responseEntity = response.getEntity();
if (responseEntity != null) {
res = EntityUtils.toString(responseEntity);
}
// 释放资源
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
JSONObject result = new JSONObject(res);
String strResult = result.getStr("phone_info");
return Result.success(new JSONObject(strResult));
}
}
package com.example.controller;
import com.example.common.Result;
import com.example.entity.AddressInfo;
import com.example.service.AddressInfoService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@RestController
@RequestMapping("/addressInfo")
public class AddressInfoController {
@Resource
private AddressInfoService addressInfoService;
@PostMapping
public Result<AddressInfo> add(@RequestBody AddressInfo info) {
addressInfoService.add(info);
return Result.success(info);
}
@DeleteMapping("/{id}")
public Result delete(@PathVariable Long id) {
addressInfoService.delete(id);
return Result.success();
}
@PutMapping
public Result update(@RequestBody AddressInfo info) {
addressInfoService.update(info);
return Result.success();
}
@GetMapping
public Result<AddressInfo> all() {
return Result.success(addressInfoService.findAll());
}
}
```java
package com.example.controller;
import com.example.common.Result;
import com.example.entity.AdvertiserInfo;
import com.example.service.AdvertiserInfoService;
import com.example.vo.ChaobaInfoVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@RestController
@RequestMapping(value = "/advertiserInfo")
public class AdvertiserInfoController {
@Resource
private AdvertiserInfoService advertiserInfoService;
@PostMapping
public Result<AdvertiserInfo> add(@RequestBody AdvertiserInfo advertiserInfo) {
advertiserInfoService.add(advertiserInfo);
return Result.success(advertiserInfo);
}
@DeleteMapping("/{id}")
public Result delete(@PathVariable Long id) {
advertiserInfoService.delete(id);
return Result.success();
}
@PutMapping
public Result update(@RequestBody AdvertiserInfo advertiserInfo) {
advertiserInfoService.update(advertiserInfo);
return Result.success();
}
@GetMapping("/{id}")
public Result<AdvertiserInfo> detail(@PathVariable Long id) {
AdvertiserInfo advertiserInfo = advertiserInfoService.findById(id);
return Result.success(advertiserInfo);
}
@GetMapping
public Result<List<AdvertiserInfo>> all() {
return Result.success(advertiserInfoService.findAll());
}
@GetMapping("/getNew")
public Result<List<AdvertiserInfo>> getNew() {
return Result.success(advertiserInfoService.getNew());
}
@PostMapping("/page")
public Result<PageInfo<AdvertiserInfo>> page( @RequestBody AdvertiserInfo advertiserInfo,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
HttpServletRequest request) {
return Result.success(advertiserInfoService.findPage(advertiserInfo.getName(), pageNum, pageSize, request));
}
@PostMapping("/front/page")
public Result<PageInfo<AdvertiserInfo>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "4") Integer pageSize,
HttpServletRequest request) {
return Result.success(advertiserInfoService.findFrontPage(pageNum, pageSize, request));
}
}