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