TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
java实现微信公众平台开发项目源码3 U; Q* [4 s$ I
本文向大家介绍使用Java来实现微信公共平台功能,实现根据回复的内容返回对应的消息。供大家学习使用。2 E" e: h! R# K% q
微信服务端收发消息接口:WechatServlet.java
* F3 j3 k# i7 c# @- package demo.servlet;6 F% t ]* g6 r7 M1 \! Q
2 h& z4 Y0 v g4 s- import java.io.BufferedReader;8 d+ u$ e0 K. {$ s* B$ q0 S; c8 E/ \
- import java.io.IOException;
+ f) H: c5 ~3 T: r& C - import java.io.InputStream;
# K+ ~ \3 Z$ t+ F) J0 C) j - import java.io.InputStreamReader;3 U1 n- L$ R$ I* q
- import java.util.Arrays;; o! z6 B8 k; ?3 e5 D
- ) R8 t8 u" }( l- ~1 K0 g9 Q H
- import javax.servlet.ServletException;
/ }6 B" Q* Q9 T& M+ _ - import javax.servlet.http.HttpServlet;# n2 z. r% j5 @# B
- import javax.servlet.http.HttpServletRequest;
+ T t0 M* E* B+ V4 X$ c& Z8 z - import javax.servlet.http.HttpServletResponse;
- U+ I9 z, @. t$ O9 C+ ~ m
- ~/ W) E c' ~$ f0 p- import demo.process.WechatProcess;
/ J- M5 Y: \2 k. o - import demo.util.SHA1;
' K- ]3 E. @' \, W+ V2 Z - /**
9 _- z: x1 W5 d" R8 }: r) t$ W2 p - * 微信服务端收发消息接口8 F& v" K: A1 S' Y- j! t" _
- *
& [6 X+ C* R5 J% |. j) _+ t( h - * @author 科帮网
2 e( F( p' y6 @& h1 ? - * 8 D8 l8 g' L3 W( J% F4 [! z
- */
8 R( o: O; P9 ` - @SuppressWarnings("serial")/ V; }& J* X& F1 s4 p
- public class WechatServlet extends HttpServlet {
- n* Y! x+ S+ V3 i% S4 ^ V
- p/ N$ o# V% g. \: p9 I- |- // 自定义 token
- {# |: H* Y9 h$ a4 [ - private String TOKEN = "52itstyle";
6 Y, N6 {+ p- c( h5 m - public void doGet(HttpServletRequest request, HttpServletResponse response)) R2 f( P( k/ N2 F& t& t+ r
- throws ServletException, IOException {+ `" {$ K1 ?! Z3 `8 z1 |) Y
- String signature = request.getParameter("signature"); // 随机字符串
* ~1 d, {$ E* L# ]) K* w - String echostr = request.getParameter("echostr"); // 时间戳; M! `- l: A& j b
- String timestamp = request.getParameter("timestamp"); // 随机数
4 u0 E+ Q, J0 U- s6 f l0 \ - String nonce = request.getParameter("nonce");% i. ]5 x$ @$ x) e
-
n# q' Z3 `; s5 Z/ Q) G - String[] str = { TOKEN, timestamp, nonce };- F# A; F" z' T3 V- c& n
- Arrays.sort(str); // 字典序排序
: a2 H! K7 h2 Z - String bigStr = str[0] + str[1] + str[2]; // SHA1加密7 K+ E2 M/ Z# [* I2 E1 E7 w) O
- String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase();
6 [. \! D5 l& o! I' r - // 确认请求来至微信
+ I2 I3 Z; m6 Z4 v c- t0 S4 E - if (digest.equals(signature)) {8 p9 O) H7 u2 {) w; X" H5 H
- request.setCharacterEncoding("UTF-8");0 V: N Y4 x. W
- response.setCharacterEncoding("UTF-8");6 l/ o# L, k* Q8 d+ v
-
/ h5 @' m( q9 Y2 z" } - /** 读取接收到的xml消息 */
4 r5 K- k5 `. x! H ?4 W - StringBuffer sb = new StringBuffer();
2 Z: d( t& l4 z$ Y9 [ - InputStream is = request.getInputStream();
. t; ~3 }* y I - InputStreamReader isr = new InputStreamReader(is, "UTF-8");: d b' D% \+ I$ L
- BufferedReader br = new BufferedReader(isr);
4 m' i2 i1 Z/ V: l+ w - String s = "";
/ {# S9 R5 }' A1 v2 s! _* l - while ((s = br.readLine()) != null) {
$ C. l9 e+ W% A2 }7 O) \ @ - sb.append(s);% Q" b1 B/ q' D- s/ l1 L
- }
6 R; q" i9 r: V9 s$ ^ - String xml = sb.toString(); //次即为接收到微信端发送过来的xml数据" D" I( D8 I: H
-
7 u0 h6 \1 j u! H1 Z9 E3 l - String result = "";
) K) R! E# x: d$ V& f - /** 判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回 */
! Z9 E9 A' O7 Y/ t# o. E& W - if (echostr != null && echostr.length() > 1) {
: f' \2 B4 Z9 E! l& l1 a - result = echostr;8 ?# e! x+ C5 w) X" W
- } else {2 Q: z" w: N/ L( L# T; ]2 l
- //正常的微信处理流程
2 {: T- A _1 M6 b$ X2 n9 d - result = new WechatProcess().processWechatMag(xml);
7 R4 _+ ~0 @, y6 ` - }
) A- {; w5 Q8 ?, F5 d - System.out.println("说的什么"+result);
; `# c3 ?+ {/ c! `! i/ K5 N P - response.getWriter().print(result);
- C; [7 f' b/ a9 T - }1 B7 p9 u- j2 Y2 x- i+ ?
- }
2 K& X4 R* m& @- R3 P. ?& {/ ` - " M9 v/ q' Y, f9 q
- /**
0 P0 `- `+ {/ z# W - * The doPost method of the servlet. <br>
( B: E6 j0 L& {! \ - * / m0 e( {# J( w' ~
- * This method is called when a form has its tag value method equals to) @. {4 \- Z2 x6 C. a E2 j# }0 m
- * post.! G; d9 [. ^( z6 J" [1 }
- * 3 L: \% }: T. h. C6 _
- * @param request- H$ {" l( g' C5 `$ G! s# _' h, e
- * the request send by the client to the server- Z }& F. |1 \6 {8 o" L1 y7 m. m
- * @param response% u p% D9 M- `: |/ b
- * the response send by the server to the client7 L( } p! o5 G; q& S6 |
- * @throws ServletException' X& A3 R' Q! P" r' g8 l+ ?
- * if an error occurred
" A, ~9 ^6 G% J% U - * @throws IOException: ?, s. T* N: d6 m
- * if an error occurred4 o( f) R0 G" ?! ^/ b
- */; e i% b4 u2 Y0 s
- public void doPost(HttpServletRequest request, HttpServletResponse response)' Z3 { Q& F. V; O( `
- throws ServletException, IOException {
* F8 U! z9 E. o: p& p - doGet(request, response);
* t+ K5 M1 G) |7 W8 u) c) [6 } - }
) ?/ Z6 s) X. n - S2 ]/ ]8 U: T- v) Z+ S7 V5 L
- }
# f0 c9 L+ ]) e1 B- V2 O0 |
复制代码 接收到的微信xml实体类:ReceiveXmlEntity.java
t- S) O/ \) p: A9 o- package demo.entity;
) W+ x* o, X& N* g. g - /**
# u) F3 @" t6 }" D - * 接收到的微信xml实体类8 H5 F4 K# v, ~0 @, g: B) N. P' X
- * @author 科帮网
) P8 I7 O5 L" ]" r - *( v. k9 O1 q, ?, t0 F( ?7 W
- */
* B4 u# Q! m# C - public class ReceiveXmlEntity {
) f6 I2 L5 q" d0 }9 | - private String ToUserName="";: c0 q- r- A" `; j; y! h! U6 D: O& o
- private String FromUserName="";0 L) w D/ _) B! A8 y# p
- private String CreateTime="";
" g0 k# R l+ Y. P/ h - private String MsgType="";
& K/ F/ [! m; q, X: r8 r+ P3 x - private String MsgId="";" Q; L5 ~0 E9 O8 b3 C
- private String Event="";
& f7 ^% N2 K) B* _1 P: {5 x - private String EventKey=""; R0 j, H- |$ a( T
- private String Ticket="";5 v; ]( P' t2 }
- private String Latitude="";
+ |& T: I: }: E+ z - private String Longitude="";+ S& Q3 y$ r7 B# n; Y1 n
- private String Precision="";) a# f- [7 e) T+ Q+ K3 Y% w
- private String PicUrl="";4 Y$ a8 M7 L4 h
- private String MediaId="";
9 O) b! M4 y& t" E; V - private String Title="";- e [% E9 N% W
- private String Description="";6 I' Q" H( _9 A3 U8 G
- private String Url="";( ]) z2 [7 X1 e( s" i2 Y/ o
- private String Location_X="";6 l4 ]' D' h+ E7 G+ W; X* a
- private String Location_Y="";5 p w. _1 X# s% r( g7 F
- private String Scale="";- ^- U& A6 Y# Q4 L6 y
- private String Label="";0 } r$ n _; h9 L; [2 l) J- t
- private String Content="";4 N# T# j, r- ]& G
- private String Format="";' Q: f( [6 D6 n* o& |
- private String Recognition="";/ H; }$ K& p- D. M6 e
- 8 A) i3 B: u* h6 V6 D# M3 a
- public String getRecognition() {
. {9 _/ ^* z6 a. d- ? - return Recognition;/ l1 r. \0 |* ?- o- W" H. g. P
- }% f$ o) x3 Q5 O$ R4 i
- public void setRecognition(String recognition) {8 v; ~& [2 N, x1 W0 c w+ v+ J
- Recognition = recognition;
0 k6 W! O! i2 }2 ~7 F& _; [ - }
3 `5 Z3 B' O$ ^, h - public String getFormat() {% O- w( M6 X) L; s8 z
- return Format;) k0 B8 z' a) q8 R3 \
- }
8 H8 X) P, f; L2 i. x# B# B - public void setFormat(String format) {
* P: m7 F1 H, s0 x - Format = format;
8 }4 ?) g$ E1 X D# z& `4 Z - }
1 s9 z$ m5 N" M4 ]8 u5 |9 R& [8 `) D! E, Y - public String getContent() {
# P; ?$ B; n; h - return Content;
" y, z3 _- J, P$ R" W5 n9 l - }: ]$ R( o: v& s% ~; X6 }+ n8 c9 j
- public void setContent(String content) {4 t+ W* v" r5 b! P) q6 ^
- Content = content;4 s1 K. u% P+ `) S" \8 R! Q
- }, a4 M) e& Q2 o, }! w
- public String getLocation_X() {
' K2 C9 r2 L- \ - return Location_X;
/ ^+ D! ~/ I. X T0 m) c, G+ D6 _ - }
4 G' H1 k6 A9 B8 h - public void setLocation_X(String locationX) {! b& y1 C2 m1 Y& |0 c
- Location_X = locationX;& k6 e7 ]3 \3 W5 @! L+ l
- }6 p( w- P! B0 v2 `4 i' D3 o
- public String getLocation_Y() {
& ^% t7 P( V+ ^+ [ - return Location_Y;
# d* t. y8 S, c - }- U G4 |* {/ _% ^6 h( X8 M+ Y
- public void setLocation_Y(String locationY) {2 t( I* J" I. F7 a
- Location_Y = locationY;
# [) U5 b1 b! c i# g3 M2 W/ ] - }; R" _2 @! {( I. u4 ]
- public String getScale() {% ~3 Q9 M s- R c; {
- return Scale;3 o5 k3 m. v; T" `% u9 _
- }
/ n7 c5 `/ o" q* l5 v% L - public void setScale(String scale) {8 x7 D! r& A9 x' p
- Scale = scale; ?$ L U! e3 j
- }- o" P6 A$ P% u, x" B$ |; T: s
- public String getLabel() {
- C3 a0 Z; z$ N - return Label;5 T' s$ a% C! R6 a& m" U* ?
- }3 Q! D+ ]% Q4 M2 I: d/ B! y) |
- public void setLabel(String label) {
0 i$ q' j6 Y* `0 c( p- J6 b - Label = label;
" I- d) H/ G8 ~ - }
- D# \, Z4 x* z - public String getTitle() {3 x2 I* [* o3 k) v( g
- return Title;2 |! g+ q: Y1 I, p* B/ ^
- }. S* O' B: @3 s. | s
- public void setTitle(String title) { C0 N+ j4 o/ k l0 [) I9 f
- Title = title;! _ C; w( D7 H" e# ~% w; N
- }
& C: @, ?& s" ?' Z3 U( D- t - public String getDescription() {
$ c- u2 c2 _: h: Y - return Description;
( @: X/ O6 r/ K% H: l' u$ U - }5 P5 E6 Y: l1 z& V: N# M) c; k$ s
- public void setDescription(String description) {
# L, b9 b6 p/ y) t. l - Description = description;
9 {. I$ M7 Y$ p2 `. f5 P - }
; T ^ D7 A( n' `4 z) ] - public String getUrl() {7 j5 W- n' ^' L4 y3 m
- return Url;
0 z |) ]/ p7 G; v; I - }2 O* O/ D: B5 L, ^
- public void setUrl(String url) {, r6 z9 k. z) z% P7 i+ E7 }
- Url = url;
& N# v: V. y( v; i, o- r n+ Y - }, e' I& H' X8 n R' K* Y
- public String getPicUrl() {
2 r) _+ P# B/ ?, {% n! a( m1 y - return PicUrl;
) B, @. s. y* M" _: [7 I4 v+ |7 U/ o& d- F - }
( |4 k4 p* |3 Y- @ - public void setPicUrl(String picUrl) {/ `) ^! O: ~7 h0 J" V. X; f( G
- PicUrl = picUrl;5 H( h; J6 G3 f" W+ u. ]! E
- }
|! K( [0 J$ @1 g - public String getMediaId() {
, }1 B1 c6 J, U2 X8 J0 T3 N - return MediaId;# X% `7 ^8 I" ]$ v0 F
- }6 P( H6 _: [+ n0 P( C0 ^
- public void setMediaId(String mediaId) {
, K ^1 q7 b% p$ G/ \! o - MediaId = mediaId;
% P) i2 W5 y+ q- k& I! b) u - }
+ k4 e: \3 R6 J: A7 @; U - public String getEventKey() {
4 N, V; d3 Q4 {( q) i7 G - return EventKey;
R( b9 g! I! z: \. Z; ~5 k - }
* X& J. [' n9 s) @: v - public void setEventKey(String eventKey) {
" [) _6 M- V. G) n) S - EventKey = eventKey;' F: I& |! c, s5 @3 w0 B
- }
5 Q+ u$ O9 U9 k3 { - public String getTicket() {
7 @1 n9 x) r/ A& g& s8 ~ - return Ticket;5 Y7 c, C1 X, |9 u. p" H& E5 J4 R* X
- }
9 h5 C% s" X- O% R$ ]+ k0 T - public void setTicket(String ticket) {& d6 m8 }! e, ~1 w6 h
- Ticket = ticket;- q! q4 l- g6 B
- }2 P/ p# R/ s' i! r( n
- public String getLatitude() {
. n: N( `# }+ W( e* | - return Latitude;' y% i: ^3 [; U `
- }
! Y4 b5 F; _, l* ?( [6 ` - public void setLatitude(String latitude) {! H8 a5 R8 H% q" a6 V& Y
- Latitude = latitude;) Y5 s% ?0 N- Z2 W
- } }% i, t' c/ ^! R# Z; p: d8 A$ e
- public String getLongitude() {) d* K7 y$ U4 a b
- return Longitude;
/ k) w4 N& S: D" r- p: g - }: J2 Z/ b! E6 ]3 p& y
- public void setLongitude(String longitude) {7 b; F( r1 _( ?5 T5 `* ^
- Longitude = longitude;
U" Y4 `7 R6 f1 L+ x, L - }
/ G0 `. v6 b$ Q7 r - public String getPrecision() {# z5 a4 U* K9 T
- return Precision;! ]) u" p2 q2 X+ U6 p, B
- }
# [: q' l4 N* c9 Q$ m( \5 J - public void setPrecision(String precision) {
7 m' _( W! Z- P; t8 E - Precision = precision;
$ s, c, J! S9 M# j - }* e. ~' P0 P& C+ d
- public String getEvent() {6 y! ?6 X7 E) Y" @3 E c
- return Event;$ L# H: ]$ v4 p- Y- _# {/ f# ]
- }
# h1 W# y1 |8 G; R - public void setEvent(String event) {
) b- g) e, M& {9 b3 v - Event = event;. T- {" d) T! ^$ `+ \& X
- }! i0 b/ z2 R' H! L" R- u
- public String getMsgId() {& N1 O( h; K9 @3 v3 B" X% g. U
- return MsgId;
- `/ a/ e0 |/ O! C2 A0 i9 u, p - }: M) I. q4 @! y5 |
- public void setMsgId(String msgId) {8 Y9 ?9 S% V8 t
- MsgId = msgId;
. B6 d5 y+ [- L |- @. t' K8 H2 \# v# v - }
" |- I4 m) t- b1 R( M8 Z; ?$ e! T - public String getToUserName() {
/ f9 L i+ ?" n# G - return ToUserName;
& C8 ]& R# J8 d6 ]) g0 Y - }, F2 Y& ?+ X' _2 a; c
- public void setToUserName(String toUserName) {" @9 G+ Y! f% ?( o$ a( q
- ToUserName = toUserName;+ K% G4 U8 b" \# C: f! l9 ] e- d
- }; o p) U- X7 f
- public String getFromUserName() {
* y1 D- y ?, j - return FromUserName;, g& V2 b9 w& b; h0 N
- }, U/ P: M; }; |7 X' T
- public void setFromUserName(String fromUserName) {! ?% q0 A I7 r! R8 g3 `4 Q) x+ J
- FromUserName = fromUserName;! R) x" L: v/ }; p, m `& `( x* P
- }+ @2 h8 P8 j t. P) T$ O3 d- u
- public String getCreateTime() {
6 R% | u1 J) {4 s N( I - return CreateTime;0 |+ d7 }- P" ]5 d
- }5 ?& ~9 B; j% I, R
- public void setCreateTime(String createTime) {; G7 }: K8 [* ` [
- CreateTime = createTime;0 Y+ e' |" `! D
- }
+ L% O' s% j! |5 C - public String getMsgType() {
4 i5 ` e2 X4 p, a: x$ c' s0 r - return MsgType;2 e" G3 C+ f. ~+ b+ r! _
- }
8 U) x( b) q7 }( N - public void setMsgType(String msgType) {
E& a4 g# z, z5 a: N - MsgType = msgType;
9 I: w7 D. ?+ W6 _ - }( m: U3 }) I5 [/ x- s
- }
4 |' t7 Q# J6 |$ T% J J' x
复制代码 调用图灵机器人api接口,获取智能回复内容 TulingApiProcess.java
6 O; L2 {* e( r7 Y) j9 n) n7 d S. l; ^
- package demo.process;
5 D: e: a/ T9 P9 r$ [: _9 z - {# W- G9 j" M: f3 u
- import java.io.IOException;
8 e5 B. G) {6 j( f' Q8 e/ b - import java.io.UnsupportedEncodingException;
# o) }5 e9 x2 j+ I- ^8 l - import java.net.URLEncoder;
' d. p+ e, s6 G. |
" {' L0 n* h% g+ H3 k& H+ m) V$ w6 ^- import org.apache.http.HttpResponse;
( \( y2 Z. e3 B) B" ]" l - import org.apache.http.client.ClientProtocolException;( t) G, u# } Y/ k' {& R1 y
- import org.apache.http.client.methods.HttpGet;
: O$ a+ O9 j, B - import org.apache.http.impl.client.HttpClients;
/ Q! ~( W( q6 q/ g7 P* T& y - import org.apache.http.util.EntityUtils;# T2 B" Q! l$ n1 A7 Y% s
- import org.json.JSONException;
+ B/ v% D6 Q" ` j5 } - import org.json.JSONObject;
C1 D. Z( R, b1 _
1 o+ F% k4 l5 u" e- /**
2 E* j7 r8 U# u - * 调用图灵机器人api接口,获取智能回复内容
9 v5 a) m9 i7 I) z. d - * @author 科帮网3 x* c- A. ], A8 a
- *
4 M# R/ D/ Y2 S: N" ` X/ l2 P, O! X - */
% S1 k/ R7 z2 U9 b. K8 D4 x- [5 j - public class TulingApiProcess {
! J( b7 }. P' n: ] - /**- Z- d- f6 s0 F4 X
- * 调用图灵机器人api接口,获取智能回复内容,解析获取自己所需结果
# [5 c1 ^+ L0 `% r2 K - * @param content
& f/ i4 g7 a0 w1 m% r - * @return+ B; [! F3 a w, s% P
- */: V! ?8 |: o+ Y6 e& H4 E: W
- public String getTulingResult(String content){8 G: _6 d" y: r; \4 K
- /** 此处为图灵api接口,参数key需要自己去注册申请 */. L* s6 m( O6 n
- String apiUrl = "http://www.tuling123.com/openapi/api?key=2a31b2f601f74b54ea13db1c82fe5d71&info=";
6 ?' A' H, U3 Y8 Z" Y - String param = "";
# u& i+ d% i3 g. D8 V( U) p+ I+ q - try {3 F/ _5 k: ~ J
- param = apiUrl+URLEncoder.encode(content,"utf-8");0 ^! ^0 I, ? f3 w0 ?
- } catch (UnsupportedEncodingException e1) {! b' G. H3 k: B8 c2 V& K" C
- e1.printStackTrace();1 I% S6 E- _$ R/ Z3 X/ ?( `$ i1 |
- } //将参数转为url编码& H. S/ R' `8 u$ ^* s: j3 n- l
- /** 发送httpget请求 */- M' `6 I0 b* ^0 V9 y/ h
- HttpGet request = new HttpGet(param);: M, x+ X: T z E9 a# B( \" n
- String result = "";* ]9 I/ L) B8 l4 K) S
- try {
6 C( r+ d: P) ^1 r. ] - HttpResponse response = HttpClients.createDefault().execute(request);
0 A. L( T# D" S; E9 h# ` - if(response.getStatusLine().getStatusCode()==200){' S" x" y* i" q0 ]2 G" K. Z- n: r
- result = EntityUtils.toString(response.getEntity());
$ B' ~0 [( B& `2 G8 m( _ - }+ I. s5 |! g* u$ a6 m9 H& }4 y; c) P
- } catch (ClientProtocolException e) {
E! H) t# p6 Y4 b( `9 w - e.printStackTrace();
# W. d) [4 T# H1 j# D3 R. @6 Z$ n - } catch (IOException e) {' _ \! o+ H3 W+ p4 {
- e.printStackTrace();- \0 `1 f" M# }+ l+ s# o
- }
6 X1 ^' {' R2 V- [/ t. q: _) c& X( [7 { - /** 请求失败处理 */* h' @' z( m1 S4 H e z; _7 o w9 n
- if(null==result){
- E5 G# ~" B) [8 k/ v - return "对不起,你说的话真是太高深了……";5 U- ~& K( b0 H5 O2 e6 h
- }2 T+ f$ Q- F7 V
-
$ c" n; d5 d: h# {7 ~- S7 j - try {$ k( L5 b+ D" ?/ f
- JSONObject json = new JSONObject(result);% T/ U0 V. x7 s1 i( s; S
- //以code=100000为例,参考图灵机器人api文档
! }$ e( z5 o9 z - if(100000==json.getInt("code")){
" D& Y6 a C3 Z G; {9 e+ b - result = json.getString("text");
* ~$ S- J$ i: X) E: G1 G - }8 F+ K& b8 v2 |* u
- } catch (JSONException e) {* `8 D! _! R# l* K3 I* P' }
- e.printStackTrace();$ y0 K& ^/ d. b# J' j) Z1 _
- }
0 ^1 a& i: v! A1 p1 ~/ U5 v9 {" d - return result;) _$ y) U" i3 l7 {2 J/ u
- }
8 Q8 j6 i' f6 i7 T# x; v - }
! |, g' {% \0 O1 a+ f$ X
复制代码 5 n" C/ p+ ?; `: }+ {. k+ F" }: @
web.xml 配置:
; O2 z# x+ M* k0 ]8 b8 C' q- <?xml version="1.0" encoding="UTF-8"?>: t, U3 v, H0 N6 s
- <web-app version="2.5"
- U* P; q+ H8 }. s - xmlns="http://java.sun.com/xml/ns/javaee" + [' d# Y2 B Q3 s$ V, c" Y
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 ~2 O5 I; Z6 N& I0 \; n2 T2 u
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 4 m* l7 q4 N! M" ?: a6 l7 J" H
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
8 N) i6 q/ K& h i - <servlet>
S" [/ [+ J+ M- N: V - <servlet-name>WechatServlet</servlet-name>* `8 \5 V" ^* q
- <servlet-class>demo.servlet.WechatServlet</servlet-class>
* a. e8 x* U5 F/ m& z/ J" ]! ~! O - </servlet>
0 f5 @2 M' P! w. u - 8 D3 u& C+ a7 y& s6 G9 b
- <servlet-mapping>! {0 b* u+ Y3 v& I! {
- <servlet-name>WechatServlet</servlet-name>' w) e+ q8 @6 Z) M4 f/ p4 h/ c2 _
- <url-pattern>/wechat.do</url-pattern>
6 h R3 J: [( k2 Q, n6 [8 E4 `9 z - </servlet-mapping>
0 x$ {8 H0 Y( A - <welcome-file-list>1 w( @2 R+ y) ^% p$ D2 G
- <welcome-file>index.jsp</welcome-file>7 G& P1 U z% g# m* T
- </welcome-file-list>6 a9 ]0 Z; s; ^ o( S% b& G4 o
- </web-app>
* q; b: @/ K3 |/ o$ G# z
复制代码
1 ~3 a7 A( h9 t6 G* J+ m) |4 l项目源码下载地址:
1 S2 l6 b [, r& k* b9 a9 v# p: y
) \& N9 K W" } ^8 t
; T' h/ D/ B& @3 S |
|