• jeewx的使用_01 接入和验证


    jeewx是java语言的用于开发微信公共平台的一个框架,有人说很臃肿,但个人感觉还不错,仁者见仁智者见智吧,

    下面简单介绍工作原理:

    1、下载

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

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

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

    2、使用

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

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

    http://域名/jeewx/wechatController.do?wechat
    当开发者填写了服务器配置后,用户消息和开发者需要的事件推送,将会被转发到该URL中
     
    3、打开WechatController.java
     1 package weixin.guanjia.core.controller;
     2 
     3 import java.io.IOException;
     4 import java.io.PrintWriter;
     5 import java.util.List;
     6 
     7 import javax.servlet.http.HttpServletRequest;
     8 import javax.servlet.http.HttpServletResponse;
     9 
    10 import org.springframework.beans.factory.annotation.Autowired;
    11 import org.springframework.stereotype.Controller;
    12 import org.springframework.web.bind.annotation.RequestMapping;
    13 import org.springframework.web.bind.annotation.RequestMethod;
    14 import org.springframework.web.bind.annotation.RequestParam;
    15 
    16 import weixin.guanjia.account.entity.WeixinAccountEntity;
    17 import weixin.guanjia.account.service.WeixinAccountServiceI;
    18 import weixin.guanjia.core.service.impl.WechatService;
    19 import weixin.guanjia.core.util.SignUtil;
    20 
    21 @Controller
    22 @RequestMapping("/wechatController")
    23 public class WechatController {
    24     @Autowired
    25     private WechatService wechatService;
    26     @Autowired
    27     private WeixinAccountServiceI weixinAccountService;
    28 
    29     /**
    30      * 与微信对接的接口
    31      * @注释添加 geenkDC
    32      * @time 2015-07-09 14:34:07
    33      * @param request
    34      * @param response
    35      * @param signature
    36      * @param timestamp
    37      * @param nonce
    38      * @param echostr
    39      */
    40     @RequestMapping(params="wechat", method = RequestMethod.GET)
    41     public void wechatGet(HttpServletRequest request,
    42             HttpServletResponse response,
    43             @RequestParam(value = "signature") String signature,
    44             @RequestParam(value = "timestamp") String timestamp,
    45             @RequestParam(value = "nonce") String nonce,
    46             @RequestParam(value = "echostr") String echostr) {
    47 
    48         List<WeixinAccountEntity> weixinAccountEntities = weixinAccountService.getList(WeixinAccountEntity.class);
    49         for (WeixinAccountEntity account : weixinAccountEntities) {
    50             if (SignUtil.checkSignature(account.getAccounttoken(), signature,
    51                     timestamp, nonce)) {
    52                 try {
    53                     response.getWriter().print(echostr);
    54                     break;
    55                 } catch (IOException e) {
    56                     // TODO Auto-generated catch block
    57                     e.printStackTrace();
    58                 }
    59             }
    60         }
    61     }
    62 
    63     /**
    64      * 统一接收微信服务器推送的接口
    65      * @注释添加 geenkDC
    66      * @time 2015-07-09 14:34:56
    67      * @param response
    68      * @param request
    69      * @throws IOException
    70      */
    71     @RequestMapping(params = "wechat", method = RequestMethod.POST)
    72     public void wechatPost(HttpServletResponse response,
    73             HttpServletRequest request) throws IOException {
    74         String respMessage = wechatService.coreService(request);
    75         PrintWriter out = response.getWriter();
    76         out.print(respMessage);
    77         out.close();
    78     }
    79 
    80 }

    可以看到当微信的服务器把request推送到该controller之后,剩下的工作就有wechatService来完成了,由于我的wechatService已经经过修改,这里就不在贴出,相信有java基础的博友一看便知,

  • 相关阅读:
    verilog RTL编程实践之四
    TB平台搭建之二
    hdu3466 Proud Merchants
    poj2411 Mondriaan's Dream (用1*2的矩形铺)
    zoj3471 Most Powerful
    poj2923 Relocation
    hdu3001 Travelling
    poj3311 Hie with the Pie
    poj1185 炮兵阵地
    poj3254 Corn Fields
  • 原文地址:https://www.cnblogs.com/geekdc/p/5216260.html
Copyright © 2020-2023  润新知