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