微信开发8------Wx-tools的使用

一、下载jar包wx-tools-2.0.0.jar,并加入项目里

https://download.csdn.net/download/dmw412724/10457645

二、在项目本资源里放一个wx.properties,里面保存这个公众号的基本信息

wx.appId=wx1ed9
wx.appSecret=bcb647b7
wx.token=12345
wx.aesKey=
wx.mchId=

三、创建菜单

public class WxTest {
	public static IService iService = new WxService();
	
	public void createMenu() throws WxErrorException{
		//创建一个菜单
		WxMenuButton menuButton = new WxMenuButton();
		
		menuButton.setName("百度");
		menuButton.setType(WxConsts.BUTTON_VIEW);
		menuButton.setUrl("http://www.baidu.com");
		//菜单集合
		List<WxMenuButton> buttons = new ArrayList<WxMenuButton> ();
		buttons.add(menuButton);
		WxMenu menu = new WxMenu();
		menu.setButton(buttons);
		iService.createMenu(menu , false);
	}
	public static void main(String[] args) throws Exception {
		new WxTest().createMenu();
		
	}
}

四、wx回调网址

@Resource
	private IService iService;
	
	@RequestMapping("/webMessageUrl")
	public String webMessageUrl(HttpServletRequest request,String signature,String timestamp,String nonce,String echostr) throws IOException{			 
		//校验发来的信息的合法性
		if (iService.checkSignature(signature, timestamp, nonce, echostr)){
			//把发来的xml的信息解码成对象。然后做进一步的操作
			WxXmlMessage wxXmlMessage = XStreamTransformer.fromXml(WxXmlMessage.class, request.getInputStream());
			log.info(wxXmlMessage);
			
			return StringUtils.isBlank(echostr)? SUCCESS: echostr;
		}	
		return null;
	}
但是这一步操作xml需要的xstream的版本要高一些,至少要高于1.4.5
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值