TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
java实现微信公众平台开发项目源码
, |/ _! m% i9 f& T4 W本文向大家介绍使用Java来实现微信公共平台功能,实现根据回复的内容返回对应的消息。供大家学习使用。
. n; ?4 ?- R+ G# L' G# N微信服务端收发消息接口:WechatServlet.java
3 I# `( w8 m% ]7 S/ y: H" V) N z- package demo.servlet;
& j6 a6 l) O) G# C( P2 d5 g3 v8 q- i
& M U1 L" m% S, {6 z9 w- import java.io.BufferedReader;" K9 d d' n- P" P
- import java.io.IOException;
+ e2 r: U% W# t3 ]% N( v' ` - import java.io.InputStream;
& ~; V# a* b F- M) U; X - import java.io.InputStreamReader;
4 q7 l8 R5 {9 T& c5 |) V - import java.util.Arrays; i. I& P0 @* b+ S) o" B/ G4 h1 Y: O
$ e! T6 G) X: S8 R# n: p- k- import javax.servlet.ServletException;0 m; r1 K. i6 M! {$ l' ~5 t
- import javax.servlet.http.HttpServlet;$ f- Y* F% t! v, p# a4 t2 F
- import javax.servlet.http.HttpServletRequest;
9 b* m- ~4 D7 K/ P9 H3 ` - import javax.servlet.http.HttpServletResponse;- ]% u3 F5 n- v ~
. Q- @2 a6 P* n/ b7 i- import demo.process.WechatProcess;
3 m `2 g+ I# {7 K - import demo.util.SHA1;6 p$ O. c9 }8 n
- /**/ i4 H+ g4 Q) Q- T0 B2 o
- * 微信服务端收发消息接口( @ K8 _- s- `9 N
- *
1 y2 Q7 e" U8 z! |4 d, I( { - * @author 科帮网
5 \/ X' o, B6 |8 [, U - * 4 U0 f3 F/ `3 J
- */
# C8 l) \& R: T8 h - @SuppressWarnings("serial")
2 p1 A7 _! Q+ `: E6 [( X' y - public class WechatServlet extends HttpServlet {( }! V- M' _$ i
3 `( A8 ?( d3 R& i3 v! Q- // 自定义 token
- k. U# R, `# z0 n - private String TOKEN = "52itstyle";
- E4 [" u# } ?9 d h1 H - public void doGet(HttpServletRequest request, HttpServletResponse response)
' h% J: I, t' Y5 t7 l- \ - throws ServletException, IOException {
1 X7 s. s: B% P; H( s% d8 H - String signature = request.getParameter("signature"); // 随机字符串( N1 c) { G; b4 Q
- String echostr = request.getParameter("echostr"); // 时间戳1 F; [: |2 h! h
- String timestamp = request.getParameter("timestamp"); // 随机数: ] X- G5 J+ `: g
- String nonce = request.getParameter("nonce");
$ y# O2 X( K% Z0 S' R7 S -
. h" Y. R* ?0 N# G' V - String[] str = { TOKEN, timestamp, nonce };
: G! E# [- n+ l0 A5 E! X4 ? - Arrays.sort(str); // 字典序排序6 n9 e) o+ `9 k. V/ o' N
- String bigStr = str[0] + str[1] + str[2]; // SHA1加密
9 ^4 o p( l# n2 O& \. R' \* ] - String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase(); 0 [7 f, |/ E* W; s& c% a$ D' z
- // 确认请求来至微信
4 d* ?4 O% D* z1 C - if (digest.equals(signature)) {
^ F( U% l: C9 U! P. Q# v - request.setCharacterEncoding("UTF-8");* m+ X( p) I. J8 H! O5 g
- response.setCharacterEncoding("UTF-8");
/ Y5 T2 D, T( k5 e) T# m6 O# x/ W -
2 \& ^+ o E+ Q$ t5 p, C - /** 读取接收到的xml消息 */
) t8 E9 _3 T+ p - StringBuffer sb = new StringBuffer();+ u" U0 O% z. O/ \5 U
- InputStream is = request.getInputStream();; B* n3 D' e& H; Q/ u6 d
- InputStreamReader isr = new InputStreamReader(is, "UTF-8");& E1 H H( W+ U- r7 U' ^" o, @. g
- BufferedReader br = new BufferedReader(isr);" B! \. ~& p$ `
- String s = "";
' X- P# t7 Y7 f- @( A - while ((s = br.readLine()) != null) {1 G u Z" I0 U- P
- sb.append(s);5 V! ]) z: }% z: Y0 A# v
- }
7 T W+ E+ d3 J/ R) [5 {6 s+ ^ - String xml = sb.toString(); //次即为接收到微信端发送过来的xml数据3 N( q+ A( N5 R% ~8 [
- ( @- y* Z: _9 @
- String result = "";$ c9 S9 D3 n8 Q5 `& a$ ]7 m1 t Q
- /** 判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回 */
. y: {1 \. q/ R1 L1 E - if (echostr != null && echostr.length() > 1) {( J# N4 `# R, C
- result = echostr;: p. ~- B4 A: o7 G. z
- } else {9 g1 j: {/ z1 |7 S- h6 z
- //正常的微信处理流程* Y/ B. m/ ?3 o: e9 [( a
- result = new WechatProcess().processWechatMag(xml);+ O0 Z5 i2 y5 p5 Q+ u. m7 [
- }
4 {9 n' Y W$ u; E7 Z% w; E$ ? - System.out.println("说的什么"+result);4 X( X! X/ j. ~, O7 P4 _6 x
- response.getWriter().print(result);
9 G* w( e. V; o, F0 i) ^- j - } A+ J9 K1 O- r) j: v$ z0 {
- }
( ?* I5 r, n& L- H
( g6 S: m) f% L/ }, ]; V! M% Z$ A- /**
& N c# X4 j6 v3 I( n - * The doPost method of the servlet. <br>
2 }0 k! ~ I8 Z8 B, b8 C4 m' T - *
) i- T, C& I7 v' v, g+ F - * This method is called when a form has its tag value method equals to$ j; C9 I* t. F7 X3 ~1 U
- * post.8 h$ s- w9 l A
- *
6 h2 N# c4 X+ _, B, a - * @param request ] u5 m4 T! g6 |& _4 R( R- p
- * the request send by the client to the server
q1 Z6 [& r% C% G6 I - * @param response& R5 c( y4 G2 i x
- * the response send by the server to the client
% F: Q4 l2 K: s. w5 G9 G3 o, q; V - * @throws ServletException
6 `! g- g5 L' P Q, Z% K - * if an error occurred* a/ a3 E/ \$ d0 l; C
- * @throws IOException: N$ D! G6 D- m, y* L* e& E
- * if an error occurred
: v7 t& Z+ k( u# ~ - */
( j0 c/ A# X$ `2 ~: d' _: S - public void doPost(HttpServletRequest request, HttpServletResponse response)
9 |# x: Z( m/ ]& u5 v+ T6 c - throws ServletException, IOException {! t/ q5 j- E) U; e
- doGet(request, response);+ E! L) w$ ~. `" n3 z
- }8 L' O: U1 h" Z, \2 S
' G' ], `2 t; j$ y" b- }8 | Z2 |9 o. H, K* _& Y& j- z" ?
复制代码 接收到的微信xml实体类:ReceiveXmlEntity.java
' _9 N- S% T! _' b8 h" I8 {- package demo.entity;' n! l1 ?* x1 T5 @+ l
- /**' ` C3 J# O* \! u
- * 接收到的微信xml实体类
, R2 q6 u, f$ P: j( }( t* [ - * @author 科帮网
5 w! b& X9 T% I( U! {0 Q0 F - *
. Z- J/ \* U. x: Y - */) V! W& i1 W# N% P- t
- public class ReceiveXmlEntity {
; H3 \. p# p* U& v5 k; K - private String ToUserName="";2 J7 o& r: H) h) u) Q M
- private String FromUserName="";
( L, X0 `% h* m# w: S( \+ g/ \4 Y - private String CreateTime="";
# o1 m3 s0 t0 F0 k - private String MsgType="";
7 I a2 y# y( T - private String MsgId="";
0 l, k% Y9 X& C- J, ]9 r) ?) Y% Y - private String Event="";/ V( ]5 Q; F2 |, y8 f+ y. J
- private String EventKey="";* B1 A5 z8 h9 [( O; n0 t+ s
- private String Ticket="";
* ~+ W' ^) u* u7 m+ s& S - private String Latitude="";
6 B7 a! n3 B# j' @ - private String Longitude="";* ?+ }6 B; W6 A, k& w
- private String Precision="";, g* A! ~+ U* F2 h5 X) u3 E3 l. F
- private String PicUrl="";
. f( Q( T4 w; X( l d0 Z( M- F0 f - private String MediaId="";4 a4 r; c% `; F
- private String Title="";% `! K3 x/ V, ]0 L8 X3 L0 D
- private String Description="";
k# M9 C( ^7 B - private String Url="";4 P0 }) Z- D) Z0 L
- private String Location_X="";2 m9 S4 {) T+ |& P0 Z* @$ d' ]
- private String Location_Y="";
0 J W- g! [% x9 U; O - private String Scale="";
3 [- b+ g9 q! d- s; F3 p& V - private String Label="";1 I9 G( I3 I' j, k
- private String Content="";0 J6 s) H1 I7 u* I) B+ ]
- private String Format="";
. T; K* N9 d8 x. T - private String Recognition="";; B4 U% B3 K. D
- + l" s5 V2 Y* ]" n/ P$ l
- public String getRecognition() {
$ q1 f' j' ]$ Z9 {1 [' } - return Recognition;. M( f/ F5 X# ?
- }
t! E9 _" g8 ^' r* D7 ? - public void setRecognition(String recognition) {; S9 j& b; G9 N. q" D8 U% X* y
- Recognition = recognition;# y7 \7 K& G5 L/ ~; x/ m9 m3 I
- }
% R: f, W7 o+ | - public String getFormat() {
M% A: Y0 B. j q - return Format;$ j6 Z( W% n7 E9 g/ J
- }5 l0 J% e, _" x/ ?0 I s
- public void setFormat(String format) {5 v3 N8 X0 i+ T
- Format = format;( v7 g7 n! K$ ]5 J$ ], D
- }5 X7 M9 K* Z# G% Q; V5 h. k/ w) _9 t
- public String getContent() {
9 M9 m. F, [4 p9 U* x1 ` - return Content;' Y" d3 e+ J) s1 m& V+ ]
- }4 X7 g; f( U8 \4 a9 F% N
- public void setContent(String content) {
3 t: H! a u( x+ K8 J$ A - Content = content;# h, t- \ g- @) O( L; L, l9 w8 J
- }
# s- {( l$ M5 O; O, V* v9 } - public String getLocation_X() {7 v! t$ u; ~. N i; V
- return Location_X;, z- r- E- H6 w
- }) R! m/ J3 B9 Q' l$ F* C; s* y/ L7 ]
- public void setLocation_X(String locationX) {
, u {3 x: v$ `( d7 K - Location_X = locationX;5 x0 Z, G4 N2 f; ]/ \7 N& j
- }
7 i; l* C# D7 M( W" x U/ _0 m - public String getLocation_Y() {
8 j [0 d# z0 F; Q2 ~4 U$ k% V - return Location_Y;1 F7 @' e! v# g" N. A1 k. a
- }; |- j! W% H: l5 x( e; ^
- public void setLocation_Y(String locationY) {
' M3 a8 `! b: G% R; j e2 ? - Location_Y = locationY;7 S, @- r; ]9 d" ?- z2 [7 p
- }
0 K/ u$ C$ F( ?) | - public String getScale() {/ J# _: X& E: \/ |/ M$ e; B
- return Scale;) ]" G( @5 p* L3 H1 E8 y
- }
; X; C G) \4 S5 \ - public void setScale(String scale) {8 K& X1 k3 Z' c. P8 q6 M- k3 j. ^
- Scale = scale;
' w* J" v2 E5 y6 B - }
) P( v" g3 W: j+ s+ E - public String getLabel() {
2 E( ]' v" \% V - return Label;" Q% f6 y0 P2 V: K4 I P6 x
- }
6 H# b* }0 \ t" v7 H - public void setLabel(String label) { l& D; }. ~ r& G$ l' Y c' |
- Label = label;
; _6 h1 ]/ L2 Z5 N9 }) U: \ - }
& y$ }+ S7 W. Z5 m& X - public String getTitle() {1 H9 W+ O* {3 J9 y. C
- return Title;
: a' u: p, K* b& @0 x. u9 V: p: j - }
0 p& s5 ~& L' H: P - public void setTitle(String title) {
; l# q+ \9 f2 Q7 s9 E* A. p - Title = title;
+ `- y K8 d- k `% H$ J - }" k4 y# E9 P0 g: ]: F
- public String getDescription() {
! F! Z, p2 C8 ^) e# L8 B - return Description;
; D* u# K. { R3 G; y' z - }3 L9 j, l+ M* U" N3 b5 h9 y
- public void setDescription(String description) {: s" a- Y* Q8 T; E3 N
- Description = description;
! u% P. n" v# [: w2 B K- y' G5 A - }
4 Z" m4 G5 Y2 [9 N - public String getUrl() {
3 j- ]$ r) u6 O# Z9 F - return Url;; _% x' [ ~6 Q7 X+ f& L
- }' M3 C1 T' s6 q" V
- public void setUrl(String url) {0 m* N! B8 D) g6 k5 E8 S
- Url = url;
( y' j! ~! _% ^, S5 z' e1 h - }3 }/ B. H# h) ]" R* P9 W
- public String getPicUrl() {- @% {3 I( `6 @
- return PicUrl;
7 ~& }/ t; q1 B' _9 m - }
5 Z$ o8 T1 G1 v, \. @) t+ H - public void setPicUrl(String picUrl) { g' Y$ P( Y% z3 G+ K2 K3 q4 h; R
- PicUrl = picUrl;$ n) W( C, l, N! t5 f" x
- }
7 V8 q' y9 t* p% l7 g1 E$ c - public String getMediaId() {
4 r+ q6 K* }# \( Z" L, G - return MediaId;8 w2 N2 L, ?2 @# J. T- d
- }' j. u1 g! u0 f5 k- X u D
- public void setMediaId(String mediaId) {
- P9 }$ ?+ z: n2 J( r - MediaId = mediaId;- m4 B$ v1 [2 Q3 N; n& P0 Q
- }
. J) V4 k$ u, a ` - public String getEventKey() {
8 l& q6 w6 v+ s& d/ a - return EventKey;3 f$ ^5 d3 Y: W% x. I: k, i
- } R% ~$ Q) D& p7 N5 f5 `
- public void setEventKey(String eventKey) {$ i$ ^- e& j* i0 Z+ G! x
- EventKey = eventKey;, L1 o# |! A2 m
- }" k/ O6 A9 H( [8 {7 ?+ a9 D$ x7 H
- public String getTicket() {
1 V+ q8 ^4 H1 @" G0 D. {7 i$ _; R0 W - return Ticket;
! l) q# E" `5 U; H: ^ - }* k1 ?3 e F ~! |' |
- public void setTicket(String ticket) {7 d0 |5 W' K9 z6 O3 b
- Ticket = ticket;& w2 d. U, @) {: K+ C2 e
- }
7 S _# l* p& h2 |) q2 X/ U/ g - public String getLatitude() {6 d* E9 y( z+ E6 L# Y8 N
- return Latitude;
$ u+ v; S/ g4 Q! f - }4 E1 J, J/ _, D6 C- B3 C! T
- public void setLatitude(String latitude) {) I- C7 Y7 u. [$ \8 B& {$ ~; V
- Latitude = latitude;; D. h* K& x4 P( |
- }
" E6 k' G% h. `7 z9 l8 ` - public String getLongitude() {' j8 l) J7 L; n" M8 i3 T u6 Y
- return Longitude;
+ n' f6 } k& P+ m- k& n7 E - }, g* u; l2 H7 Y9 J: `
- public void setLongitude(String longitude) {; W& {) R/ o! x
- Longitude = longitude;
7 j# z: U" |, L+ A. t - }5 n1 e& \3 J' ~ x+ r( h
- public String getPrecision() {( F* p; R5 o: L' {
- return Precision;
8 k* ?( W; U4 A' I8 B! J) L - }& a6 E. d% c. {3 K; @; v$ s
- public void setPrecision(String precision) {
L2 [0 l9 i6 F' s1 A - Precision = precision;
% H- ?6 n; I5 ^ - }
* d& ~# f$ Y, Z& b" o( o - public String getEvent() {6 I2 w1 j! k! _5 `/ y. J
- return Event;) L+ d2 U9 @5 h, y( g
- }5 y& S0 Z, q+ _- V$ a; |, M5 W
- public void setEvent(String event) {
) h- @, Z% l# v7 O, a, s7 F( b - Event = event;
% b) u: ]% i2 y! c# a! t: o - }
8 ?: C \8 t3 ]/ @/ j( Q0 C2 a - public String getMsgId() {! S) G3 [/ ^* i$ |
- return MsgId;
e8 L3 H# J9 ~ - }
! _- X& y; u# g% G* V - public void setMsgId(String msgId) {8 Q. P0 c* l3 k D+ M" K! R4 @2 R
- MsgId = msgId;0 g2 W* D& Z7 ~1 F4 X) I
- }! J" u% [1 _. p% s7 j; y
- public String getToUserName() {# R" M: l: }2 {! U2 L7 y8 X
- return ToUserName;
3 O" [+ T7 o# i1 P. f2 y- Q - }5 h W4 Q, T" I
- public void setToUserName(String toUserName) {
& @% {9 W/ G1 e% q9 N0 j' l - ToUserName = toUserName;0 X; O- N o! V0 B R9 t9 U1 s3 s
- }
7 I4 [! b8 b& }. A5 Y" `% Q - public String getFromUserName() {
' j; X0 n; y% C1 y1 n7 g- P5 ~ - return FromUserName;+ J5 v& `% }: u# Z) V
- }
8 x& ^, S* ^6 D* e - public void setFromUserName(String fromUserName) {
" c7 b( t8 @5 n4 w) n- A - FromUserName = fromUserName;
" W/ @ o* y( y; G - }& B' \- g$ E _7 ~" S! k
- public String getCreateTime() {6 r2 D5 F# l1 E4 P
- return CreateTime;9 N/ J# u+ D2 Z" B
- }2 e. Z3 g) V, K; M# r
- public void setCreateTime(String createTime) {/ c9 \9 Y3 c( B) _; N4 D4 ~
- CreateTime = createTime;
7 D0 s" c' |" G: { - }
) z( Q5 Q Q% P$ s: g - public String getMsgType() {
$ c" V9 \, C1 N0 c* d7 ^/ W - return MsgType;
+ {% k/ ~4 J" t% ] - }
: ^ @# e. J0 l% J* }7 Y - public void setMsgType(String msgType) {
4 B* S, |: M8 `6 E7 l - MsgType = msgType;
0 a. j6 l, ]+ N5 f7 M - }
/ I ^2 N. z, z4 I1 g+ T( [' B - }# p, ]7 V b8 ~! a! ^ y* b
复制代码 调用图灵机器人api接口,获取智能回复内容 TulingApiProcess.java2 A9 J; t7 P* u3 U# _3 M* Q( E
+ K% f$ X. v( A: f- package demo.process;
& o& t5 I2 m; S - 1 j( ^2 p; ~ f: i9 l
- import java.io.IOException;3 G# e+ C, \, R% y2 R
- import java.io.UnsupportedEncodingException;# r% W1 }8 A. l5 g, w" X
- import java.net.URLEncoder;
' a% W4 U6 e) l y; d1 Q6 E( [ - , i. X k# `! ?4 ]0 \6 i
- import org.apache.http.HttpResponse;
* v) b1 w! s z - import org.apache.http.client.ClientProtocolException;3 K+ v9 F6 F; c" ^* `) d% m3 j
- import org.apache.http.client.methods.HttpGet;7 U% C/ v5 H a/ J( Q
- import org.apache.http.impl.client.HttpClients; I( Z$ P8 X: D, \
- import org.apache.http.util.EntityUtils;& w; J2 D7 O% ^6 T& D8 V; _& f
- import org.json.JSONException;$ i! |. W* K0 L! y1 i4 I: P' r
- import org.json.JSONObject;; d' F1 Q' R% S) w
1 X; H* ~% X' v, U( T- /**
3 X. ?1 O$ l% q* J: L3 a% G" Q/ q - * 调用图灵机器人api接口,获取智能回复内容7 {* f5 o, i: Z7 z5 [1 i
- * @author 科帮网7 b( L- N" X: V; N# e
- *! @+ N( T$ U' M: r, r6 p3 Q
- */
+ w6 h) ]. c* T& d L1 _1 H - public class TulingApiProcess {
' V# X( b* I2 J+ H; t, l; F - /**6 v. F7 x+ @0 w7 D. j$ L" m
- * 调用图灵机器人api接口,获取智能回复内容,解析获取自己所需结果1 e, ]& ?8 k$ J4 S4 J b
- * @param content
$ Z& }: j/ N! n i' O - * @return/ I q; }/ u# x j9 B$ S' ^
- */
1 {: \* h3 N) E& F# J8 I; m - public String getTulingResult(String content){! |+ p3 ]4 ^) }! @/ k" a+ A
- /** 此处为图灵api接口,参数key需要自己去注册申请 */! s1 `( V9 L3 \/ R8 D# }! k' t
- String apiUrl = "http://www.tuling123.com/openapi/api?key=2a31b2f601f74b54ea13db1c82fe5d71&info=";; ^$ E/ x6 D6 c5 ?% \" d7 m4 z; g
- String param = "";
3 O. ~& M$ y& O - try {
! B# M7 S8 D6 ?8 w1 V/ ~1 v1 }- s - param = apiUrl+URLEncoder.encode(content,"utf-8");
1 B6 h* K+ i1 L% P" W$ C - } catch (UnsupportedEncodingException e1) {/ o: g" @/ |0 Z* r3 V
- e1.printStackTrace();
q9 [+ q# Q G; l: R; D j- h; | - } //将参数转为url编码$ T5 `+ w, X9 P) B) W9 w
- /** 发送httpget请求 *// ]5 x; k ]. v$ X+ {0 y" X" f
- HttpGet request = new HttpGet(param);7 n. i$ D" |+ u5 s _4 f* z
- String result = "";
1 l$ n8 V: G7 ~: I1 r6 ]# t - try { |+ u$ U0 p3 a5 }
- HttpResponse response = HttpClients.createDefault().execute(request);
- w2 e( o4 C4 ? - if(response.getStatusLine().getStatusCode()==200){
4 V) W% A0 Y* K+ j - result = EntityUtils.toString(response.getEntity());' [& k& l3 T4 t6 G$ h# \) w9 W
- }
6 W9 k/ _% X- I$ h w7 s* M. ]0 Q" | - } catch (ClientProtocolException e) {" D! _ ]* [; p H, q+ A O
- e.printStackTrace();5 c4 p, q" N5 i8 v# e5 M
- } catch (IOException e) {; \+ n$ a/ @, f! e
- e.printStackTrace();
" R9 t+ S3 P' D - }. Z7 k# g! t5 W& d& }* l
- /** 请求失败处理 */
" y/ A+ U* U* i1 p/ A& a* A- n - if(null==result){0 M6 ~) n4 Z- R9 f/ h2 ~
- return "对不起,你说的话真是太高深了……";+ F/ j u" y {' ]4 V, p5 w
- }
- M, N* l6 S) C5 D' t -
D6 I' v6 H: q - try {/ L/ [- \, M6 u
- JSONObject json = new JSONObject(result);
! G) l& o* q8 n3 G4 n - //以code=100000为例,参考图灵机器人api文档: D8 ~# I: C/ P3 Y& [: }9 g5 H
- if(100000==json.getInt("code")){$ |7 n, u1 a# ^7 c* ]! ^/ i8 J. V
- result = json.getString("text");& S `& d+ \. H4 _0 R% l
- }
2 r0 t+ C) [6 Q& U* i6 L' w - } catch (JSONException e) {! c6 \( f& l7 ~% L+ i& A$ [
- e.printStackTrace();% ^$ d1 n9 l; M' n1 \& l& _2 J
- }
: }8 v! g6 k) s M4 l - return result;) Q& `: o0 X/ B8 p: E7 w8 F
- }2 ~0 w/ w% s" t) c# q
- }
/ B- d, a* J: g6 m0 f+ r! @
复制代码 7 i, y" D* e7 K* D( p' d! `6 T
web.xml 配置:4 u8 Z0 M; ^' p% l( J2 m
- <?xml version="1.0" encoding="UTF-8"?>; \2 I( V, L: g% S; M
- <web-app version="2.5" # y# F& s% u% M: b2 z o
- xmlns="http://java.sun.com/xml/ns/javaee"
+ A) M. Z! B- |1 Q0 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' q o/ }1 z2 E9 g
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
( Q, p2 G1 x+ \4 {( n( m. a - http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
7 l# ]7 _# `8 S4 J - <servlet>
5 y) e; N7 X& \* y2 \ - <servlet-name>WechatServlet</servlet-name>
; s( U, O& Q7 M" k - <servlet-class>demo.servlet.WechatServlet</servlet-class>; P& l" p0 G! L$ z, @
- </servlet>' T; x0 q w$ Z& `
- * _) W# @) f- j' d' i( {
- <servlet-mapping>
; T/ B' U0 V; G) \; P1 n - <servlet-name>WechatServlet</servlet-name>
) Y* H' U9 \9 M4 u) Q. s* | - <url-pattern>/wechat.do</url-pattern>* D7 ^% U; N: D! C, P2 [2 w) i
- </servlet-mapping>: E' l7 q% J t; E5 w. V3 `* f
- <welcome-file-list>
6 N; T% B/ @4 V+ |& J8 h( ? - <welcome-file>index.jsp</welcome-file>
5 G# K: F1 ~1 G7 H - </welcome-file-list>! X. ]6 k8 A- z
- </web-app>
5 k8 A/ d" P2 U P' Y
复制代码 8 }& p6 p% a! n3 E" ~9 e
项目源码下载地址:& a* b7 X& K' W
" C t( [/ S6 w
5 e; v& S- w; l; O7 o. ]- s4 K% ~
|
|