TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
java实现微信公众平台开发项目源码/ N# l$ n7 m! O# h
本文向大家介绍使用Java来实现微信公共平台功能,实现根据回复的内容返回对应的消息。供大家学习使用。- I% S; u. y5 o% Y3 ~
微信服务端收发消息接口:WechatServlet.java* O( g& S4 ]4 `; {+ o
- package demo.servlet;
8 \2 a6 K$ A' p* p8 u - 7 |$ A& u/ _/ A3 R9 ?
- import java.io.BufferedReader;% q K* V4 {! o0 X/ r
- import java.io.IOException;
; q4 G$ }8 t+ O$ I$ i. i$ q - import java.io.InputStream;
% J! p7 _; N/ ] V, o - import java.io.InputStreamReader;+ `& X' q3 A! V# t4 _1 v: \8 U
- import java.util.Arrays;
* H. ]9 Q, Q% o0 H8 ` [
6 {8 I; U4 a7 Y4 L, k' s9 \1 A- import javax.servlet.ServletException;7 Z* L, l1 C! v
- import javax.servlet.http.HttpServlet;
4 L% G3 `: s& q% A- c2 H' c# w - import javax.servlet.http.HttpServletRequest;
5 g5 G$ `( u6 I" p% C! T5 ~1 C+ I - import javax.servlet.http.HttpServletResponse;+ f& m: `; I# l% _* [/ q
. i: e6 v2 h) m. B# @- import demo.process.WechatProcess;, ~! G" @ ]7 c3 Q
- import demo.util.SHA1;
1 f! `4 z/ R* q - /**
0 w# P! O4 S, I0 c) D - * 微信服务端收发消息接口
8 Y @' e& c% c R/ Z5 M+ y, | - *
# E/ \' q* q) f( ~: q4 v5 h9 I - * @author 科帮网
1 @* Y! \+ ~" D# K - * 7 Y+ f' c7 K" ] u
- */
4 ]" S/ i% N6 D% n& E, L' p/ z" D - @SuppressWarnings("serial")
$ `% ~9 k \: k/ U9 u0 P$ Y- j - public class WechatServlet extends HttpServlet {
_# m5 A: V0 @& t3 l
7 t( F' o M2 t# _+ ^- // 自定义 token* h' I; Y& r) i: w! t g
- private String TOKEN = "52itstyle"; + f9 o1 g& f+ |# V% m
- public void doGet(HttpServletRequest request, HttpServletResponse response)1 z g7 Q2 ?1 O" k: j
- throws ServletException, IOException {
6 s% E* s) Z; C - String signature = request.getParameter("signature"); // 随机字符串1 P) i; `6 W6 M8 S& G: [7 Q- N
- String echostr = request.getParameter("echostr"); // 时间戳
* r6 l8 z# K* o5 ]5 v0 r - String timestamp = request.getParameter("timestamp"); // 随机数
+ N+ g4 @- ]( W W, V' n% Q1 O$ T2 i! s - String nonce = request.getParameter("nonce");
) O- u; @- O O' X' @4 O1 ? -
) J! Z1 C" c/ v) h - String[] str = { TOKEN, timestamp, nonce };& g' a! Q4 B7 @( `
- Arrays.sort(str); // 字典序排序
3 _, F0 l6 |- C9 ^* Y0 |$ \2 | - String bigStr = str[0] + str[1] + str[2]; // SHA1加密
& o& \1 v7 P. Z0 h - String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase(); ( I% {: ?' Z# `
- // 确认请求来至微信: x3 _+ V9 W5 V0 Q5 `) J- Q# j
- if (digest.equals(signature)) {
/ ?( I& I% x/ _3 h8 k( W c - request.setCharacterEncoding("UTF-8");
2 C: U8 o5 ~" z - response.setCharacterEncoding("UTF-8");
8 }' \/ d- x2 f0 K! J, B3 ^) h - # a1 t1 y4 ]/ N- x
- /** 读取接收到的xml消息 */4 C: j$ r5 ~4 Y, n5 U2 A/ Z
- StringBuffer sb = new StringBuffer();3 s+ J' m- c4 v1 A Q' o
- InputStream is = request.getInputStream();
) n* s2 m2 @. X0 K - InputStreamReader isr = new InputStreamReader(is, "UTF-8");
6 ?- C( q+ Q2 w& {5 k) s& o7 o - BufferedReader br = new BufferedReader(isr);
6 Q, O# l4 h h: m9 G/ v: U4 n$ i - String s = "";
/ L; K3 Y0 l- C0 O - while ((s = br.readLine()) != null) {' j; Z$ a) w4 z$ S
- sb.append(s);
9 l' d# q2 L( d# _4 [9 X s - }
2 o/ R+ a: Z l! I( S - String xml = sb.toString(); //次即为接收到微信端发送过来的xml数据
! A% T+ _6 C$ b$ ^. d" \4 O - 8 ^7 K. |9 q* `! ^, T; r( n
- String result = "";
: A3 ]4 E+ P0 E4 ^# H1 y/ R H - /** 判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回 */8 r& J6 c( u7 {: y. h- _2 R
- if (echostr != null && echostr.length() > 1) {: g! \" z9 a9 k6 X
- result = echostr;
. u, S. g, A$ `* ?6 } - } else {! p. g; m7 _+ d( X
- //正常的微信处理流程
" P/ }7 a# E8 b3 t2 [) l - result = new WechatProcess().processWechatMag(xml);( B2 U0 Z4 A& H5 m. L
- }8 G( H: ~$ x6 S1 ~0 O( Y
- System.out.println("说的什么"+result);# N4 I* J' u3 ]3 e& a
- response.getWriter().print(result);5 i, l: C. \6 M \3 l- B
- }
: Y" U$ @ z r - }# V7 Y% p3 F; ^
- / N' S9 K6 }& K! C4 {0 C
- /**
) B; F3 @% m- m1 i - * The doPost method of the servlet. <br>
8 U8 g. z9 b/ P) {4 e8 v - * 6 q! t- J! q. |0 | J
- * This method is called when a form has its tag value method equals to
0 V8 ~0 Q2 _& K2 ~ B; I( q - * post.
. p& Z) h" D" S* o1 K) R - *
2 \1 w* u- g9 k* y- B2 m. g - * @param request
3 |! m) c8 c, ]2 E# u* L) z - * the request send by the client to the server
# k# i* I7 U1 d' c/ f M - * @param response2 e d. j/ N0 {
- * the response send by the server to the client
5 x3 V- h. W9 r$ W- _2 Z - * @throws ServletException. L1 o' p9 ^" a# ^' Y1 |( ? e
- * if an error occurred
0 E/ M4 ~* k8 q1 |- q$ N! E - * @throws IOException7 u: s3 b i7 j
- * if an error occurred
: [# j4 p7 A& m l& h) C8 m - */5 l& I0 I; x; [# s
- public void doPost(HttpServletRequest request, HttpServletResponse response)
9 u! U3 a' g3 ` - throws ServletException, IOException {' D/ J9 }) B7 ^+ Y j$ N. z w5 o
- doGet(request, response);
$ b1 t7 B$ I: k, {. b - }8 U% q) i: Z8 \
& o2 C- U) P, X1 D( P/ L- }
, i% |: i: l! E1 F$ w3 Z! |
复制代码 接收到的微信xml实体类:ReceiveXmlEntity.java3 g+ O4 q" W b" w ?
- package demo.entity;
% d1 ^# s9 ~$ g" p - /**& f& h% y- h) W1 B$ y4 ?( w( z
- * 接收到的微信xml实体类 C/ y! Z! a, ]2 d+ o! j
- * @author 科帮网
6 o( k% B& U, t/ b: d. V9 ? - *2 L1 I. j) l) i' x* Q8 P/ J
- */4 g/ ?) _$ E# Z8 h
- public class ReceiveXmlEntity {
! J7 e, i/ Y9 h z - private String ToUserName="";
, D; A6 h, v; K* M9 e" p - private String FromUserName="";
) v$ o* s3 s2 }( y X8 P0 k' } - private String CreateTime="";
' Z" N6 z5 k& a7 W - private String MsgType="";7 x# n( L3 F8 ^9 i: P
- private String MsgId="";8 x5 z! p5 {6 Q. [. E( G
- private String Event="";0 C3 N+ c2 H& q: U# o g5 A' E4 a
- private String EventKey="";+ B) F! F- ?: o: P
- private String Ticket="";1 x% T t- C9 O! r0 j5 E) g
- private String Latitude="";' c$ r" {( A7 z4 c
- private String Longitude="";" v& s$ ~( z2 ^& O' o. D
- private String Precision="";
, k/ w! p( c; F - private String PicUrl="";
' C+ D; W8 B8 ^" D) g! U - private String MediaId="";
4 u7 `" `$ `; J- z- m; H, `+ | - private String Title="";
# F$ b7 n! n# l; l1 S, _7 t - private String Description="";
u0 g% r9 u& o; z: ?3 D" N - private String Url="";
3 J$ M+ P0 V; x8 ?! [4 i; J( ^ - private String Location_X="";' J( V4 n0 z5 @ Y7 z, C: g5 Q
- private String Location_Y="";
& ~5 u4 ? K; ~$ ` Z. h9 n, i - private String Scale="";, S. l* G: [+ X& H( H
- private String Label="";
! H) ]1 `' W+ R; R. h- y - private String Content="";
' H! [" k8 A# A1 e4 O' [# t - private String Format="";
, L" R0 C( ~) M d/ P5 b' Y - private String Recognition="";' }3 Z4 h4 l1 h4 r3 P S
-
- w# i0 ^# e4 i0 c& J; ~: P" c - public String getRecognition() { L0 d5 k( q( G) c Q+ {$ ^
- return Recognition;
5 r! d" X+ j( w: _+ ~" q - }
; ~& r3 D4 m" @9 U6 c - public void setRecognition(String recognition) {
. Y' ]6 T% }. J2 l- b - Recognition = recognition;
Z! l( J0 G0 D: P7 N+ B3 P7 P - }9 ?6 o0 e8 M2 N
- public String getFormat() {: r) y6 E( }. h+ X
- return Format;
% X! X7 r8 m4 n% R4 ~9 [2 C - }
' B, z" h4 A* Q, m) K - public void setFormat(String format) {
$ l7 M8 p3 s, w8 ?. U - Format = format;
& e& Y, T* F' l* C - }
9 ]0 `6 L: } k3 | - public String getContent() {
, w4 P# d8 d. G% j9 p, K - return Content;
" p0 o/ ^2 c% M( O - }. u g: g* @7 t2 Y4 }
- public void setContent(String content) {
: H! I* ]0 |1 | - Content = content;9 B4 p9 W. y6 R$ w- E
- }$ @ l2 Y9 m* w& U# P
- public String getLocation_X() {: I' S" l2 R0 B; q& S
- return Location_X;/ d/ g* p2 B2 p9 G! A
- }
3 x: v! ^8 `( @! G% B r C# W - public void setLocation_X(String locationX) {
# M( s, k3 |4 b) U - Location_X = locationX;
0 D3 m2 y i' K$ p - }
/ ]" t o. {. `: h* z7 v - public String getLocation_Y() {
, ~2 ]: E" l, r! t5 O7 u - return Location_Y;
2 \$ q4 n0 b2 ~8 U+ F$ i - }
5 `% ^: j) s4 _8 ^9 V, ` - public void setLocation_Y(String locationY) {& J1 E8 t# @' h
- Location_Y = locationY;
* R L. E, b+ t3 a% B- ?1 s - }# D7 ~1 t5 f+ A; o
- public String getScale() {
8 N: b$ ^& S$ ?! n8 g - return Scale;
' d* G# M1 r6 Z4 L; a - }
1 S: Q; u4 |8 C* d- z! R% v7 [. T. n - public void setScale(String scale) {2 |' U& ^- I0 f. j$ ^
- Scale = scale;
/ Z/ e0 c* q5 k' Q0 M V! ` - }# y( b) R4 |4 k
- public String getLabel() {4 y8 S7 n( O5 ^* G7 s7 t0 K# C
- return Label;9 |2 ]' `/ C: ~3 Q
- }
% \1 G. t0 U* {6 p c: Y0 Y - public void setLabel(String label) {
0 S% \ M1 x% \: f3 \% Q% N1 @/ t: N- E - Label = label;
; ?% E; j) ~% w7 L/ a; X - }
' f9 T0 p1 W: ?; s& k. u% m9 W& U - public String getTitle() {, u2 N; n+ K$ y
- return Title;
9 [$ P, E. k5 S; A - }+ P7 q/ M5 N6 G" |! c
- public void setTitle(String title) {5 |+ l( p& g! P* ^8 Y# q& b' Q
- Title = title;
& B3 T' w% W0 Q. Y0 E - }; d2 R2 y R s
- public String getDescription() {
9 g0 `# R3 `# i - return Description;
3 C1 s1 {9 p# \- y8 v - }
: C: F2 C! ^8 n' s! Z - public void setDescription(String description) {) @; {0 C% v+ n( _2 P
- Description = description; n( J+ D, M$ x, l; ~
- }
: l: D: L" A6 D& |2 M, F# l7 c8 G - public String getUrl() {
+ b ^4 ?) m: q0 Z* A. W% i2 x - return Url;3 R2 \( o9 m# H
- }
2 n( X3 y) j$ o0 ?- c0 N s - public void setUrl(String url) {
( @+ H9 O5 P5 T* y: ^ - Url = url;
3 H# p' d6 t- k m. H9 t) s - }
3 \( I& T6 Q; n. [6 z2 F" F - public String getPicUrl() {2 B" T; e0 v' e, N
- return PicUrl;
6 ]% H, f- I6 `& B* [ - }
1 P1 C' t% j4 \ - public void setPicUrl(String picUrl) {3 i- y( e1 e% z; s$ d' @# |, A5 h
- PicUrl = picUrl;: M- N9 C) x0 k: I9 i. h# d
- }" w; K. y3 p# \
- public String getMediaId() {
, k# g5 E( ]* Q+ r8 h - return MediaId;5 l8 i$ @' D3 L) V. B/ p
- }$ }! i+ Y$ i W: |7 u
- public void setMediaId(String mediaId) {
' s. _. ?/ ?5 Q1 T; q7 ~ - MediaId = mediaId;
2 c9 l: j2 L5 ~4 }- R3 m& a - }
, U1 o3 s5 F$ u V- c3 F/ ?5 N2 Q - public String getEventKey() {3 A# [# J. ^7 e' G: g7 ?/ D* D/ p. h+ F
- return EventKey;
; Q, @8 G* z- A+ ~6 J' A8 r - }
$ d( W7 `$ F7 g c4 I - public void setEventKey(String eventKey) {
" Q3 Y+ x0 \$ z1 T - EventKey = eventKey;
; {' Z& }+ }) s8 X& u+ X$ i! d - }
$ K. S* V8 j$ ?# x- p }$ ~7 t - public String getTicket() {0 c+ ~( y& l( P8 v0 i$ i
- return Ticket;
) l1 i( Q9 @4 a$ U9 X - }
4 X9 j: w7 @2 Z; |4 C - public void setTicket(String ticket) {7 A, P/ t7 w+ J. L( h0 d8 a
- Ticket = ticket;6 X# w) a. o$ E
- }
5 v" p7 \; X8 K) J& Q: y7 E - public String getLatitude() {
; J! }4 f$ `* c$ V! F( b - return Latitude;/ u# r e" m' W: u' {1 q4 b. B/ T
- }
7 r1 |3 e5 i" p - public void setLatitude(String latitude) {
$ O1 X1 w# h. o( ^& p - Latitude = latitude;
3 H5 b1 W* I/ `* Q- G - }
8 Y U6 u/ _4 p/ w9 ? - public String getLongitude() {( L0 ^/ I; T/ ] n
- return Longitude;
" G, n( B: | h& a4 [! e3 y; p - }# v0 S& R4 u' R8 g( m7 _' R: f
- public void setLongitude(String longitude) {
% \7 ^8 z% h" |" Z - Longitude = longitude;0 R. b, o0 a b
- }
. X$ T7 @7 |& j# ~7 n1 ]/ | - public String getPrecision() {
) [( u9 ?! S3 T8 Y- s0 @ - return Precision;( J* T! S) }9 B
- }1 q e0 f9 v4 k5 H5 D6 y. B5 A
- public void setPrecision(String precision) {, {* P4 Y; a- ?% Z
- Precision = precision;* ] Q6 S( H8 G$ f* ~6 ?0 Z
- }
4 h2 S2 ?# z: q; \7 W4 r - public String getEvent() {- q$ H# B X! k4 n, x6 c- k' j2 v* j- _
- return Event;
& k4 J% V7 l) v0 k - }6 E2 g! e1 r) |5 b
- public void setEvent(String event) {/ Z( R j0 G p' j
- Event = event;
3 c0 _! r: W' u - }4 C- u J3 T) u
- public String getMsgId() {! B5 a0 _' d, O7 ^8 N: ~+ n
- return MsgId;2 j4 p) ~3 Q. I3 `8 U( I1 \
- }- X0 k9 E. ]+ x0 p8 y
- public void setMsgId(String msgId) {
/ S; _4 g0 {2 ~- t6 S - MsgId = msgId;$ }5 o5 s4 G6 @) G" [: r
- }
* C4 Y; s" \3 z - public String getToUserName() {4 G0 h3 Q5 n& u6 L! |& y0 m5 J* m
- return ToUserName;: ~+ ]! J: e+ I; D0 Y: Q
- } s& W6 Y5 B+ H5 v0 ~0 R
- public void setToUserName(String toUserName) {
3 A( E" g7 _, q/ E/ ?# i# Y - ToUserName = toUserName;0 }3 m. v5 l# \1 t7 ~8 R8 O
- }2 v: V3 F8 i6 U; I2 K# i* s7 G
- public String getFromUserName() {
7 Z1 C$ `! A3 V6 D - return FromUserName;
: x/ j7 N$ @( u: |5 p2 f$ S& X - }- ~* {) r2 y% w& v: o( o- [. ^
- public void setFromUserName(String fromUserName) {' o8 m+ t) x) r3 o- p/ f' I
- FromUserName = fromUserName;/ g* y3 M2 q& N8 z3 P5 N% y% W! ~
- }; l3 x) C8 O. `' o+ U) p+ t1 j
- public String getCreateTime() {: M# m; c9 h7 B2 P7 U3 J, E
- return CreateTime;! ~2 Q8 v8 @$ p/ s! U4 |2 x- j A
- }& \1 S. B- s! _7 A& |
- public void setCreateTime(String createTime) {
% Y2 n" c0 L/ G - CreateTime = createTime;
. O3 p# A' p2 Q+ } - }9 W& B# Q0 e! L7 Q( Z
- public String getMsgType() {
+ T6 \; g# a" V/ B( E - return MsgType;
0 d5 J& h$ k" R) T# O/ e" G - }, V$ P6 ~! W7 r8 p% C
- public void setMsgType(String msgType) {; | y+ H2 d' D; E8 {% n
- MsgType = msgType;
+ N, n7 E, [9 V; d. v6 T6 z - }
( k& p4 N/ e- Y8 G$ g- @0 j - }4 f- o& j# n# j0 u" {
复制代码 调用图灵机器人api接口,获取智能回复内容 TulingApiProcess.java
: s; y" [5 d( \! X0 f
# _& S) J! d6 Y3 s) F" n- package demo.process;+ ~; K: ]/ ]3 q; a. \( y# s7 M) W0 K
* \7 g0 d7 ] c1 F. D7 y I9 \. U6 _' w- import java.io.IOException;8 I' J4 q7 {" Q' D
- import java.io.UnsupportedEncodingException;0 ]/ T2 v( |2 _
- import java.net.URLEncoder;
6 [) t$ B% V, U
- K3 A! O0 Z# c- O3 G% o" q8 w- import org.apache.http.HttpResponse;0 M9 U: ~+ J# a0 V0 p% h! p3 h# d
- import org.apache.http.client.ClientProtocolException;6 v1 c) S# O3 L7 H3 F5 c) z
- import org.apache.http.client.methods.HttpGet;# D8 \, b9 u0 y
- import org.apache.http.impl.client.HttpClients;
9 E D- V/ `1 K$ Q; m- h) l3 B9 y - import org.apache.http.util.EntityUtils;! _9 L, \6 A1 k3 Z
- import org.json.JSONException;: L! Q @: G: m* A
- import org.json.JSONObject;0 H! Z. k1 y8 b
) Y' f3 p( B5 h6 I* w- /**
+ t9 N- |+ q/ ?& i, d - * 调用图灵机器人api接口,获取智能回复内容5 O6 E8 D/ q; t7 s% G6 L# |, [
- * @author 科帮网6 |2 j# d& Y4 G: `3 y, W
- *
W: B( ?# _6 Z: G+ ^4 Z - */
( I/ A0 q4 h8 y8 e, w - public class TulingApiProcess {
9 H& k" T' N* b2 n1 }! d R - /**
9 [5 r+ e. m; x4 r2 O* d - * 调用图灵机器人api接口,获取智能回复内容,解析获取自己所需结果
* d4 {5 a1 n+ j - * @param content
) `( O4 v7 n8 W, S- f/ [& I+ X% ] - * @return: L) H6 ? }2 F5 v7 @. A
- */, x7 b" a+ D3 P+ {0 q# |0 e( g! J0 w
- public String getTulingResult(String content){
. h6 J3 m+ \" ?- I! S - /** 此处为图灵api接口,参数key需要自己去注册申请 */$ _: r/ M4 F: `* m# W% J- A
- String apiUrl = "http://www.tuling123.com/openapi/api?key=2a31b2f601f74b54ea13db1c82fe5d71&info=";
! A5 Q0 j. b; H - String param = "";, o) [& W0 ~6 m3 g9 ]- h
- try {+ o# ]# {2 o/ Y
- param = apiUrl+URLEncoder.encode(content,"utf-8"); W- C7 ` x( G8 Q/ l, I
- } catch (UnsupportedEncodingException e1) { c+ ~/ B' T) I
- e1.printStackTrace();
* C1 x9 B" x3 O" v0 \1 F - } //将参数转为url编码; ~6 W$ T' P* |3 z+ C& P7 j/ k
- /** 发送httpget请求 */
. a$ V$ d* |1 G( y/ O7 N6 ` - HttpGet request = new HttpGet(param);
" F5 L$ [: s2 R: N; s - String result = "";
! J& E; v; v/ s( F - try {/ Q* B- Z$ q7 q& h' S0 {" {5 L7 @. b, Z
- HttpResponse response = HttpClients.createDefault().execute(request);
3 z' U$ b0 k" ~: {8 V7 X - if(response.getStatusLine().getStatusCode()==200){9 U) W7 [* I% w. A
- result = EntityUtils.toString(response.getEntity());
' s$ g$ l. o( _: z- M9 } - }
3 Z% \: O' p6 J% E - } catch (ClientProtocolException e) {
; l1 I. e3 G+ P - e.printStackTrace();
$ `! {" C& N: d: ]9 j. r - } catch (IOException e) {( k4 x( @* X/ }( f( a! b
- e.printStackTrace();. O, N6 ~, b* m" H3 K
- }
2 n. h6 A9 x9 }( w/ T ~* I" ]% A - /** 请求失败处理 */
' w6 k, C- ~2 M/ r - if(null==result){) V5 W: c, }9 A& I: Y3 g. c
- return "对不起,你说的话真是太高深了……";
: E) e y! c! g - }
7 Q" S8 }3 O4 X; x& k -
( {8 l1 A# b( F - try {
* v3 l0 g9 H9 |6 I - JSONObject json = new JSONObject(result);
- ?( L% L. p' U: L - //以code=100000为例,参考图灵机器人api文档! o8 z) e" y* O$ S9 G+ i D* q/ g
- if(100000==json.getInt("code")){& J9 y. q! ?" w% S% H
- result = json.getString("text");& m+ h. @( Z2 R$ w5 r2 B* H
- }1 O! P- a/ B3 ?4 r
- } catch (JSONException e) {: y* C6 ~! d. d1 ]+ }' S
- e.printStackTrace();
/ v7 F. R/ w3 Q, j; y- n' M. ] - }. i9 _5 P! i5 E* y7 K4 x l$ K
- return result;3 z1 Y4 I+ X# Z
- }! P, k+ [3 h; k5 l! d6 `
- }4 e9 h& J1 f' ? \7 J2 @7 e( R
复制代码 1 x- T# ^3 j; H9 E, s5 S8 X
web.xml 配置:' J% j) E/ G$ w1 y/ E% \
- <?xml version="1.0" encoding="UTF-8"?>- a6 D4 I( E* u
- <web-app version="2.5" 0 z' _% i) P5 [% }% ]! {4 t1 ~
- xmlns="http://java.sun.com/xml/ns/javaee"
+ E- ]0 u- d8 t7 T' g - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
% p& e5 q* V& J7 I& g' I( M% j - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
8 a' B& L1 T- M! k4 _; B* I0 ~ - http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> t: m! V! i' t: h6 }
- <servlet>
2 a1 ~5 [7 B4 X+ F - <servlet-name>WechatServlet</servlet-name>
3 [- _! H& \+ `/ ]+ }: l - <servlet-class>demo.servlet.WechatServlet</servlet-class>
4 R: [- I6 `$ l1 P% [ - </servlet>
0 W' X4 h- ~# i: }3 s7 @
* w. o$ F+ a; x- <servlet-mapping>, i8 e* ?3 Q& w& x3 Q2 q( B: U
- <servlet-name>WechatServlet</servlet-name>
, l- P; i L9 _2 N/ C - <url-pattern>/wechat.do</url-pattern>
; f7 Q5 U- F1 m4 R - </servlet-mapping>
: c7 g4 ] {2 e* n# F - <welcome-file-list>
4 k5 M: x$ {/ V) X/ I, _ - <welcome-file>index.jsp</welcome-file>
5 l4 d1 d" V5 t9 ] - </welcome-file-list>
1 R) D+ g% e4 D4 ` w9 h - </web-app>" t! l- u' a _% X
复制代码
! m2 }- `2 n1 X* u/ I3 d0 @- M& S% p项目源码下载地址:, Z2 w, b2 O7 A
4 M/ m6 \. a) z/ y- g' H9 J# }2 a- K' N- i- q1 q3 u' |
|
|