package com.yihu.jkedu.action; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.yihu.utils.ApiUtil; import com.yihu.utils.StringUtil; import com.yihu.utils.WxConfig; @Controller @RequestMapping("/weixin") public class WeiXinControl { @RequestMapping(value = "/getWeiXinConfig") public void getWeiXinConfig(HttpServletRequest request, HttpServletResponse response)throws Exception { response.setContentType("application/json;charset=UTF-8"); String url = StringUtil.isEmpty(request.getParameter("url")) ? null : request.getParameter("url"); String jsapi_ticket = StringUtil.isEmpty(request.getParameter("jsapi_ticket")) ? null : request.getParameter("jsapi_ticket"); if(StringUtil.isEmpty(url)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "url不能为空,分享不了该文章").toString()); return; } if(StringUtil.isEmpty(jsapi_ticket)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "jsapi_ticket不能为空,分享不了该文章").toString()); return; } try{ JSONObject config=WxConfig.getConfig(jsapi_ticket, url); JSONObject resultJson=new JSONObject(); if(null!=config && config.size()>0){ resultJson.put("Code", 10000); resultJson.put("Message", "成功"); resultJson.put("Result", config); }else{ resultJson.put("Code", -10000); resultJson.put("Message", "获取失败"); resultJson.put("Result", config); } response.getWriter().write(resultJson.toString()); return; }catch(Exception e){ e.printStackTrace(); response.getWriter().write(ApiUtil.jsonResult(-10000, "获取微信认证异常").toString()); return; } } }