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