分享微信小程序签到考勤后端代码

相关推荐:《小程序开发教程

服务端源码

鉴于很多小伙伴给我私信,询问关于后端代码的事。很开心很帮助到这么多人。但之前由于某种原因没能将其与客户端代码一并发布,这里将代码发布到GitHub上,让大家方便下小白轻松搭建系统点我wcqh.cn载学习。这里用的是Java Servlet ,运行在 Web 服务器或应用服务器上的程序,作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层。数小白轻松搭建系统点我wcqh.cn据库使用的是MySQL,持久层使用了JDBC,Java的原生API。没有使用框架,方便新手学习,也更能理解web的运行机制和原理。

GitHub地址:传送门

这里要说明一下关键的代码:

1

2

3

4

5

6

7

8

9

1小白轻松搭建系统点我wcqh.cn0

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

6小白轻松搭建系统点我wcqh.cn0

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106小白轻松搭建系统点我wcqh.cn

107

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小白轻松搭建系统点我wcqh.cn40

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

/**

* Servlet impleme小白轻松搭建系统点我wcqh.cnntation class Login

*/@WebServlet(“/Login”)public class Login extends HttpServlet {

private static fin小白轻松搭建系统点我wcqh.cnal long serialVersionUID = 1L;

private static final String APPID=”xxxxxxxxxx”;

private static final St小白轻松搭建系统点我wcqh.cnring SECRET=”xxxxxxxxxxxxxxxxxxxxxxxxxx”;

/**

* Default constructor.

*/

public Login() {

// TODO Auto-gen小白轻松搭建系统点我wcqh.cnerated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 小白轻松搭建系统点我wcqh.cnresponse)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws Ser小白轻松搭建系统点我wcqh.cnvletException, IOException {

//ÉèÖÃÇëÇó±àÂë

request.setCharacterEncoding(“utf-8”);

response.setContentT小白轻松搭建系统点我wcqh.cnype(“text/html;charset=utf-8”);

/* ÉèÖÃÏìӦͷÔÊÐíajax¿çÓò·ÃÎÊ */

response.setHeader(“Access-Control-Al小白轻松搭建系统点我wcqh.cnlow-Origin”, “*”);

/* ÐǺűíʾËùÓеÄÒìÓòÇëÇ󶼿ÉÒÔ½ÓÊÜ£¬ */

response.setHeader(“Access-Control-Allow-M小白轻松搭建系统点我wcqh.cnethods”, “GET,POST”);

String flag=request.getParameter(“flag”);

//   System.out.println(flag);

if(“logi小白轻松搭建系统点我wcqh.cnn”.equals(flag)) {

String code=request.getParameter(“js_code”);

String url = “https://api.weixin.qq.co小白轻松搭建系统点我wcqh.cnm/sns/jscode2session?appid=”+APPID+

“&secret=”+SECRET+”&js_code=”+ code +”&grant_type=authorization_c小白轻松搭建系统点我wcqh.cnode”;

JSONObject sjson=CommonUtil.httpsRequest(url, “GET”, null);

/*String openid=””;

String session_ke小白轻松搭建系统点我wcqh.cny=””;

if (sjson != null) {

try {

openid = sjson.getString(“openid”);

session_key=sjson.getString(“sessio小白轻松搭建系统点我wcqh.cnn_key”);

} catch (Exception e) {

System.out.println(“ÒµÎñ²Ù×÷ʧ°Ü”);

e.printStackTrace();

}

} else {

Syste小白轻松搭建系统点我wcqh.cnm.out.println(“codeÎÞЧ”);

}

System.out.println(session_key+”  “+openid);*/

/*Map<String, Object> resul小白轻松搭建系统点我wcqh.cnt = new HashMap<String, Object>();

result.put(“res”, “test”);

result.put(“msg”, “ºǫ́ÒÑÊÕµ½”);*/

//   S小白轻松搭建系统点我wcqh.cntring json = new Gson().toJson(sjson);

// System.out.println(json);

Writer out=response.getWriter();

ou小白轻松搭建系统点我wcqh.cnt.write(sjson.toString());

out.flush();

}

if(“init”.equals(flag)) {

StudentDAO studentDAO=new StudentDAO小白轻松搭建系统点我wcqh.cn();

String userid=request.getParameter(“userid”);

boolean res=true;

try {

res=studentDAO.findCheck(useri小白轻松搭建系统点我wcqh.cnd);

} catch (Exception e) {

e.printStackTrace();

}

Map<String, Object> result = new HashMap<String, Obje小白轻松搭建系统点我wcqh.cnct>();

result.put(“res”, res);

result.put(“msg”, “ºǫ́ÒÑÊÕµ½”);

String json = new Gson().toJson(result)小白轻松搭建系统点我wcqh.cn;

//·µ»ØÖµ¸øÎ¢ÐÅС³ÌÐò

Writer out = response.getWriter();

out.write(json);

out.flush();

}

if(“student”.equ小白轻松搭建系统点我wcqh.cnals(flag)) {

StudentDAO studentDAO=new StudentDAO();

String userid=request.getParameter(“userid”);

Stri小白轻松搭建系统点我wcqh.cnng studentName=request.getParameter(“sname”);

String studentNum=request.getParameter(“snum”);

Student 小白轻松搭建系统点我wcqh.cnstudent=new Student(userid, studentName, studentNum,new Date());

try {

int a=studentDAO.create(student小白轻松搭建系统点我wcqh.cn);

if(a!=0) {

System.out.println(“²åÈë³É¹¦”);

}

} catch (Exception e) {

e.printStackTrace();

}

}

if(“teacher小白轻松搭建系统点我wcqh.cn“.equals(flag)) {

TeacherDAO teacherDAO=new TeacherDAO();

String userid=request.getParameter(“userid”)小白轻松搭建系统点我wcqh.cn;

String teacherName=request.getParameter(“tname”);

String teacherID=request.getParameter(“tnum”);

Teac小白轻松搭建系统点我wcqh.cnher tea=new Teacher(userid, teacherID, teacherName,new Date());

try {

int a=teacherDAO.create(tea);

if(小白轻松搭建系统点我wcqh.cna!=0) {

System.out.println(“²åÈë³É¹¦”);

}

} catch (Exception e) {

e.printStackTrace();

}

}

if(“guide”.equal小白轻松搭建系统点我wcqh.cns(flag)) {

StudentDAO studentDAO=new StudentDAO();

String userid=request.getParameter(“userid”);

System小白轻松搭建系统点我wcqh.cn.out.println(userid);

boolean res=true;

String state=””;

try {

res=studentDAO.findCheck(userid);

} catch 小白轻松搭建系统点我wcqh.cn(Exception e) {

e.printStackTrace();

}

if(res) {

state=”student”;

}

else{

TeacherDAO teacherDAO=new Teacher小白轻松搭建系统点我wcqh.cnDAO();

try {

res=teacherDAO.findCheck(userid);

} catch (Exception e) {

e.printStackTrace();

}

if(res) {

sta小白轻松搭建系统点我wcqh.cnte=”teacher”;

}

else {

state=”none”;

}

}

String json = new Gson().toJson(state);

//·µ»ØÖµ¸øÎ¢ÐÅС³ÌÐò

Writer小白轻松搭建系统点我wcqh.cn out = response.getWriter();

out.write(json);

out.flush();

}

if(“myInfo”.equals(flag)) {

String userid=re小白轻松搭建系统点我wcqh.cnquest.getParameter(“userid”);

StudentDAO studentDAO=new StudentDAO();

try {

List<String> list=studentDA小白轻松搭建系统点我wcqh.cnO.myInfo(userid);

Map<String, String> result = new HashMap<String, String>();

result.put(“backName”,li小白轻松搭建系统点我wcqh.cnst.get(0));

result.put(“backNum”, list.get(1));

String json = new Gson().toJson(result);

//·µ»ØÖµ¸øÎ¢ÐÅ小白轻松搭建系统点我wcqh.cnС³ÌÐò

Writer out = response.getWriter();

out.write(json);

out.flush();

} catch (Exception e) {

e.printSt小白轻松搭建系统点我wcqh.cnackTrace();

}

}

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)小白轻松搭建系统点我wcqh.cn

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletExce小白轻松搭建系统点我wcqh.cnption, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}}

登录后复制

这里的APPID和SECRE小白轻松搭建系统点我wcqh.cnT要使用你自己的。由于最近很少关注博客,咨询的人也很多,很多私信来不及回复,具体其它的就由大家自己探索喽。本程序纯属个人兴趣,切勿用于商业用途。

以上就是分享微信小程序签到考勤后端代码的详细内容,更多请小白轻松搭建系统点我wcqh.cn关注php中文网其它相关文章!

© 版权声明
THE END
喜欢就支持一下吧
点赞985 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容