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