首页 / 更多教程 / jeewx-api.jar入门教程
jeewx-api.jar入门教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jeewx-api.jar入门教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3528字,纯文字阅读大概需要6分钟。
内容图文
![jeewx-api.jar入门教程](/upload/InfoBanner/zyjiaocheng/1257/51f4f89c8ecd478d91141570c9440857.jpg)
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页面
- < 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方法中,写:
- //设置编码格式
- request.setCharacterEncoding("utf-8");
- //获取页面传过来的参数
- String appid = request.getParameter("appId");
- String appsecret = request.getParameter("appSecret");
- //判断appid和appsecret是否为空
- if(StringUtils.isNotBlank(appid) && StringUtils.isNotBlank(appsecret)){
- //token
- String token = null;
- //获取token
- try {
- //调用jeewx-api中的方法,获取token
- token = JwTokenAPI.getAccessToken(appid, appsecret);
- } catch (WexinReqException e) {
- }
- List<Wxuser> users = null;
- //通过token获取所有用户
- 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/>");
- }
- //将结果放入session中
- request.getSession().setAttribute("data", result.toString());
- //跳转到刚才的页面
- response.sendRedirect("index.jsp");
- }
7、web.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点击提交,下面会返回对应的结果:
原文:http://blog.csdn.net/zhangdaiscott/article/details/44857191
内容总结
以上是互联网集市为您收集整理的jeewx-api.jar入门教程全部内容,希望文章能够帮你解决jeewx-api.jar入门教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。