您的位置:首页 > 其它

jeewx的使用_01 接入和验证

2016-02-25 11:07 260 查看
jeewx是java语言的用于开发微信公共平台的一个框架,有人说很臃肿,但个人感觉还不错,仁者见仁智者见智吧,

下面简单介绍工作原理:

1、下载

要使用jeewx需要先下载其源码

jeewx介绍:http://www.oschina.net/p/jeewx

下载地址:http://git.oschina.net/jeecg/jeewx

2、使用

首先要在安装好的jeewx中填写需要二次开发的微信公众号的基本信息

然后登录微信公众平台,在基本设置中填写url

URL(服务器地址)
http://域名/jeewx/wechatController.do?wechat 当开发者填写了服务器配置后,用户消息和开发者需要的事件推送,将会被转发到该URL中

3、打开WechatController.java

package weixin.guanjia.core.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import weixin.guanjia.account.entity.WeixinAccountEntity;
import weixin.guanjia.account.service.WeixinAccountServiceI;
import weixin.guanjia.core.service.impl.WechatService;
import weixin.guanjia.core.util.SignUtil;

@Controller
@RequestMapping("/wechatController")
public class WechatController {
@Autowired
private WechatService wechatService;
@Autowired
private WeixinAccountServiceI weixinAccountService;

/**
* 与微信对接的接口
* @注释添加 geenkDC
* @time 2015-07-09 14:34:07
* @param request
* @param response
* @param signature
* @param timestamp
* @param nonce
* @param echostr
*/
@RequestMapping(params="wechat", method = RequestMethod.GET)
public void wechatGet(HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "signature") String signature,
@RequestParam(value = "timestamp") String timestamp,
@RequestParam(value = "nonce") String nonce,
@RequestParam(value = "echostr") String echostr) {

List<WeixinAccountEntity> weixinAccountEntities = weixinAccountService.getList(WeixinAccountEntity.class);
for (WeixinAccountEntity account : weixinAccountEntities) {
if (SignUtil.checkSignature(account.getAccounttoken(), signature,
timestamp, nonce)) {
try {
response.getWriter().print(echostr);
break;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

/**
* 统一接收微信服务器推送的接口
* @注释添加 geenkDC
* @time 2015-07-09 14:34:56
* @param response
* @param request
* @throws IOException
*/
@RequestMapping(params = "wechat", method = RequestMethod.POST)
public void wechatPost(HttpServletResponse response,
HttpServletRequest request) throws IOException {
String respMessage = wechatService.coreService(request);
PrintWriter out = response.getWriter();
out.print(respMessage);
out.close();
}

}


可以看到当微信的服务器把request推送到该controller之后,剩下的工作就有wechatService来完成了,由于我的wechatService已经经过修改,这里就不在贴出,相信有java基础的博友一看便知,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: