TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
java实现微信公众平台开发项目源码
- ~( F* e0 f- F' z本文向大家介绍使用Java来实现微信公共平台功能,实现根据回复的内容返回对应的消息。供大家学习使用。8 Y/ b* J7 M* D: V6 _6 n
微信服务端收发消息接口:WechatServlet.java b/ u1 n4 |9 [/ W* s$ Q
- package demo.servlet;
! s" Z+ y) j' U" J$ p - ' [( M: f, f! E7 c, U6 R$ }9 d/ B" g
- import java.io.BufferedReader;+ F" p6 U, [7 X( r1 N! h
- import java.io.IOException;: I2 v0 ]1 f5 m& w7 ?4 x- J- \
- import java.io.InputStream;
2 _' N( R* t, Y - import java.io.InputStreamReader;
2 X) m4 }! @% p% ~; R% M' i - import java.util.Arrays;7 I+ Q& _- G. C' E6 u
- + m" s: q9 H$ o+ H. K, P
- import javax.servlet.ServletException;
9 v, {+ M! ^2 z! l- K - import javax.servlet.http.HttpServlet;/ X1 d5 ]+ n3 G8 E) t
- import javax.servlet.http.HttpServletRequest; P7 r8 H- g5 ^4 A
- import javax.servlet.http.HttpServletResponse;
* c# n, r ?- O8 |/ P
+ U, Q5 j( p9 s- P- import demo.process.WechatProcess;' a) `, v1 ?7 C' O! ]6 |3 T# n
- import demo.util.SHA1;2 C' N/ Z. E2 Z6 J. W- p; A' D
- /**" e, |- P7 i: ]$ s# ?
- * 微信服务端收发消息接口
$ y8 G; n) |. f - *
% m. @3 G. B6 }- P6 ~9 |0 ~ - * @author 科帮网
/ R% n" L- z* u9 F* Y+ H4 Q - *
+ ?4 l* E$ L. I$ p - */6 o+ p. d( F$ [7 v* j
- @SuppressWarnings("serial")4 F6 x) L3 q9 ?0 c+ o# j
- public class WechatServlet extends HttpServlet {. @( L, ?" T$ R$ b' D
- $ O( K% |# _- y! T
- // 自定义 token
1 I( u9 E4 s0 w - private String TOKEN = "52itstyle"; . M' \% l! l/ L" d- ~ c
- public void doGet(HttpServletRequest request, HttpServletResponse response)8 @6 K: B9 t1 ^) X( ~ l( V/ |
- throws ServletException, IOException {; o/ ]+ @8 n! d5 {$ E+ u8 `
- String signature = request.getParameter("signature"); // 随机字符串/ S3 Y- H/ H" |# v/ P
- String echostr = request.getParameter("echostr"); // 时间戳
4 b3 ~$ ^) _, Y4 w - String timestamp = request.getParameter("timestamp"); // 随机数 {2 i' k6 B5 P/ E" L
- String nonce = request.getParameter("nonce");; D: G# m: B |) T) y
-
1 {, j% d1 n$ r2 {3 b: J; x. E2 F" k9 p - String[] str = { TOKEN, timestamp, nonce };
! f8 C/ b. }" H) b4 { - Arrays.sort(str); // 字典序排序
9 S7 ^2 u o1 l% [5 a% K - String bigStr = str[0] + str[1] + str[2]; // SHA1加密! P% q5 p- f% z
- String digest = new SHA1().getDigestOfString(bigStr.getBytes()).toLowerCase();
/ N3 g* C1 E" p: U - // 确认请求来至微信! c5 n. O' U- _. L9 S% H
- if (digest.equals(signature)) {
$ E: A# D0 ?7 q- t7 J2 P1 j/ l - request.setCharacterEncoding("UTF-8");
/ }$ F2 t- m8 F$ [2 u9 M3 `( f - response.setCharacterEncoding("UTF-8");3 k; l! N* R( M l3 }
-
$ y A9 e& ]0 _3 F6 t0 c* b - /** 读取接收到的xml消息 */
( d# O, r& L5 V+ P* N9 b. \ - StringBuffer sb = new StringBuffer();
2 n. U8 t6 A4 N6 }1 R. E. P( i - InputStream is = request.getInputStream();
6 P9 _: c8 h4 N8 n v& \: J+ ]7 P - InputStreamReader isr = new InputStreamReader(is, "UTF-8");; C7 U$ d! e2 g3 ^/ y4 |4 |" ^
- BufferedReader br = new BufferedReader(isr);0 f$ h n$ X9 L& ?( y
- String s = "";
# E4 Z! d) r# q* y) x! I) n8 X, b - while ((s = br.readLine()) != null) {" C7 V/ r9 z! B& [8 w L
- sb.append(s);
! f# O8 k; f2 D3 q o2 d - }
# @& g9 G* s+ H/ r3 i - String xml = sb.toString(); //次即为接收到微信端发送过来的xml数据- W: N- X/ S+ W2 ]8 D8 H# b6 U
- 0 t5 |# ^: Q+ O% ^+ K- T' O q2 z
- String result = "";( K: o/ }8 M/ B, g& D$ I
- /** 判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回 */
; ?2 G9 \" Q5 V) L- |; O - if (echostr != null && echostr.length() > 1) {; r; S! Y/ }2 |) r& w( U
- result = echostr;
: U$ v @' I' \* i. I$ P8 S - } else {
' G! P9 b+ T6 [; y) C# K - //正常的微信处理流程* _; T4 h2 x8 K& P# W
- result = new WechatProcess().processWechatMag(xml);0 F4 \) E/ l8 g5 h# V
- }# r* M6 N% Z" H
- System.out.println("说的什么"+result);" j4 c; {+ \4 ]2 `+ f
- response.getWriter().print(result);
, o" t* e; {2 [# Y: e$ P - }. k4 G; w$ B' A, L* w
- }( [ Y6 r& q' B
- ) v8 L4 a/ z" [6 S% g K
- /**
. P# ^# {/ [, i4 T6 q9 N* N4 I - * The doPost method of the servlet. <br>
" g. U4 A' v9 T4 j" p$ L* D8 H - * * J$ z* E9 W" X. I% Q
- * This method is called when a form has its tag value method equals to6 {& p% R3 P4 L4 B
- * post.; S# Q) s$ d0 \9 P$ L, X8 D
- * $ G1 n0 P9 N% |
- * @param request
! s1 \# |9 z* B/ \9 j - * the request send by the client to the server
3 k' ?' X0 c2 Z z - * @param response
$ M& ?5 ^; S( z0 [+ m" H) b - * the response send by the server to the client
4 M1 R. u/ v1 w/ H. Q3 ] - * @throws ServletException& ~7 a7 q) T: z+ v: W" s M
- * if an error occurred
& W) V, v! { f& r$ R8 O6 O - * @throws IOException
Q! ~7 Q# ]0 e- x: n* Y! ~ - * if an error occurred
4 o7 j7 }5 p7 S* q5 `9 {* { - */" x# k+ D9 W% o I
- public void doPost(HttpServletRequest request, HttpServletResponse response)1 h7 R J) D1 y+ K- m6 t& ]3 `; ^
- throws ServletException, IOException {
7 ~, v3 n7 e) Z - doGet(request, response);
- E, b4 `! N" r+ ] - }
$ \( d' [6 z2 C0 l. h - 8 H/ d, W( G& m7 `0 c) l
- }( B+ |, S# d0 M0 f3 c
复制代码 接收到的微信xml实体类:ReceiveXmlEntity.java/ i5 Z$ m& b- x8 ]( g+ v5 p/ s9 E4 c/ i
- package demo.entity;
9 P- U4 G( O$ c6 \# ^; c - /**! ^$ @- ]2 P' X& z2 \2 ~6 b" P" \
- * 接收到的微信xml实体类
5 m4 E' `; i% _ - * @author 科帮网
# _8 a8 v/ z5 u4 Q- p; G$ G - *
& X' |; T1 }4 S( C - */% ], [. i/ e2 [% B, A. { ~/ K. G
- public class ReceiveXmlEntity {& P V. c/ C' |+ _$ P4 H: c8 u
- private String ToUserName="";
8 ~& p' D( S! t+ N6 m - private String FromUserName="";3 L8 Y# K ]6 v* {
- private String CreateTime="";3 E. v5 ~6 x$ I2 V
- private String MsgType="";( r. y' [" {9 k* J1 B% D. V
- private String MsgId="";: O/ a2 u, Y, q; A& g
- private String Event="";
7 m: d0 w5 a4 [( ~# h - private String EventKey="";
* s* j& O) P3 {7 q5 Y+ L - private String Ticket="";8 ]* r4 i$ y2 v* h* w7 p+ o
- private String Latitude="";
$ z: o3 s/ j7 G& u3 \ - private String Longitude="";
1 L0 x" z/ U( B* f; l - private String Precision="";
" [- J) H& Z% T. {8 I - private String PicUrl="";/ e9 b) _4 H3 o# {
- private String MediaId="";
& d) I% h4 J7 ^0 k - private String Title="";3 {( C5 H: \0 P2 w6 F
- private String Description="";
3 x8 R& k. H* b; [8 g: A" ^ - private String Url="";
4 L9 F, f: N, p2 Q% R% I - private String Location_X="";
' T& `/ n( m2 I" D2 z, P3 X - private String Location_Y="";& a0 b# Z! Z1 B4 {. X- z/ Z5 e
- private String Scale="";
/ M) l3 u; n1 t9 L) A$ l& Q - private String Label="";5 w1 Q }2 \! M! m* I
- private String Content="";
O3 N, c% y* q& i! g - private String Format="";" C1 _* [; M4 H" ~# g% p/ z
- private String Recognition="";0 S1 j. m9 e- J0 M
-
9 w/ d( t, _' X# S - public String getRecognition() {
: ]! d: \, i5 {, W) x" y - return Recognition;) l8 n" \; ` H- v" l/ ~7 T
- }
/ y# b8 P" y9 [% p- v! c - public void setRecognition(String recognition) {
6 j4 r: j) v3 }& W% T - Recognition = recognition;# ^, P, i) B3 ^$ _7 U
- }5 U% Z% s5 U7 Z9 v7 ]. W+ T2 X
- public String getFormat() {
% a/ S/ n: d# y/ n& B - return Format;- H& w6 x- r. {
- }+ W, N/ `# }6 ^
- public void setFormat(String format) {
! E4 k* T8 a/ I/ K& } - Format = format;' I& y8 Z+ w7 o# K* \ j( l
- }2 V. L2 z H8 V0 T2 D i" p
- public String getContent() {
% C, @# i2 F: d% k/ k! R - return Content;
5 L! \# v9 ^/ ~! c8 W$ l% G8 E - }( Z+ p, f9 e3 u) J6 X( k2 w
- public void setContent(String content) {
- U4 {6 i* c+ \9 G, ^& h% a2 ]* a - Content = content;8 @5 X7 Y' \3 f! e, ?( e7 X
- }1 q2 D% v) ^6 R( N8 w; _, f* E
- public String getLocation_X() {# P3 I' Q7 o. ?; D4 ?) _8 I
- return Location_X;7 |8 v: a1 B# k$ A
- }4 V6 y% M8 t* b- T) P+ f- T
- public void setLocation_X(String locationX) {
4 Y/ o9 P! {+ \% g# s8 { - Location_X = locationX;, J5 @0 ?9 N9 E
- }
$ X5 r! L# a! c1 s* {% o6 J( K6 [ - public String getLocation_Y() {* ?0 O1 w2 J/ r# S# C& g! d
- return Location_Y;
8 ? N( q1 ?" l5 t' V# V3 N - }
8 z4 w9 }7 J; ]& U( z& h - public void setLocation_Y(String locationY) {' b- ?; K- _& C4 Y0 L8 N) F+ A
- Location_Y = locationY;
1 y/ P0 T7 l5 {/ w - }
|4 }7 n) _# s - public String getScale() {
4 V q# h# U; t2 a' b - return Scale;0 i' }% Y2 e [! L
- }
8 c1 {. d( F6 ` j - public void setScale(String scale) {
4 q$ I+ K) S0 G( b7 C8 F( @ - Scale = scale;, L4 A+ v% O6 B9 C, \
- }
3 j! ?2 ]9 M! W( e - public String getLabel() {
* Z% R6 Q$ A4 B4 k3 {3 T - return Label;
/ y- y) @& \5 }/ l& T8 x1 u - }. y0 `5 V7 _7 r3 Y D: t
- public void setLabel(String label) {! l* h L6 c4 C7 Y6 |' B4 U3 r
- Label = label;
7 a0 t4 S/ j* o8 O5 ~$ r" M - }
* J, S, J( O, ^+ p+ w' q - public String getTitle() {
* C+ i1 O( l& w( c* A. ? - return Title;& \1 o V$ Y* L0 }2 a6 {" n9 n& f
- }
8 `: @' |7 w5 z, M8 w, ?# H9 k - public void setTitle(String title) {6 w% ~% N0 A; t; R; k7 h0 ]
- Title = title;$ S. M1 j" Q9 ]/ o
- }
6 H1 j ?4 I6 w' W: X$ M4 r - public String getDescription() {" o) c2 @9 k3 L7 g- T. G
- return Description;1 O" \, L9 L J9 R5 |7 _' L
- }
8 ]* k- A/ e, X. n. o - public void setDescription(String description) {' j' L/ M* `8 f" |+ B$ Z, f
- Description = description;
* I L, e+ x/ i/ d* J - }/ M7 v+ `5 k! l* M1 q5 \6 l( Y d
- public String getUrl() {9 W9 U; r3 k: B# Z( s* Q/ D/ E
- return Url;
7 J: a4 Q8 x) j) s' [ - }8 x) Q' I3 R! D8 h1 }" e8 }7 o
- public void setUrl(String url) {
: `' G0 b9 E% V1 c& `% b) \ - Url = url;
' S4 z" h1 W' V6 f4 \) r& k - }; b$ g5 C& l0 w7 o5 h
- public String getPicUrl() {: @. ?) ^# ?( G$ w" o/ Q
- return PicUrl;
6 u J; d' v, V, b8 ~& z# q% b. j - }
8 G3 l; B7 U: A; q w) ] - public void setPicUrl(String picUrl) {
2 ^7 P0 E' j% e2 n, F @ - PicUrl = picUrl;8 ]/ P, J2 ^( K2 l1 g1 H
- }
, p' \2 H( {* g( X2 Z7 I( N3 n - public String getMediaId() {: y7 \1 ]1 x' D0 ^; {" _6 l
- return MediaId;
" |( _# m( P- ]5 X+ W - }% m9 H8 h8 w' O2 ^
- public void setMediaId(String mediaId) {0 v6 H+ |+ q9 X- i+ ?
- MediaId = mediaId;
) r1 H6 ]4 \7 Y3 j4 U/ n - }
7 a) K. _ `1 C1 e& Y - public String getEventKey() {1 B$ @! W. j. w) [ w. k- d
- return EventKey;
$ Z; X; r9 J. k) x - }
. m$ _1 b0 I. v0 M* M8 `4 K - public void setEventKey(String eventKey) {, v6 T* n# C7 F" k, ]
- EventKey = eventKey;
1 y. a. }3 r: [% { - }5 Q. c7 F# R1 Q# z( U9 w
- public String getTicket() {
6 B0 @& s& |2 {7 i4 m - return Ticket;
# ^& q1 Z, x+ z- `3 }! v7 O - }1 a0 @3 l4 [4 q, Q) T. V; T% ^/ L: X
- public void setTicket(String ticket) {
. o: u* j+ H/ L; P% ~, P - Ticket = ticket;
' h, h: ?( y. d* r# V! A) } - }# j w( X4 D7 _: O4 x% h) }" W& W- k
- public String getLatitude() {% G4 V2 x k; ]' q4 N- b1 q
- return Latitude;
1 Q3 R" c! e1 f) ~9 u; C - }
/ y. h7 X6 P) J9 h. c* s$ \! g1 i6 F - public void setLatitude(String latitude) {
( m) ^! U3 ^+ Z - Latitude = latitude;
" g' v2 z( J, L. l - } a7 q8 @7 P" p, A$ h5 L% u
- public String getLongitude() {
: p$ V9 w9 s: I: M - return Longitude;
5 r+ o) ?4 I+ i - }8 v0 Z" o' @" ~+ a. b- ?
- public void setLongitude(String longitude) {
A& c: Z* M% v0 } }6 j) @, L7 j - Longitude = longitude;' @' J5 B, Z% d6 N; f
- }
9 ]* ]* ^$ T6 a( } - public String getPrecision() {6 u' U: H/ ?# W4 H* U
- return Precision; a& u" |' I9 J* ^0 S
- }; z- j; D$ G, I8 V. ?* o
- public void setPrecision(String precision) {
$ X# W4 X! I5 a - Precision = precision;
6 `8 ^) g% x& A4 n/ O; K9 t% D- t' U! Y - }
7 P/ R: _% U# Z8 N# J - public String getEvent() {
7 {; X7 C- t0 R' a - return Event;
w% p- `. Y6 {3 t; R! r - } x8 T+ N1 `' s- }4 b4 E- q
- public void setEvent(String event) {
8 [6 c3 J; [/ n3 S - Event = event;2 X' m0 d: m# A- D4 C! k
- }8 F; `( H% N3 x1 M4 g9 S5 f
- public String getMsgId() {
; H& S& l6 r/ {4 y - return MsgId;8 H; O7 \2 Y+ X9 z) T4 b
- }* B4 V& ^/ e5 {. W3 F" M4 c
- public void setMsgId(String msgId) {
/ X) `, I8 a8 o3 h5 R) f2 Z - MsgId = msgId;9 c1 b# J1 b6 Y" H; e
- }: G' U7 p1 O3 G
- public String getToUserName() {
# l/ ^4 n# }. X - return ToUserName;
% d$ r' C0 `5 v+ L$ v. x! y" Q - }7 z, Q0 j# |' m5 {1 w) K
- public void setToUserName(String toUserName) {
* `* k3 ]! X5 N' u$ }, n$ \ - ToUserName = toUserName;3 ]' l" T+ H& K' H
- }
$ b+ k- Z9 q* \8 { - public String getFromUserName() {
1 s1 w b$ i5 U5 y( s - return FromUserName;; |1 i( F' a: @
- }: b$ A8 K% g. Z9 @+ S- M1 F" ]
- public void setFromUserName(String fromUserName) {6 C* R2 o2 S% h j# c3 i+ P- Q
- FromUserName = fromUserName;: h- l/ A; Q6 U% o* j, J3 O+ e
- }
, m! o, j7 b& x" U/ g - public String getCreateTime() {
( H* a/ \. V$ ?7 p - return CreateTime;
2 q6 C1 q+ t) s1 T/ p8 D% b - }- S# l, ?* V: L1 M0 A5 _
- public void setCreateTime(String createTime) {/ q4 w( G& | J# W
- CreateTime = createTime;$ {8 L' a" E4 [' e! [0 y L8 n
- }9 m \/ Q, H* A# `; w4 N3 I
- public String getMsgType() {
& Y" R* P! }6 h. L - return MsgType;& n" {9 f* [4 S; v
- }; u- p9 F5 v- r6 p
- public void setMsgType(String msgType) {
& F4 k5 e# L) n9 l+ N - MsgType = msgType;0 p8 b% d' X! G" G6 m2 k8 f$ e0 b `
- }3 B) w, G. C+ n) z
- }4 P, ~) M3 N8 l
复制代码 调用图灵机器人api接口,获取智能回复内容 TulingApiProcess.java
+ X* D5 b: e8 E$ E. ~
9 G& v+ I) o4 a- package demo.process;2 C( x" E) C% g( B
; O* [' i/ C! d7 |4 h4 n+ i/ q& Z# [, A- import java.io.IOException;4 X8 T* M" { }; q3 w8 q. b4 p8 R6 m
- import java.io.UnsupportedEncodingException;
, ~1 I8 X4 O3 W3 \! w/ k - import java.net.URLEncoder;
0 D3 ]2 V; C$ t
. e/ ^% S5 k! z! o' O0 p* s3 X- import org.apache.http.HttpResponse;: c ?: a. ^- w4 B
- import org.apache.http.client.ClientProtocolException;
/ b# @$ d {$ w7 g - import org.apache.http.client.methods.HttpGet;
$ U( n3 m7 v/ F% d - import org.apache.http.impl.client.HttpClients;
; t, Q- U. l% D, {' U$ @5 V3 n) K - import org.apache.http.util.EntityUtils;5 w: c& ?- b- i# g4 K
- import org.json.JSONException;! `8 L) k2 D) n+ M; h
- import org.json.JSONObject;
8 L3 g. n$ M/ z1 Y! h: d% X
' b2 s3 f: I: M' A, p/ F: C% \- /**4 F! Q8 |" N! a, W+ V1 p$ a* F' }
- * 调用图灵机器人api接口,获取智能回复内容0 i. o7 V2 T/ v0 B8 {; G) X' t
- * @author 科帮网/ ]* Y0 r1 I! p2 }, W
- *
2 b, ]$ F1 S- H - */
$ ?* ~6 n, Y7 w J; F - public class TulingApiProcess {
. d1 p# c+ |; J9 g, O - /**
. A! c7 V6 w( R. J k - * 调用图灵机器人api接口,获取智能回复内容,解析获取自己所需结果$ H9 |8 m5 W( |9 v" t" f/ H% S
- * @param content' C; O9 B6 ]8 g
- * @return) h/ g! M2 |1 o" Z( ^5 C' E
- */
s4 W f/ ^: W - public String getTulingResult(String content){
" d" R8 [ f9 O6 P; p& }0 c' s; n! x7 l - /** 此处为图灵api接口,参数key需要自己去注册申请 */
( l: {8 J" S, M2 g - String apiUrl = "http://www.tuling123.com/openapi/api?key=2a31b2f601f74b54ea13db1c82fe5d71&info=";
( f6 j/ a" r+ n: E - String param = "";
! F H$ m6 `( o9 V - try {+ r$ I7 z; K& @3 L
- param = apiUrl+URLEncoder.encode(content,"utf-8");
6 T4 I2 n. T2 Y5 d$ k - } catch (UnsupportedEncodingException e1) {
8 N* U2 @: a1 v2 B) \ - e1.printStackTrace();; f% t9 f) x. V
- } //将参数转为url编码 h9 H9 e# J: F' q T" P
- /** 发送httpget请求 */- _( v; S/ |5 `; M7 A; M0 Q/ S( ]
- HttpGet request = new HttpGet(param);
$ l: a% F$ K7 a4 |/ s - String result = "";
# a6 ?0 \1 H; E, S2 g - try {; T' r. O! s- n
- HttpResponse response = HttpClients.createDefault().execute(request);/ E, n0 Y, Q: L* @" m' }
- if(response.getStatusLine().getStatusCode()==200){
) G$ F! P2 L1 K - result = EntityUtils.toString(response.getEntity());5 E! {9 _" o+ z* V! l$ [
- }2 m( Y6 B8 }5 {, i% ^ F
- } catch (ClientProtocolException e) {# K. P9 h. A3 H
- e.printStackTrace();
) {( `; Y# p( r; c - } catch (IOException e) {7 @' v% K1 w- r6 h
- e.printStackTrace();3 W- x/ a" D; A, `4 c! I
- }
9 i: r; i% x0 j$ Q- { - /** 请求失败处理 */0 D/ Q7 V" U9 N6 g% A: g5 A
- if(null==result){' v5 ~/ s4 {4 M$ X$ p
- return "对不起,你说的话真是太高深了……";
! T) L, S# z3 s - }
' P/ A0 K0 ]; M$ S9 r -
, ?) P) p* F7 U0 } - try {" N/ B: y- L( B- z! u
- JSONObject json = new JSONObject(result);4 G9 \- I8 a, h. v: P9 d6 ]
- //以code=100000为例,参考图灵机器人api文档: v$ G0 W! C% m+ Q
- if(100000==json.getInt("code")){
/ N5 \) x1 P5 G. k/ Y - result = json.getString("text");
: r% j: T3 k0 ` - }
; P9 }" m; M/ h - } catch (JSONException e) {
3 n8 M; R1 ]" r0 q# [, y; W - e.printStackTrace();
w) {3 N! W b: F& C - }6 z l) ?' [ D. L/ q5 p6 L5 ?; r
- return result;! U T! M& Q F5 P$ _6 H) K
- }
) y# j3 M$ B0 D; f! u - }
. [, [$ }8 W2 h. _7 s" [' C
复制代码
0 d) t/ A+ d: H% v3 q8 V; u: Q7 i: oweb.xml 配置:
4 R( x$ m; E; y% D: x, c- <?xml version="1.0" encoding="UTF-8"?>+ ~4 X- b4 r- y2 t$ X3 y# H/ [
- <web-app version="2.5" ! z+ Z4 B- B4 y2 |
- xmlns="http://java.sun.com/xml/ns/javaee"
8 Q9 Y7 s+ ?' F) N - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9 L7 D& V. h; S" \% r - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5 j; _% z& U1 o# J- k- V' z. c - http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
1 Z9 E; X4 V& E, W9 g4 d - <servlet>0 L; B% V8 X5 ~
- <servlet-name>WechatServlet</servlet-name>
: g+ d- k. m2 n a7 k( C% D: R - <servlet-class>demo.servlet.WechatServlet</servlet-class>2 L8 {$ q2 y$ W' u
- </servlet>9 \# f) {$ n6 C5 M& h& N; y* [
- & H6 F! G6 o' e. Z7 ^% |- k p
- <servlet-mapping>
7 r1 q9 E8 W( T* c2 U2 J" m# x - <servlet-name>WechatServlet</servlet-name>6 S3 h$ f7 K# [* w& @ h+ f" ?: ~
- <url-pattern>/wechat.do</url-pattern>8 h6 d2 ?$ s" F, D1 f: G
- </servlet-mapping>: N; a! O' U9 Q9 d! F# ]
- <welcome-file-list>
+ W7 Z6 G, i! a; x% h1 p& n" @$ G - <welcome-file>index.jsp</welcome-file>
8 U' e2 F! g7 c6 a - </welcome-file-list>
2 g {5 r1 _( k! [( Q& }$ v - </web-app>
2 q, f" H" H1 U$ `- J7 e5 g i# P
复制代码
. j3 ^, Q8 r9 [# H3 g+ |项目源码下载地址:
' P& \, p, ~, o2 h$ U$ y
) ?& t$ E5 ]5 h, s* p1 F; z7 ^
; i% Q! I$ f, c" `; J0 x7 r |
|