TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
java实现微信公众平台开发项目源码
$ f6 z8 |0 r, o% `1 u4 G0 }8 [本文向大家介绍使用Java来实现微信公共平台功能,实现根据回复的内容返回对应的消息。供大家学习使用。
% w( `0 [- }# k9 W3 ?微信服务端收发消息接口:WechatServlet.java
6 p# N- z" q: _8 o- package demo.servlet;
/ }" ^$ \3 A$ U; l& E8 W
4 \6 `. J% O2 }) R! M+ G- import java.io.BufferedReader;- C* O0 `& L' I7 v* J3 u) o; X
- import java.io.IOException;& I5 X! Z# m! \% y. ?( U" S0 _8 u
- import java.io.InputStream;
2 D B' n6 x9 G/ Z( |; r. a - import java.io.InputStreamReader;
4 l0 p" \5 I- q; j; i( T - import java.util.Arrays;" h) b* a' c% _% E: b; `: h/ z
- o6 C; _4 F2 v& n1 J* G( s* k
- import javax.servlet.ServletException;
* c& j% u; Q3 ^% J \/ R - import javax.servlet.http.HttpServlet;
& {& S5 s+ Z" i, A - import javax.servlet.http.HttpServletRequest;
7 J8 f9 ?. R; g, A" v& S - import javax.servlet.http.HttpServletResponse;2 p& y" s4 o6 u: E" h/ F. o( b( ^
7 T; q: r3 S" z- import demo.process.WechatProcess;
6 p! S% E9 ?( Q7 J - import demo.util.SHA1;6 M4 W5 e# T n
- /**2 X9 Z7 F n2 M+ p6 n- w
- * 微信服务端收发消息接口1 ?" \3 v0 G4 k! |
- * 6 \. L. {* b6 T9 a
- * @author 科帮网
+ N8 S' v9 p( t8 t7 T* P( ] - * 3 Z; k% I" J% G B7 @5 A6 P
- */, V% L; u* n5 p9 s
- @SuppressWarnings("serial"): D. Y; U0 p8 A$ o! p( V/ L
- public class WechatServlet extends HttpServlet {/ i6 M6 V# @- [2 j3 J
, I- P2 G' ` u3 ^7 |" q+ U# \! B- // 自定义 token
" e2 O8 L" Y, A3 ^# q. q/ m: m - private String TOKEN = "52itstyle";
( s! S, O; @/ p0 a! m - public void doGet(HttpServletRequest request, HttpServletResponse response)
) W7 O/ k1 ?7 V1 A2 p - throws ServletException, IOException {
2 J# O/ T4 h7 H$ p5 S - String signature = request.getParameter("signature"); // 随机字符串
8 p& r$ u+ y; T# l/ t - String echostr = request.getParameter("echostr"); // 时间戳
4 {2 S7 H# E& H8 E - String timestamp = request.getParameter("timestamp"); // 随机数
( E8 y# i( w9 M6 _ - String nonce = request.getParameter("nonce");
% \' w1 @' W. Q$ k -
' ]4 u+ A# ?6 |& @+ r - String[] str = { TOKEN, timestamp, nonce };; n- ~8 L1 [, a; F2 F0 L* \
- Arrays.sort(str); // 字典序排序9 F! j5 a( v. Y) z& N
- String bigStr = str[0] + str[1] + str[2]; // SHA1加密% N8 g& M* m9 n0 x" s( l; L
- String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase(); . [4 ~" d" L y3 p. E8 ]( y0 ]
- // 确认请求来至微信$ S+ W% ^& v5 q H, i& p
- if (digest.equals(signature)) {
" r7 Z3 e' R' c! [ - request.setCharacterEncoding("UTF-8");) l& Q* Z' z: E0 G
- response.setCharacterEncoding("UTF-8");
1 k. N+ [- a4 k( v -
, ]/ R# a; B8 J4 a5 m) q - /** 读取接收到的xml消息 */! d% Q& m: o/ |0 k
- StringBuffer sb = new StringBuffer();& n- G) Q5 h4 E5 P' S. f% Y
- InputStream is = request.getInputStream();# ]9 _8 u" G* B$ s9 \& l& N3 w
- InputStreamReader isr = new InputStreamReader(is, "UTF-8");
" Y" `( i" v" S" S/ Z - BufferedReader br = new BufferedReader(isr);+ ~' K2 @6 K* k. L$ x U- ]
- String s = "";
: F" `9 v0 v' ?5 n - while ((s = br.readLine()) != null) {
, f% [- Z0 d5 E/ |6 c0 X% W - sb.append(s);3 w( i+ I( f, M3 X+ L6 q
- }
* ^/ A3 Z1 p9 S H& f - String xml = sb.toString(); //次即为接收到微信端发送过来的xml数据
- p I% o. ~% O8 n/ [6 B8 p - 0 X7 E& M! U6 o) ?: D4 a
- String result = "";# f3 u! y# H) p7 f$ l. M3 O7 @- r
- /** 判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回 */
; s: ]8 A3 a- E$ k* s4 n - if (echostr != null && echostr.length() > 1) {7 |3 c$ O* M- J5 N2 L
- result = echostr;# J+ Q8 |# A5 D
- } else { F |& N5 ~+ ?8 w: c6 a
- //正常的微信处理流程, j: M% e2 e( W2 K6 z$ r
- result = new WechatProcess().processWechatMag(xml);
9 c* h/ i1 w) A( A - }$ e1 u/ p' _" Z, u5 h- P, D
- System.out.println("说的什么"+result);$ i4 B1 O( }7 W6 q# d6 j( _
- response.getWriter().print(result);/ I: T% L7 z- x- d3 K8 j" T3 @) n
- }
" ~. {6 [% j* s4 t - }1 P; X! n2 H. @! u1 s
- E* s! _! {4 g$ B- /**8 d8 w) n+ N+ O; A: t i
- * The doPost method of the servlet. <br>& Q7 h& ?' n2 I- V
- * " T4 m1 }2 h6 \. {4 d
- * This method is called when a form has its tag value method equals to7 F6 D- Q& W( M& H5 D5 G( g
- * post.9 ^4 v. O& y& T# R2 f
- *
+ G' [$ R$ @6 b j% R. [- A# ?/ D - * @param request9 y5 T1 }; U! C* i
- * the request send by the client to the server \" ~ T1 A v7 V! n
- * @param response
0 z4 O. p6 |7 S. j: R& h5 { - * the response send by the server to the client! R6 [/ }; Z' s+ p( r
- * @throws ServletException
3 [& Q t. _+ X0 _( H' Z1 w - * if an error occurred, n( P, h v) C" u5 k/ G& {6 b
- * @throws IOException) v# d' K$ v. {" Q( q
- * if an error occurred1 X5 U2 B3 B" Y$ n7 W0 z
- */
: G+ Y0 B4 f, N+ q' m - public void doPost(HttpServletRequest request, HttpServletResponse response). C' u( {# {" u4 C
- throws ServletException, IOException {
6 B0 [' @7 G# U0 B5 \. n - doGet(request, response);8 l! @9 k+ E! R1 I6 B$ v6 |
- }
2 y% B* T0 A8 r: t - # B$ B2 k$ y( O, z
- }
2 e5 s; u9 Y7 V
复制代码 接收到的微信xml实体类:ReceiveXmlEntity.java
9 m' j2 g7 ^& X* _3 A6 K- package demo.entity;
1 r( F2 ~# b' B' ?( ]1 Q1 n( t - /**, o6 ^ y( ?& m* D( y
- * 接收到的微信xml实体类
. }* K7 d* M9 |7 w3 _2 b9 B - * @author 科帮网
6 h, {) L5 u# [ - *
4 T0 h; s# `; T+ h - */3 G$ R5 s# i6 N0 Y3 |' H+ K& b. i
- public class ReceiveXmlEntity {
" L* z* d8 c E$ @, m0 W! J4 E0 _ - private String ToUserName="";1 \0 X, }$ T9 U+ W
- private String FromUserName="";
6 w8 L: Z9 D0 D - private String CreateTime="";) ^- X; ]' g0 ^4 g/ `4 k+ f! n
- private String MsgType="";
4 y0 A. j- `- P: P" o3 z5 o* R - private String MsgId="";
, f1 h" `, Z2 h) {; i8 K2 v - private String Event="";7 X. ^& k: U# [# G! x
- private String EventKey="";
# I' Z+ T! A: e) i* i6 X1 R- `+ P+ z - private String Ticket="";
! K2 y. A7 b1 a# q - private String Latitude="";
/ |. c* m+ b* q b1 s6 ^+ q7 f - private String Longitude="";) P3 b2 R- [$ L4 a
- private String Precision="";+ i9 F/ R p1 S3 O# n
- private String PicUrl="";3 E' j/ m! E# c# k' `
- private String MediaId="";
9 @* ]% f4 s) m9 y! U) ~ - private String Title="";
+ I4 i7 `7 A5 i7 e5 | - private String Description="";
* C+ b( k' R( ?$ j% C* F - private String Url="";
# I2 E, z3 T5 [5 P2 y: d - private String Location_X="";
m/ ^" m' B! @% m+ b) M - private String Location_Y="";& ?# m0 m0 s/ X8 p1 k g
- private String Scale="";0 M/ ?4 }( ^% ?2 B1 `% v, \
- private String Label="";
" O& K. l( V: b5 k! r e" h - private String Content="";
7 c" }% e9 @- }( r3 Q - private String Format="";5 U/ s5 x$ {1 D4 O S8 ?/ S
- private String Recognition="";
) l2 X8 p- y3 N+ m6 C# _ -
/ e2 h x# }/ m* R - public String getRecognition() {' h; y: @& w/ e2 N, Q
- return Recognition;
& z9 y" g9 N( p0 X - }" y Y" u8 A9 N. `2 y
- public void setRecognition(String recognition) {6 b0 e6 t. Z1 X# u! n' I+ j* i
- Recognition = recognition;
. L9 a( I# S3 K - }
8 h. D$ S9 x" K3 j% A' [4 I - public String getFormat() {) D, S" I5 a+ L2 [! `
- return Format;; f- z4 w, s4 n
- }) b# y* G3 X6 f/ D! j4 b
- public void setFormat(String format) {+ H/ C. O5 z; c9 G6 i0 J$ r
- Format = format;
. o/ V$ i; R4 U2 f. c - }
2 A: V: A8 y, x6 @" f - public String getContent() {) B: P, E7 Y, j: t
- return Content;/ d) M- Z( j9 W7 s/ l
- }; {0 B* @. F6 j3 Y% _- a- l
- public void setContent(String content) {6 `* ~2 i4 M$ q4 ^& l; d
- Content = content;
( M" R& S0 Z/ T& z- |! u/ J - }
- M1 X0 P: e3 T, [! N c4 C - public String getLocation_X() {
/ A9 |/ {4 m3 n - return Location_X; {2 _+ m6 ?8 w+ {6 [- ?
- }
5 _/ b/ h5 d' j' W3 C - public void setLocation_X(String locationX) {
* @5 K* u# x0 U- _8 N" I - Location_X = locationX;# S. s+ \" [* @$ ~; r6 O
- }
4 M3 O& l, U# p3 I: C) K/ A - public String getLocation_Y() {
, o$ P3 q+ i- C6 [; J$ t - return Location_Y;
4 n( _4 l2 t F - }
* R4 U" W- l; R5 I0 n) E( a. ? - public void setLocation_Y(String locationY) {
/ _* {' k; N# } - Location_Y = locationY;
, p0 y1 ?5 K' Z - }' u2 `3 e7 Z- [/ T0 u+ \/ \ }
- public String getScale() {
: X* ?2 d& |, G - return Scale;. m C' M# Q% E, b( u2 f1 f6 J, w2 `2 ~
- }
4 U! C( `# y$ ^7 z+ V - public void setScale(String scale) {
- U8 p# \. F$ ?% \. ~' y - Scale = scale;
/ X6 f) m. p5 m3 s - }
5 U' r* a" E; p% j) Z$ u - public String getLabel() {
: m/ T% T$ Z- \8 @5 N, i - return Label;' g( g- V/ o6 x% ^/ R; K0 N4 t
- }
& [% ]) n+ c. ^4 L. A4 U - public void setLabel(String label) {
- F0 n# p2 E# S. L - Label = label;
& }( o7 T. l# c9 @0 \ - }
% m" R9 j: V) d2 R% v1 q - public String getTitle() {
# B! i) u9 K7 N& O2 | - return Title;# A) t; @7 I/ o' Z4 \8 I) C: i
- }
& d. Y9 `5 E* `* u) H# h0 b# ? - public void setTitle(String title) {
: k/ { s! \6 {# a - Title = title;
1 G2 j1 k* f4 G: b - }
+ O& S0 u2 l. Q" X: S - public String getDescription() {- i1 A" V1 y1 B3 f0 h
- return Description;
' h7 A* o4 j' _* w) j# G$ V0 P - }
* I: x6 T( X2 }6 E2 @7 s - public void setDescription(String description) {
) B+ w4 S9 [" A - Description = description;) k! U c7 T1 L: M8 Z% ]! a
- }
+ I' V# W% i) L* _2 k. M1 L* S - public String getUrl() {
( b" z9 G, P' T8 {5 Z' P - return Url;! s* P3 d g3 V+ z6 d1 Y* \# t
- }
/ C& m1 `8 g* o, j, t - public void setUrl(String url) {
1 F9 @3 b/ @* W - Url = url;, c; A& f+ B' G1 _- e: X
- }
# V; z" [3 e9 Y9 ~. V, @& L" R8 R/ j - public String getPicUrl() {
) ?6 x+ X8 h, w' V' f' h - return PicUrl;& r; C5 ?$ X2 f7 T& R8 t
- }+ s) W$ E5 G+ ?7 ~ b+ D
- public void setPicUrl(String picUrl) {
; C* u) B# z2 d$ _: g( b - PicUrl = picUrl;) g; ^' C( S, r: a( W. T' d
- }
' P5 S, r+ |" R R7 ]2 h, W; f - public String getMediaId() {
# U8 t9 X% a& ] - return MediaId;
) f, k% _1 A% O# O/ p7 \/ ] - }
4 s7 F0 f& X9 q8 _3 N2 P) q - public void setMediaId(String mediaId) {
6 ]5 v* {- h3 B) H - MediaId = mediaId;
/ [2 @+ ~( z4 w - }
; g& e9 G7 ~0 c! ~. w W - public String getEventKey() {. p# J1 J }5 K5 q: V2 c8 f' g3 P5 }* C0 W
- return EventKey;
* m+ i' ^: B" M - }
1 ?6 T0 F% [0 x$ Z7 T0 ?% f - public void setEventKey(String eventKey) {- n) g/ ~. b2 J# F" |5 C
- EventKey = eventKey;
1 M. _* q0 V) E/ N7 p - }
/ I- \' S6 k5 H7 E. F, @ - public String getTicket() {* x/ F/ `7 g1 \* P$ K+ u9 Q0 k
- return Ticket;- k/ s9 \* R9 R7 M3 ]
- }6 S7 L- u& G2 c! _5 q: d+ T" z
- public void setTicket(String ticket) {
5 O' C( M# L9 p9 J& f; m: b - Ticket = ticket;8 ^% a4 c* O" y k0 Y
- }
) u0 o; ?' i+ d - public String getLatitude() {% X5 j# P! q% T% z
- return Latitude;6 {8 S+ V6 s% `$ r& h& B* _
- }
4 M. [; F% j8 M3 B( s7 H0 M - public void setLatitude(String latitude) {) }; p0 @1 c+ t
- Latitude = latitude;! q4 [# i1 r) _; m0 }
- }3 p6 ^: N$ V/ m8 E: i
- public String getLongitude() {
7 P( Z0 k: z# E# h5 x& [$ g& u - return Longitude;4 Y1 h* T+ }4 X4 |
- }/ x4 {1 t( s9 m0 c$ U
- public void setLongitude(String longitude) {
0 D, w$ H% s: E' x+ A$ Q - Longitude = longitude;
* U& Y) l2 O% A' T* M: {/ u - }4 K! J/ q2 @* P) x' J. _
- public String getPrecision() {
) S0 d0 a' |2 Y! \4 \ - return Precision;
" D1 |7 C8 S7 V - }
+ {3 v- ^$ o5 k' h, f/ w* x - public void setPrecision(String precision) {
6 T" X N9 j6 M- o I5 H7 s - Precision = precision;
% a/ A) ?* ?; D E; X1 U( i - } g) r+ f7 Q* Y. N) G2 ?3 q- y
- public String getEvent() {
+ C7 N9 b0 \8 U3 P% H, l - return Event;( w; S$ I1 H& C; S
- }
& x/ r2 s$ D4 }, s$ B6 P - public void setEvent(String event) {
3 C' h2 f1 h2 v: O1 O1 b - Event = event;# v: ] N4 a2 ?7 D0 f
- }1 V5 m3 D* s9 \6 Y
- public String getMsgId() {; n& t+ S+ z2 X m
- return MsgId;6 N U1 u( v+ f' B& J( i* J' q
- }
; j3 M1 `7 y; ^2 n7 X+ ?9 ] - public void setMsgId(String msgId) {
: b& w$ n+ B" g9 E, o9 B - MsgId = msgId;8 U. T" c8 s5 u
- }
, r! `6 I+ e$ L+ I/ r - public String getToUserName() {
' Z, n( C/ x- s# _- I - return ToUserName;
- J# b5 E# z# \) M) r. ^, T, x - }
: R+ U( D2 \, N8 d, @* W- q - public void setToUserName(String toUserName) {& ]2 ?3 I0 x; ]9 x. a3 V4 p
- ToUserName = toUserName;4 v' ~5 Z$ D# S: n! w- R
- }
9 v# a G2 {: j2 f3 t - public String getFromUserName() {
( N- I5 U& U( A9 M& I, A! Y) U - return FromUserName; y/ x1 q" @! q
- }+ S! H/ ^# ]2 \# k; K- ?
- public void setFromUserName(String fromUserName) {
2 B ^& ^7 t8 P# m; @& [6 K - FromUserName = fromUserName;
2 K, O# ^; o3 M3 `; k7 I - }
' s3 f! l1 _2 T( Y, q - public String getCreateTime() {
4 W2 a' |2 U2 A( v - return CreateTime;' ?0 z# B' S2 l/ [
- }& @5 j* \0 t0 d$ Z9 D# r
- public void setCreateTime(String createTime) {
9 i: W$ A7 w/ y2 ` - CreateTime = createTime;* Q7 [* @9 E9 C/ C- |
- }
6 B6 y% @% W# T; u2 K. _ - public String getMsgType() {+ S0 C* |7 b0 l4 I; h$ v
- return MsgType;
8 D0 }1 y' K3 W - }
% J8 F( U L7 [- P1 Y - public void setMsgType(String msgType) {
2 f) e; g; t6 g J; q - MsgType = msgType;* z- X. R1 ]$ r1 Q$ D6 o
- }
, }( G: r, i1 a1 d - }
5 w6 b9 i! `3 y% \5 w- B
复制代码 调用图灵机器人api接口,获取智能回复内容 TulingApiProcess.java
7 c l( @6 R# d: W: j
* Z7 [9 L) Z& c& p& S- package demo.process;
; i! a- I, n& X- x8 C+ V( h - ; M: l5 e3 C3 v( |7 H- ^ Y+ `, h
- import java.io.IOException;
" ]" C p, y+ q; ~0 j( L - import java.io.UnsupportedEncodingException;5 j6 b: t! j$ H8 y* ~# o- I
- import java.net.URLEncoder;4 g1 O( r! n9 z; h& a3 K, J0 ^
! x: l* d% ?& D" S- import org.apache.http.HttpResponse;; x: Q5 W0 [% L% |0 m4 T" c" w
- import org.apache.http.client.ClientProtocolException;+ m2 v2 K6 t: p B' A
- import org.apache.http.client.methods.HttpGet;2 n3 O' R3 i' H/ h' G2 c
- import org.apache.http.impl.client.HttpClients;$ l3 y% L0 ]. v3 H, ~6 T2 ^" a2 O
- import org.apache.http.util.EntityUtils;
6 v8 E* f% b3 l - import org.json.JSONException;
# k& C% H$ A: b: w: s - import org.json.JSONObject;
( y @7 P( a$ v9 s% A0 d# X$ W; x
. ` }$ u6 ~/ U- /*** c- C4 Y7 l$ K2 Z$ ~! u8 d( ]
- * 调用图灵机器人api接口,获取智能回复内容
& Z2 q, a# K% f& n# ? - * @author 科帮网
4 C7 J$ S# j+ o6 D9 n - *% g1 {! G# ^2 r
- */( u( F/ @! s' C9 {( m/ i( e' T
- public class TulingApiProcess {
/ k; y5 [+ N! g, P: r' i& s* O - /**
5 N. C+ J/ [7 r) p; O& f - * 调用图灵机器人api接口,获取智能回复内容,解析获取自己所需结果. q' O2 g" Q( ?7 V6 f( o
- * @param content9 h; Z9 C6 p; N+ y) M8 D* J, W# Y* O
- * @return) J8 w9 l$ E& p' O7 N' [5 V
- */8 `+ i' s; a% h1 S* |- V- F" Q( Q3 O! Z4 G
- public String getTulingResult(String content){% W/ N& ]5 m" w9 ~' g/ D4 n6 T5 v
- /** 此处为图灵api接口,参数key需要自己去注册申请 */
# r/ t' k1 X3 D - String apiUrl = "http://www.tuling123.com/openapi/api?key=2a31b2f601f74b54ea13db1c82fe5d71&info=";
5 b6 c8 }0 P" K7 m. Q/ X' ?( t - String param = "";
q1 q: W+ Y3 s( J4 u; I - try {
7 @7 C/ ^: f( q' i/ a - param = apiUrl+URLEncoder.encode(content,"utf-8");( d' g7 H$ Q1 W7 L5 Q
- } catch (UnsupportedEncodingException e1) {
7 a! m3 {# s. x7 ~* S8 b - e1.printStackTrace();9 n) B6 \8 M8 C4 N
- } //将参数转为url编码
& c) |* E) g6 {7 c) d* z - /** 发送httpget请求 */. ^& w6 h( s" S" E' _
- HttpGet request = new HttpGet(param);/ y G& B+ G$ i8 z2 m( |- ]0 A+ G. o5 z
- String result = "";0 `0 V6 x5 y9 d6 R" p
- try {
$ S, h& B- c- o l0 ] - HttpResponse response = HttpClients.createDefault().execute(request);, f6 r" y0 b6 H! B& }4 l; r9 o: U
- if(response.getStatusLine().getStatusCode()==200){
* h$ r! M3 X" Q' _1 q8 `: M/ @$ N - result = EntityUtils.toString(response.getEntity());
; n' k6 Z& c7 F" O& E - }
) W' v( u1 Z: s$ X. p8 W4 d - } catch (ClientProtocolException e) {; b" j4 q- h8 v+ t3 Z% T
- e.printStackTrace();
( |$ ~* `1 {& i4 ~ - } catch (IOException e) {4 l% V7 [" w4 b9 v1 u) f
- e.printStackTrace();6 k5 z" q( z$ S1 K$ ?8 ?
- }
; A+ ]$ _1 p) F8 c; ]" J' ] - /** 请求失败处理 */( m& T- |) U" ?& [9 C a# U, m. a
- if(null==result){4 V6 C7 Y" ]3 V) k9 q3 p& d r, `
- return "对不起,你说的话真是太高深了……";- E0 e! W4 P% Y2 V. D( w7 z
- }
\! t9 `/ j! k0 {" n/ k - V) W7 {6 F; O
- try {
3 o4 T1 p" Z2 j- u - JSONObject json = new JSONObject(result);0 V# G( y# R# @3 j. S- {+ J
- //以code=100000为例,参考图灵机器人api文档
8 I+ t$ n0 Q2 `; J/ \# W9 `' F - if(100000==json.getInt("code")){
3 m! ?1 ?/ Y2 ^! q- e9 |% _ - result = json.getString("text");; a6 j; _. h2 y: I. x
- }
& I( K* w0 t8 e+ d - } catch (JSONException e) {
% T, @0 u! m+ f2 t/ z - e.printStackTrace();
9 S/ @7 l1 j$ m' `% t' F - }
# l- {. Q8 W" a) f+ o. { - return result;
+ g$ `7 K( q9 r0 K) ^+ t% m - }% o) l" `0 W, T# M3 t
- }
2 x" S- k$ A: m' W- }
复制代码
5 i/ `6 ^2 y0 q) g9 Oweb.xml 配置:$ Z( q; q+ O0 x$ i
- <?xml version="1.0" encoding="UTF-8"?>
8 E+ G7 _9 E8 u, P5 W+ s, p* n0 o0 V; x - <web-app version="2.5" . O8 T- H" z& `: Q
- xmlns="http://java.sun.com/xml/ns/javaee" 6 ~7 \2 T8 C! M1 y# g% a; c
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" $ L0 M6 p( ^5 X; q6 U6 M: u
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- M" ^# \1 F/ C' g. o5 T - http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">- I- g, x5 z' F! D$ D+ {' P
- <servlet>8 N: h& C* A* W# a5 \
- <servlet-name>WechatServlet</servlet-name>
% I" ]2 A) H3 |9 P4 z0 F6 I3 X - <servlet-class>demo.servlet.WechatServlet</servlet-class>% F' O5 G7 N3 D# q; T. J
- </servlet>
6 x: |1 {' `7 ^7 n) p- J1 {& j' S
8 T, g+ Z M8 ?+ n7 o0 q' r+ P) @- <servlet-mapping>
9 O& N" v1 _0 ~; C" e - <servlet-name>WechatServlet</servlet-name>- b( P2 u2 w% a" i- Z# L
- <url-pattern>/wechat.do</url-pattern>0 [' X9 C% L: q! d, ?
- </servlet-mapping>
) f2 |1 n3 K# ?% @* m - <welcome-file-list>7 f6 r4 c7 M/ `' [, _' I2 `* \ p
- <welcome-file>index.jsp</welcome-file>
4 H; V" @) |" x" Y - </welcome-file-list>
5 k5 {& B! R/ W! X - </web-app>
( U. [8 Q7 J& p/ P( N8 c
复制代码
" ~' G! K7 G1 z0 w& v项目源码下载地址:
) e B* a- j$ v5 X7 | X
7 l; T" `" n. S* x4 \# N" J
* \) w8 ^. j4 g1 [5 j0 L6 [# Y& H |
|