+发表新主题
查看: 2525|回复: 1

[开发入门] 微信公众平台开发教程Java版

[复制链接]

[开发入门] 微信公众平台开发教程Java版

[复制链接]
caprioliu 发表于 2015-11-19 09:42:37 浏览:  2525 回复:  1 [显示全部楼层] 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
好多教程都是php写的,来个java版的,现在用java开的人也很多,应该还是比较实用。
  1. package com.ifp.weixin.controller;

  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.io.UnsupportedEncodingException;

  5. import javax.annotation.Resource;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;

  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;

  11. import com.ifp.weixin.biz.core.CoreService;
  12. import com.ifp.weixin.util.SignUtil;

  13. @Controller
  14. @RequestMapping("/weixinCore")
  15. public class WeixinController {

  16.         @Resource(name="coreService")
  17.         private CoreService coreService;
  18.         
  19.         @RequestMapping(method = RequestMethod.GET)
  20.         public void get(HttpServletRequest request, HttpServletResponse response) {
  21.                 // 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
  22.                 String signature = request.getParameter("signature");
  23.                 // 时间戳
  24.                 String timestamp = request.getParameter("timestamp");
  25.                 // 随机数
  26.                 String nonce = request.getParameter("nonce");
  27.                 // 随机字符串
  28.                 String echostr = request.getParameter("echostr");

  29.                 PrintWriter out = null;
  30.                 try {
  31.                         out = response.getWriter();
  32.                         // 通过检验signature对请求进行校验,若校验成功则原样返回echostr,否则接入失败
  33.                         if (SignUtil.checkSignature(signature, timestamp, nonce)) {
  34.                                 out.print(echostr);
  35.                         }
  36.                 } catch (IOException e) {
  37.                         e.printStackTrace();
  38.                 } finally {
  39.                         out.close();
  40.                         out = null;
  41.                 }
  42.         }

  43.         @RequestMapping(method = RequestMethod.POST)
  44.         public void post(HttpServletRequest request, HttpServletResponse response) {
  45.                 //暂时空着,在这里可处理用户请求
  46.         }
  47. }
复制代码


微信公众平台开发教程Java版.zip (1.64 MB, 下载次数: 0)
回复

使用道具 举报

0

主题

1

帖子

39

积分

心领神会

Rank: 4

积分
39
QQ
biopig 发表于 2015-11-19 09:53:34 显示全部楼层
嗯你手头有类似java的资料不!多搞点,我努力学学
回复 支持 反对

使用道具 举报


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版| 赣南网

© 2013-2016 Comsenz Inc. Powered by Discuz! X3.4

用微信扫一扫

赣南网