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

网友投稿 384 2024-06-10

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

服务端源码

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

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

GitHub地址:传送门

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

1

2

3

4

5

6

7

8

9

10

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

60

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

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

140

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 implementation class Login

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

private static final long serialVersionUID = 1L;

private static final String APPID="xxxxxxxxxx";

private static final String SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxx";

/**

* Default constructor.

*/

public Login() {

// TODO Auto-generated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//éè-??ó±à??

request.setCharacterEncoding("utf-8");

response.setContentType("text/html;charset=utf-8");

/* éè-ìó|í·?êDíajax??óò·??ê */

response.setHeader("Access-Control-Allow-Origin", "*");

/* D?o?±íê??ùóDμ?òìóò-ó-éò??óêü£? */

response.setHeader("Access-Control-Allow-Methods", "GET,POST");

String flag=request.getParameter("flag");

//   System.out.println(flag);

if("login".equals(flag)) {

String code=request.getParameter("js_code");

String url = "https://api.weixin.qq.com/sns/jscode2session?appid="+APPID+

"&secret="+SECRET+"&js_code="+ code +"&grant_type=authorization_code";

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

/*String openid="";

String session_key="";

if (sjson != null) {

try {

openid = sjson.getString("openid");

session_key=sjson.getString("session_key");

} catch (Exception e) {

System.out.println("òμ??2ù×÷ê-°ü");

e.printStackTrace();

}

} else {

System.out.println("code?TD-");

}

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

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

result.put("res", "test");

result.put("msg", "oóì¨ò?ê?μ?");*/

//   String json = new Gson().toJson(sjson);

// System.out.println(json);

Writer out=response.getWriter();

out.write(sjson.toString());

out.flush();

}

if("init".equals(flag)) {

StudentDAO studentDAO=new StudentDAO();

String userid=request.getParameter("userid");

boolean res=true;

try {

res=studentDAO.findCheck(userid);

} catch (Exception e) {

e.printStackTrace();

}

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

result.put("res", res);

result.put("msg", "oóì¨ò?ê?μ?");

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

//·μ-μ-¢D?D?3ìDò

Writer out = response.getWriter();

out.write(json);

out.flush();

}

if("student".equals(flag)) {

StudentDAO studentDAO=new StudentDAO();

String userid=request.getParameter("userid");

String studentName=request.getParameter("sname");

String studentNum=request.getParameter("snum");

Student student=new Student(userid, studentName, studentNum,new Date());

try {

int a=studentDAO.create(student);

if(a!=0) {

System.out.println("2?è?3é1|");

}

} catch (Exception e) {

e.printStackTrace();

}

}

if("teacher".equals(flag)) {

TeacherDAO teacherDAO=new TeacherDAO();

String userid=request.getParameter("userid");

String teacherName=request.getParameter("tname");

String teacherID=request.getParameter("tnum");

Teacher tea=new Teacher(userid, teacherID, teacherName,new Date());

try {

int a=teacherDAO.create(tea);

if(a!=0) {

System.out.println("2?è?3é1|");

}

} catch (Exception e) {

e.printStackTrace();

}

    &n

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:9 款进度条特效推荐,值得收藏
下一篇:9 篇微商文章推荐
相关文章

 发表评论

暂时没有评论,来抢沙发吧~