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