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