生活随笔
收集整理的這篇文章主要介紹了
jeewx-api.jar入门教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jeewx-api.jar入門教程
附件:?
http://download.csdn.net/detail/zxl78585/8549027?
1、到微信官網申請測試帳號?
申請地址:http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index?
點擊登錄后,用自己的微信掃描
2、在Eclipse中配置Tomcat?
在window->preferences->server->runtime environments?
2、打開Eclipse,創建一個web項目?
我的eclipse默認的jdk是1.5的,這里,我們需要將jdk修改成1.7的。:在項目上點擊右鍵,選擇build path,選中configure build path,將libraries中的jdk1.5選中,點擊edit,修改成1.7的。?
3、導入jar包?
jeecg-api包依賴其他九個包,一塊兒導入?
選中這些包,點擊右鍵,build path ,點擊add to build path,這樣,所有的jar都被添加到項目中去了?
4、創建表單頁面?
在WebContent目錄中創建一個index.jsp頁面
Html代碼??
<body>??<form?action="ApiDemo"?method="post">?????????<table>??????????????????<tr>??????????????????????????<td>appId</td>??????????????????????????<td><input?type="text"?id="appId"?name="appId"?/></td>??????????????????</tr>?????????????????<tr>??????????????????????????<td>appSecret</td>?????????????????????????<td><input?type="text"?id="appSecret"?name="appSecret"?/></td>?????????????????</tr>?????????????????<tr>?????????????????????????<td?colspan="2"?align="center"><input?type="submit"?value="提交"?/></td>?????????????????</tr>??????????</table>??</form>??<%??/*?獲取后臺傳過來的內容?*/??String?data?=?(String)session.getAttribute("data");??%>??<%=data?%>??</body>???
5、創建servlet?
新創建一個servlet會報錯,這個一般是缺少jar導致的,這時候,我們不需要從外部導入,在build path中將tomcat的包加過來即可添加方法?
在項目上點擊右鍵?
build path->configure build path->libraries->add library->server runtime?
6、在doPost方法中,寫:
?
?
Java代碼??
???request.setCharacterEncoding("utf-8");????????????String?appid?=?request.getParameter("appId");??????????String?appsecret?=?request.getParameter("appSecret");????????????if(StringUtils.isNotBlank(appid)?&&?StringUtils.isNotBlank(appsecret)){????????????????????????String?token?=?null;????????????????????????try?{????????????????????????????????????token?=?JwTokenAPI.getAccessToken(appid,?appsecret);??????????????????}?catch?(WexinReqException?e)?{??????????????????}??????????????????List<Wxuser>?users?=?null;????????????????????????try?{??????????????????????????users?=?JwUserAPI.getAllWxuser(token,?null);??????????????????}?catch?(WexinReqException?e)?{??????????????????}??????????????????StringBuffer?result?=?new?StringBuffer();????????????????????????for?(Wxuser?wxuser?:?users)?{??????????????????????????result.append("國家:"+wxuser.getCountry()+"?城市:"+wxuser.getCity()+"?性別:"+wxuser.getSex()+"<br/>");??????????????????}????????????????????????request.getSession().setAttribute("data",?result.toString());????????????????????????response.sendRedirect("index.jsp");??????????}??
7、web.xml文件中
Xml代碼??
<?xml?version="1.0"?encoding="UTF-8"?>??<web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns="http://java.sun.com/xml/ns/javaee"?xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"?id="WebApp_ID"?version="2.5">????????<display-name>apiDemo</display-name>????????<welcome-file-list>??????????????<welcome-file>index.html</welcome-file>??????????????<welcome-file>index.htm</welcome-file>??????????????<welcome-file>index.jsp</welcome-file>??????????????<welcome-file>default.html</welcome-file>??????????????<welcome-file>default.htm</welcome-file>??????????????<welcome-file>default.jsp</welcome-file>????????</welcome-file-list>????????<servlet>??????????????<description></description>??????????????<display-name>ApiDemo</display-name>??????????????<servlet-name>ApiDemo</servlet-name>??????????????<servlet-class>apiDemo.userServiceTest.ApiDemo</servlet-class>????????</servlet>????????<servlet-mapping>??????????????<servlet-name>ApiDemo</servlet-name>??????????????<url-pattern>/ApiDemo</url-pattern>????????</servlet-mapping>??</web-app>???
8、運行tomcat服務器?
頁面:?
在里面輸入appId和appSecret點擊提交,下面會返回對應的結果:?
?
總結
以上是生活随笔為你收集整理的jeewx-api.jar入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。